diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 62f6b87c9e98c..fc611a0a2da5e 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -6074,7 +6074,16 @@ fn point_at_assoc_type_restriction( let ty::ClauseKind::Projection(proj) = clause else { return; }; - let name = tcx.item_name(proj.projection_term.def_id); + let Some(name) = tcx + .opt_rpitit_info(proj.projection_term.def_id) + .and_then(|data| match data { + ty::ImplTraitInTraitData::Trait { fn_def_id, .. } => Some(tcx.item_name(fn_def_id)), + ty::ImplTraitInTraitData::Impl { .. } => None, + }) + .or_else(|| tcx.opt_item_name(proj.projection_term.def_id)) + else { + return; + }; let mut predicates = generics.predicates.iter().peekable(); let mut prev: Option<(&hir::WhereBoundPredicate<'_>, Span)> = None; while let Some(pred) = predicates.next() { diff --git a/tests/ui/associated-type-bounds/return-type-notation/return-type-notation-where-clause-doesnt-apply.rs b/tests/ui/associated-type-bounds/return-type-notation/return-type-notation-where-clause-doesnt-apply.rs new file mode 100644 index 0000000000000..a12e8235662ba --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/return-type-notation-where-clause-doesnt-apply.rs @@ -0,0 +1,18 @@ +// Regression test for https://github.com/rust-lang/rust/issues/152887 +//@ edition: 2024 + +#![feature(return_type_notation)] + +pub trait Trait { + async fn func(); +} + +impl> Trait for T {} +//~^ ERROR not all trait items implemented, missing: `func` + +fn check(_: impl Trait) {} + +fn main() { + check(()); + //~^ ERROR overflow evaluating the requirement +} diff --git a/tests/ui/associated-type-bounds/return-type-notation/return-type-notation-where-clause-doesnt-apply.stderr b/tests/ui/associated-type-bounds/return-type-notation/return-type-notation-where-clause-doesnt-apply.stderr new file mode 100644 index 0000000000000..84697aecfc638 --- /dev/null +++ b/tests/ui/associated-type-bounds/return-type-notation/return-type-notation-where-clause-doesnt-apply.stderr @@ -0,0 +1,34 @@ +error[E0046]: not all trait items implemented, missing: `func` + --> $DIR/return-type-notation-where-clause-doesnt-apply.rs:10:1 + | +LL | async fn func(); + | ---------------- `func` from trait +... +LL | impl> Trait for T {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `func` in implementation + +error[E0275]: overflow evaluating the requirement `impl Future { <() as Trait>::func(..) } == _` + --> $DIR/return-type-notation-where-clause-doesnt-apply.rs:16:5 + | +LL | check(()); + | ^^^^^^^^^ + | +note: required for `()` to implement `Trait` + --> $DIR/return-type-notation-where-clause-doesnt-apply.rs:10:32 + | +LL | impl> Trait for T {} + | ---- ^^^^^ ^ + | | + | unsatisfied trait bound introduced here + = note: 1 redundant requirement hidden + = note: required for `()` to implement `Trait` +note: required by a bound in `check` + --> $DIR/return-type-notation-where-clause-doesnt-apply.rs:13:18 + | +LL | fn check(_: impl Trait) {} + | ^^^^^ required by this bound in `check` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0046, E0275. +For more information about an error, try `rustc --explain E0046`.