diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-01-24 08:08:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-24 08:08:08 +0100 |
| commit | efb80846721d5a1161be82ff8bf2738e44ba17f3 (patch) | |
| tree | 6204530dadf9116b434049b3104eddd1120a4255 /compiler/rustc_interface/src/errors.rs | |
| parent | 40e28582bb95e33f762dea75b78f6ebb5c29b836 (diff) | |
| parent | 2c58212619e32035d5c9b15e834c89314ba1d900 (diff) | |
| download | rust-efb80846721d5a1161be82ff8bf2738e44ba17f3.tar.gz rust-efb80846721d5a1161be82ff8bf2738e44ba17f3.zip | |
Rollup merge of #135865 - zachs18:maybe_report_similar_assoc_fn_more, r=compiler-errors
For E0223, suggest associated functions that are similar to the path, even if the base type has multiple inherent impl blocks.
Currently, the "help: there is an associated function with a similar name `from_utf8`" suggestion for `String::from::utf8` is only given if `String` has exactly one inherent `impl` item. This PR makes the suggestion be emitted even if the base type has multiple inherent `impl` items.
Example:
```rust
struct Foo;
impl Foo {
fn bar_baz() {}
}
impl Foo {} // load-bearing
fn main() {
Foo::bar::baz;
}
```
Nightly/stable output:
```rust
error[E0223]: ambiguous associated type
--> f.rs:7:5
|
7 | Foo::bar::baz;
| ^^^^^^^^
|
help: if there were a trait named `Example` with associated type `bar` implemented for `Foo`, you could use the fully-qualified path
|
7 | <Foo as Example>::bar::baz;
| ~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0223`.
```
Output with this PR, or without the load-bearing empty impl on nightly/stable:
```rust
error[E0223]: ambiguous associated type
--> f.rs:7:5
|
7 | Foo::bar::baz;
| ^^^^^^^^
|
help: there is an associated function with a similar name: `bar_baz`
|
7 | Foo::bar_baz;
| ~~~~~~~
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0223`.
```
Ideally, this suggestion would also work for non-ADT types like ~~`str::char::indices`~~ (edit: latest commit makes this work with primitives) or `<dyn Any>::downcast::mut_unchecked`, but that seemed to be a harder change.
`@rustbot` label +A-diagnostics
Diffstat (limited to 'compiler/rustc_interface/src/errors.rs')
0 files changed, 0 insertions, 0 deletions
