forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#125622 - oli-obk:define_opaque_types15, r=compiler-errors Winnow private method candidates instead of assuming any candidate of the right name will apply partially reverts rust-lang#60721 My original motivation was just to avoid the `delay_span_bug` (by attempting to thread the `ErrorGuaranteed` through to here). But then I realized that the error message is wrong. It refers to the `Foo<A>::foo` instead of `Foo<B>::foo`. This is almost invisible, because both functions are the same, but on different lines, so `-Zui-testing` makes it so the test is the same no matter which of these two functions is referenced. But there's a much more obvious bug: If `Foo<B>` does not have a `foo` method at all, but `Foo<A>` has a private `foo` method, then we'll refer to that one. This has now been fixed, and we report a normal `method not found` error. The way this is done is by creating a list of all possible private functions (just like we create a list of the public functions that can actually be called), and then winnowing it by analyzing where bounds and `Self` types to see if any of the found methods can actually apply (again, just like with the list of public functions). I wonder if there is room for doing the same thing with unstable functions instead of running all of method resolution twice. r? ``@compiler-errors`` for method resolution stuff
- Loading branch information
Showing
8 changed files
with
72 additions
and
31 deletions.
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