diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 038ba220608..c8ca51348cc 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -696,14 +696,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { ) = &bounded_ty.kind { // use this to verify that ident is a type param. - let Ok(Some(partial_res)) = self.resolve_qpath_anywhere( - None, - &Segment::from_path(path), - Namespace::TypeNS, - span, - true, - Finalize::No, - ) else { + let Some(partial_res) = self.r.partial_res_map.get(&bounded_ty.id) else { return false; }; if !(matches!( @@ -718,16 +711,10 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { return false; }; - if let ast::TyKind::Path(None, type_param_path) = &ty.peel_refs().kind { + let peeled_ty = ty.peel_refs(); + if let ast::TyKind::Path(None, type_param_path) = &peeled_ty.kind { // Confirm that the `SelfTy` is a type parameter. - let Ok(Some(partial_res)) = self.resolve_qpath_anywhere( - None, - &Segment::from_path(type_param_path), - Namespace::TypeNS, - span, - true, - Finalize::No, - ) else { + let Some(partial_res) = self.r.partial_res_map.get(&peeled_ty.id) else { return false; }; if !(matches!( diff --git a/src/test/ui/traits/associated_type_bound/assoc_type_bound_with_struct.rs b/src/test/ui/traits/associated_type_bound/assoc_type_bound_with_struct.rs index c66009fe24c..471a6b836b5 100644 --- a/src/test/ui/traits/associated_type_bound/assoc_type_bound_with_struct.rs +++ b/src/test/ui/traits/associated_type_bound/assoc_type_bound_with_struct.rs @@ -16,4 +16,8 @@ fn foo(_: T) where ::Baz: String { //~ ERROR expected trait, f fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: String { //~ ERROR expected trait, found } +fn issue_95327() where ::Assoc: String {} +//~^ ERROR expected trait, found struct +//~| ERROR use of undeclared type `Unresolved` + fn main() {} diff --git a/src/test/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr b/src/test/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr index 38b2e5ae9b9..9ca446a0a89 100644 --- a/src/test/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr +++ b/src/test/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr @@ -1,3 +1,9 @@ +error[E0433]: failed to resolve: use of undeclared type `Unresolved` + --> $DIR/assoc_type_bound_with_struct.rs:19:31 + | +LL | fn issue_95327() where ::Assoc: String {} + | ^^^^^^^^^^ use of undeclared type `Unresolved` + error[E0404]: expected trait, found struct `String` --> $DIR/assoc_type_bound_with_struct.rs:5:46 | @@ -78,6 +84,18 @@ help: a trait with a similar name exists LL | fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: ToString { | ~~~~~~~~ -error: aborting due to 4 previous errors +error[E0404]: expected trait, found struct `String` + --> $DIR/assoc_type_bound_with_struct.rs:19:51 + | +LL | fn issue_95327() where ::Assoc: String {} + | ^^^^^^ help: a trait with a similar name exists: `ToString` + | + ::: $SRC_DIR/alloc/src/string.rs:LL:COL + | +LL | pub trait ToString { + | ------------------ similarly named trait `ToString` defined here -For more information about this error, try `rustc --explain E0404`. +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0404, E0433. +For more information about an error, try `rustc --explain E0404`.