-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding E0011 explanation #25825
Adding E0011 explanation #25825
Conversation
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
} | ||
|
||
const a: Foo = Foo { a: 0u8}; | ||
const b: u8 = a[0]; // Index trait is defined by the user, bad ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All other Rust documentation I've read so far does not add spaces before exclamation marks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@killercup: Oh right ! <well, in french we have a space between the last word and '?'/'!'. I change that but you'll have to wait tomorrow before I rebase the second commit.
I squashed ! r+ or do you see something which might need to be improved/fixed ? |
4d2aaf7
to
0b53019
Compare
@@ -176,6 +176,38 @@ for the entire lifetime of a program. Creating a boxed value allocates memory on | |||
the heap at runtime, and therefore cannot be done at compile time. | |||
"##, | |||
|
|||
E0011: r##" | |||
Using user-defined operator on const/static variable is restricted to what can be | |||
evaluated at compile-time. Using an user-defined operator could call a user-defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "Using a user-defined ..."
@mrmonday: Should be good now, thanks for signaling me typos ! |
const b: u8 = a[0]; // Index trait is defined by the user, bad! | ||
``` | ||
|
||
The only traits which can be used have to be already implemented, not user-defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "already implemented" is somewhat unclear, and that a better replacement would be: "only operators on builtin types are allowed."
Updated ! |
|
||
struct Foo { a: u8 } | ||
|
||
impl ::std::ops::Index<u8> for Foo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need for a full path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right ! I totally forgot that I imported the trait just above...
@@ -176,6 +176,38 @@ for the entire lifetime of a program. Creating a boxed value allocates memory on | |||
the heap at runtime, and therefore cannot be done at compile time. | |||
"##, | |||
|
|||
E0011: r##" | |||
Using a user-defined operator on const/static variable is restricted to what |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This first sentence doesn't really make sense as you can't use user-defined operators to define consts or statics at all. I think we should accentuate the point from the second sentence. Something like:
Initializers for constants and statics are evaluated at compile time. User-defined operators rely on user-defined functions, which cannot be evaluated at compile time.
Updated. |
Perfect! Ready to land! r+ @Manishearth ? |
@bors: r+ rollup |
📌 Commit dbfc8c5 has been approved by |
Part of #24407.