-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #94237 - compiler-errors:dont-wrap-ambiguous-receiver…
…s, r=lcnr Do not suggest wrapping an item if it has ambiguous un-imported methods If the method is defined for the receiver we have, but is ambiguous during probe, then it probably comes from one of several traits that just weren't `use`d. Don't suggest wrapping the receiver in `Box`/etc., even if that makes the method probe unambiguous. Fixes #94218
- Loading branch information
Showing
4 changed files
with
65 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
mod banana { | ||
//~^ HELP the following traits are implemented but not in scope | ||
pub struct Chaenomeles; | ||
|
||
pub trait Apple { | ||
fn pick(&self) {} | ||
} | ||
impl Apple for Chaenomeles {} | ||
|
||
pub trait Peach { | ||
fn pick(&self, a: &mut ()) {} | ||
} | ||
impl<Mango: Peach> Peach for Box<Mango> {} | ||
impl Peach for Chaenomeles {} | ||
} | ||
|
||
fn main() { | ||
banana::Chaenomeles.pick() | ||
//~^ ERROR no method named | ||
//~| HELP items from traits can only be used if the trait is in scope | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/ui/suggestions/dont-wrap-ambiguous-receivers.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error[E0599]: no method named `pick` found for struct `Chaenomeles` in the current scope | ||
--> $DIR/dont-wrap-ambiguous-receivers.rs:18:25 | ||
| | ||
LL | pub struct Chaenomeles; | ||
| ----------------------- method `pick` not found for this | ||
... | ||
LL | banana::Chaenomeles.pick() | ||
| ^^^^ method not found in `Chaenomeles` | ||
| | ||
= help: items from traits can only be used if the trait is in scope | ||
help: the following traits are implemented but not in scope; perhaps add a `use` for one of them: | ||
| | ||
LL | use banana::Apple; | ||
| | ||
LL | use banana::Peach; | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |