rust/compiler/rustc_hir_analysis/src
Matthias Krüger efb8084672
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
2025-01-24 08:08:08 +01:00
..
check Auto merge of #134299 - RalfJung:remove-start, r=compiler-errors 2025-01-21 19:46:20 +00:00
coherence Rollup merge of #135816 - BoxyUwU:root_normalizes_to_goal_ice, r=lcnr 2025-01-22 19:29:39 +01:00
collect Auto merge of #134504 - oli-obk:push-rltsvnyttwll, r=compiler-errors 2025-01-16 18:46:28 +00:00
errors Clarify implicit captures for RPITIT 2024-10-10 11:46:51 -07:00
hir_ty_lowering Also check for associated fns on primitives in E0223 similar-path check. 2025-01-22 02:13:10 -06:00
impl_wf_check Fix const specialization 2024-12-02 22:21:53 +00:00
outlives Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
variance Begin to implement type system layer of unsafe binders 2024-12-22 21:57:57 +00:00
autoderef.rs Rename structurally_normalize to structurally_normalize_ty 2025-01-22 07:04:53 +00:00
bounds.rs Merge HostPolarity and BoundConstness 2024-10-30 16:23:16 +00:00
check_unused.rs Remove #[macro_use] extern crate tracing from rustc_hir_analysis. 2024-08-30 17:14:59 +10:00
collect.rs Add hir::HeaderSafety to make follow up commits simpler 2025-01-14 10:54:11 +00:00
constrained_generic_params.rs Remove #[macro_use] extern crate tracing from rustc_hir_analysis. 2024-08-30 17:14:59 +10:00
delegation.rs Effects cleanup 2024-10-26 10:19:07 +08:00
errors.rs remove support for the #[start] attribute 2025-01-21 06:59:15 -07:00
hir_wf_check.rs uplift fold_regions to rustc_type_ir 2024-11-28 10:40:58 +01:00
impl_wf_check.rs footnote to ordinary comment 2025-01-06 07:37:52 +01:00
lib.rs Do not project when there are unconstrained impl params 2025-01-03 05:01:14 +00:00