-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Suggest fully qualified path on method name collision #153662
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
Open
estebank
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
estebank:suggest-fully-qualified-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Can't use rustfix because we provide two suggestions: | ||
| // to remove the arg for `Borrow::borrow` or to call `Type::borrow`. | ||
| use std::borrow::Borrow; | ||
|
|
||
| struct A; | ||
|
|
||
| impl A { fn borrow(&mut self, _: ()) {} } | ||
|
|
||
| struct B; | ||
|
|
||
| fn main() { | ||
| // The fully-qualified path for items within functions is unnameable from outside that function. | ||
| impl B { fn borrow(&mut self, _: ()) {} } | ||
|
|
||
| struct C; | ||
| // The fully-qualified path for items within functions is unnameable from outside that function. | ||
| impl C { fn borrow(&mut self, _: ()) {} } | ||
|
|
||
| let mut a = A; | ||
| a.borrow(()); //~ ERROR E0061 | ||
| // A::borrow(&mut a, ()); | ||
| let mut b = B; | ||
| b.borrow(()); //~ ERROR E0061 | ||
| // This currently suggests `main::<impl B>::borrow`, which is not correct, it should be | ||
| // B::borrow(&mut b, ()); | ||
| let mut c = C; | ||
| c.borrow(()); //~ ERROR E0061 | ||
| // This currently suggests `main::C::borrow`, which is not correct, it should be | ||
| // C::borrow(&mut c, ()); | ||
| } | ||
|
|
||
| fn foo() { | ||
| let mut b = B; | ||
| b.borrow(()); //~ ERROR E0061 | ||
| // This currently suggests `main::<impl B>::borrow`, which is not correct, it should be | ||
| // B::borrow(&mut b, ()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| error[E0061]: this method takes 0 arguments but 1 argument was supplied | ||
| --> $DIR/shadowed-intrinsic-method.rs:20:7 | ||
| | | ||
| LL | a.borrow(()); | ||
| | ^^^^^^ -- unexpected argument of type `()` | ||
| | | ||
| note: the `borrow` call is resolved to the method in `std::borrow::Borrow`, shadowing the method of the same name on the inherent impl for `A` | ||
| --> $DIR/shadowed-intrinsic-method.rs:20:7 | ||
| | | ||
| LL | use std::borrow::Borrow; | ||
| | ------------------- `std::borrow::Borrow` imported here | ||
| ... | ||
| LL | a.borrow(()); | ||
| | ^^^^^^ refers to `std::borrow::Borrow::borrow` | ||
| note: method defined here | ||
| --> $SRC_DIR/core/src/borrow.rs:LL:COL | ||
| help: you might have meant to call the other method; you can use the fully-qualified path to call it explicitly | ||
| | | ||
| LL - a.borrow(()); | ||
| LL + A::borrow(&mut a, ()); | ||
| | | ||
| help: remove the extra argument | ||
| | | ||
| LL - a.borrow(()); | ||
| LL + a.borrow(); | ||
| | | ||
|
|
||
| error[E0061]: this method takes 0 arguments but 1 argument was supplied | ||
| --> $DIR/shadowed-intrinsic-method.rs:23:7 | ||
| | | ||
| LL | b.borrow(()); | ||
| | ^^^^^^ -- unexpected argument of type `()` | ||
| | | ||
| note: the `borrow` call is resolved to the method in `std::borrow::Borrow`, shadowing the method of the same name on the inherent impl for `main::<impl B>` | ||
| --> $DIR/shadowed-intrinsic-method.rs:23:7 | ||
| | | ||
| LL | use std::borrow::Borrow; | ||
| | ------------------- `std::borrow::Borrow` imported here | ||
| ... | ||
| LL | b.borrow(()); | ||
| | ^^^^^^ refers to `std::borrow::Borrow::borrow` | ||
| note: method defined here | ||
| --> $SRC_DIR/core/src/borrow.rs:LL:COL | ||
| help: you might have meant to call the other method; you can use the fully-qualified path to call it explicitly | ||
| | | ||
| LL - b.borrow(()); | ||
| LL + B::borrow(&mut b, ()); | ||
| | | ||
| help: remove the extra argument | ||
| | | ||
| LL - b.borrow(()); | ||
| LL + b.borrow(); | ||
| | | ||
|
|
||
| error[E0061]: this method takes 0 arguments but 1 argument was supplied | ||
| --> $DIR/shadowed-intrinsic-method.rs:27:7 | ||
| | | ||
| LL | c.borrow(()); | ||
| | ^^^^^^ -- unexpected argument of type `()` | ||
| | | ||
| note: the `borrow` call is resolved to the method in `std::borrow::Borrow`, shadowing the method of the same name on the inherent impl for `main::C` | ||
| --> $DIR/shadowed-intrinsic-method.rs:27:7 | ||
| | | ||
| LL | use std::borrow::Borrow; | ||
| | ------------------- `std::borrow::Borrow` imported here | ||
| ... | ||
| LL | c.borrow(()); | ||
| | ^^^^^^ refers to `std::borrow::Borrow::borrow` | ||
| note: method defined here | ||
| --> $SRC_DIR/core/src/borrow.rs:LL:COL | ||
| help: you might have meant to call the other method; you can use the fully-qualified path to call it explicitly | ||
| | | ||
| LL - c.borrow(()); | ||
| LL + C::borrow(&mut c, ()); | ||
| | | ||
| help: remove the extra argument | ||
| | | ||
| LL - c.borrow(()); | ||
| LL + c.borrow(); | ||
| | | ||
|
|
||
| error[E0061]: this method takes 0 arguments but 1 argument was supplied | ||
| --> $DIR/shadowed-intrinsic-method.rs:34:7 | ||
| | | ||
| LL | b.borrow(()); | ||
| | ^^^^^^ -- unexpected argument of type `()` | ||
| | | ||
| note: the `borrow` call is resolved to the method in `std::borrow::Borrow`, shadowing the method of the same name on the inherent impl for `main::<impl B>` | ||
| --> $DIR/shadowed-intrinsic-method.rs:34:7 | ||
| | | ||
| LL | use std::borrow::Borrow; | ||
| | ------------------- `std::borrow::Borrow` imported here | ||
| ... | ||
| LL | b.borrow(()); | ||
| | ^^^^^^ refers to `std::borrow::Borrow::borrow` | ||
| note: method defined here | ||
| --> $SRC_DIR/core/src/borrow.rs:LL:COL | ||
| help: you might have meant to call the other method; you can use the fully-qualified path to call it explicitly | ||
| | | ||
| LL - b.borrow(()); | ||
| LL + B::borrow(&mut b, ()); | ||
| | | ||
| help: remove the extra argument | ||
| | | ||
| LL - b.borrow(()); | ||
| LL + b.borrow(); | ||
| | | ||
|
|
||
| error: aborting due to 4 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0061`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should be running this logic 3 times: one for "all of the arguments apply", "the number of arguments match" and "only the name matches", in order. If any of the cases happens, break (as we get less and less confident the further away we get from things matching).