-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Clearer Error Message for Duplicate Definition #42076
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Could you give us a before/after comparison? |
src/test/compile-fail/E0254.rs
Outdated
@@ -11,7 +11,7 @@ | |||
#![feature(collections)] | |||
|
|||
extern crate collections; | |||
//~^ NOTE previous import of `collections` here | |||
//~^ NOTE previous import of the extern crate `collections` here |
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 feel like this should just be the crate, there's no such thing as an "extern crate."
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 don't mind either way.
The original behavior was to regard this as an extern crate
, although it was identified as such in the error header rather than the span label.
Of course! Source (
Original message:
New message:
|
Thanks for the PR @alex-ozdemir! We'll make sure @arielb1 or another team member reviews this soon |
r? @nrc |
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 looks good, I especially like the changes to the notes on the second use. Two issues inline.
src/librustc_resolve/lib.rs
Outdated
}; | ||
|
||
let msg = format!("the name `{}` is defined twice in this {}", name, container); |
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 message would be inaccurate if the name were defined more than twice, right?
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.
Good point. I'll change this.
src/librustc_resolve/lib.rs
Outdated
false => "definition", | ||
}; | ||
|
||
let new_participle = match binding.is_import() { |
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.
naming nits: why old_
and new_
here?
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 should use this more consistently. The original (old) definition/import and the new one may have different participles/nouns.
The old message was suboptimal, but it tried to convey something about namespaces
The new message just says "name"
which is not strictly correct because several items in a module can have the same name if they are in different namespaces
Maybe extend the message to
? |
src/test/compile-fail/issue-28472.rs
Outdated
@@ -13,10 +13,10 @@ | |||
extern { | |||
fn foo(); | |||
|
|||
pub //~ ERROR a value named `foo` has already been defined | |||
pub //~ ERROR E0428 |
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.
Could you keep using messages for testing and avoid error codes outside of E0XXX.rs
tests.
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.
Sure thing.
@petrochenkov: Good idea, will do. Question: which is better?
The former is more correct (it could be any duplication of imports & definitions), but the word bound is less common. |
@alex-ozdemir |
Thanks for the feedback! New error format:
|
The test Error details
|
Good spot! |
I've pinged @nrc on IRC to get a second review pass for this PR. |
r = me with commits squashed. Thanks! |
We're just waiting for you to squash the commits. Can you get that done so we can finish working on this PR? |
c7e4cdb
to
87c8bf7
Compare
Okay, sorry for the delay. I had forgotten that Rust doesn't use the standard PR workflow that allows y'all to squash & merge on your own. Assuming I squashed correctly the integration tests should pass again, and we'll be good to go! |
Looks like the squash possibly introduced some problems, could you take a look and fix those please? https://travis-ci.org/rust-lang/rust/jobs/240754613#L786 |
Whoops! All good now. |
@bors r=nrc |
📌 Commit 89bd87e has been approved by |
🔒 Merge conflict |
☔ The latest upstream changes (presumably #42648) made this pull request unmergeable. Please resolve the merge conflicts. |
Clearer use of the error message and span labels to communicate duplicaiton defitions/imports. New error format: ``` error[E0428]: the name `Foo` is defined twice --> example.rs:2:1 | 1 | trait Foo { } | ------------- previous definition of the trait `Foo` here 2 | struct Foo { } | ^^^^^^^^^^^^^^ `Foo` redefined here = note: `Foo` must be defined only once in the type namespace of this module error: aborting due to previous error ```
I believe the merge conflicts are resolved. |
Looks like this PR fell between the chairs a bit. Currently waiting for review by @nrc. |
@bors: r+ |
📌 Commit a82890e has been approved by |
Clearer Error Message for Duplicate Definition Clearer use of the error message and span labels to communicate duplication definitions/imports. fixes #42061
☀️ Test successful - status-appveyor, status-travis |
Clearer use of the error message and span labels to communicate duplication definitions/imports.
fixes #42061