Skip to content
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

Merged
merged 3 commits into from
Jun 1, 2015
Merged

Adding E0011 explanation #25825

merged 3 commits into from
Jun 1, 2015

Conversation

GuillaumeGomez
Copy link
Member

Part of #24407.

@rust-highfive
Copy link
Collaborator

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 !
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

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.

@GuillaumeGomez
Copy link
Member Author

I squashed ! r+ or do you see something which might need to be improved/fixed ?

@GuillaumeGomez GuillaumeGomez force-pushed the check_co branch 2 times, most recently from 4d2aaf7 to 0b53019 Compare May 29, 2015 22:33
@@ -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
Copy link
Contributor

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 ..."

@GuillaumeGomez
Copy link
Member Author

@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.
Copy link
Member

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."

@GuillaumeGomez
Copy link
Member Author

Updated !

@Manishearth
Copy link
Member

cc @michaelsproul


struct Foo { a: u8 }

impl ::std::ops::Index<u8> for Foo {
Copy link
Member

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

Copy link
Member Author

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
Copy link
Contributor

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.

@GuillaumeGomez
Copy link
Member Author

Updated.

@michaelsproul
Copy link
Contributor

Perfect! Ready to land! r+ @Manishearth ?

@Manishearth
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Jun 1, 2015

📌 Commit dbfc8c5 has been approved by Manishearth

bors added a commit that referenced this pull request Jun 1, 2015
@bors
Copy link
Contributor

bors commented Jun 1, 2015

⌛ Testing commit dbfc8c5 with merge 3e561f0...

@bors bors merged commit dbfc8c5 into rust-lang:master Jun 1, 2015
@GuillaumeGomez GuillaumeGomez deleted the check_co branch June 1, 2015 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants