-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Winnow private method candidates instead of assuming any candidate of the right name will apply #125622
Merged
Merged
Winnow private method candidates instead of assuming any candidate of the right name will apply #125622
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e8df95
Manual rustfmt
oli-obk 14f9c63
Show that it will pick up the entirely wrong function as a private ca…
oli-obk 7d151fa
Turn a delayed bug back into a normal bug by winnowing private method…
oli-obk 7894a11
Move tests to a more appropriate directory
oli-obk 8189506
Give test a more useful name
oli-obk ffb1b2c
Add test description
oli-obk 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,15 @@ | ||
error[E0599]: no function or associated item named `foo` found for struct `Foo<B>` in the current scope | ||
--> $DIR/ufc-method-call.rs:27:27 | ||
| | ||
LL | pub struct Foo<T>(T); | ||
| ----------------- function or associated item `foo` not found for this struct | ||
... | ||
LL | test::Foo::<test::B>::foo(); | ||
| ^^^ function or associated item not found in `Foo<B>` | ||
| | ||
= note: the function or associated item was found for | ||
- `Foo<A>` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
This file contains 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,30 @@ | ||
//! This test used to report that the method call cannot | ||
//! call the private method `Foo<A>::foo`, even though the user | ||
//! explicitly selected `Foo<B>::foo`. This is because we only | ||
//! looked for methods of the right name, without properly checking | ||
//! the `Self` type | ||
|
||
//@ revisions: same_name different_name | ||
|
||
pub mod test { | ||
pub struct A; | ||
pub struct B; | ||
pub struct Foo<T>(T); | ||
|
||
impl Foo<A> { | ||
fn foo() {} | ||
} | ||
|
||
impl Foo<B> { | ||
#[cfg(same_name)] | ||
fn foo() {} | ||
#[cfg(different_name)] | ||
fn bar() {} | ||
} | ||
} | ||
|
||
fn main() { | ||
test::Foo::<test::B>::foo(); | ||
//[same_name]~^ ERROR associated function `foo` is private | ||
//[different_name]~^^ ERROR no function or associated item named `foo` found for struct `Foo<B>` | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/ui/issues/issue-53498.stderr → .../privacy/ufc-method-call.same_name.stderr
This file contains 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.
What is the difference between these lol
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.
Or actually, better question: Why do we need two fields 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.
We need the
private_candidate
field to communicate an actually found candidate out to thepick
method. While we could just eagerly return thePrivateMatch
error, that would mean we'd miss out on suggesting traits that could be imported to get access to another method of the same name.Of course we could just eagerly report (not return) an error from method selection and return that no methods were found, which will subsequently return an error containing the list of traits that should be imported. But then method selection is reporting errors, which is also not be desirable (and probably wrong in various cases where we'll return a better error later).