]> git.lizzy.rs Git - rust.git/commitdiff
review comments: account for generics
authorEsteban Küber <esteban@kuber.com.ar>
Sun, 8 Jan 2023 20:51:40 +0000 (20:51 +0000)
committerEsteban Küber <esteban@kuber.com.ar>
Wed, 11 Jan 2023 21:30:32 +0000 (21:30 +0000)
compiler/rustc_hir_analysis/src/astconv/mod.rs
tests/ui/associated-item/ambiguous-associated-type-with-generics.fixed [new file with mode: 0644]
tests/ui/associated-item/ambiguous-associated-type-with-generics.rs [new file with mode: 0644]
tests/ui/associated-item/ambiguous-associated-type-with-generics.stderr [new file with mode: 0644]
tests/ui/did_you_mean/bad-assoc-ty.stderr

index 315a2a2af1bcacebc5c6c52f7b64d8d904f51aac..5baaaf09edb66553b393b30b25b024bea8bae406 100644 (file)
@@ -2147,8 +2147,12 @@ pub fn associated_path_to_ty(
                                 .is_accessible_from(self.item_def_id(), tcx)
                             && tcx.all_impls(*trait_def_id)
                                 .any(|impl_def_id| {
-                                    let trait_ref = tcx.impl_trait_ref(impl_def_id);
-                                    trait_ref.map_or(false, |impl_| {
+                                    let trait_ref = tcx.bound_impl_trait_ref(impl_def_id);
+                                    trait_ref.map_or(false, |trait_ref| {
+                                        let impl_ = trait_ref.subst(
+                                            tcx,
+                                            infcx.fresh_substs_for_item(span, impl_def_id),
+                                        );
                                         infcx
                                             .can_eq(
                                                 param_env,
diff --git a/tests/ui/associated-item/ambiguous-associated-type-with-generics.fixed b/tests/ui/associated-item/ambiguous-associated-type-with-generics.fixed
new file mode 100644 (file)
index 0000000..23f7152
--- /dev/null
@@ -0,0 +1,14 @@
+// run-rustfix
+trait Trait<A> {}
+
+trait Assoc {
+    type Ty;
+}
+
+impl<A> Assoc for dyn Trait<A> {
+    type Ty = i32;
+}
+
+fn main() {
+    let _x: <dyn Trait<i32> as Assoc>::Ty; //~ ERROR ambiguous associated type
+}
diff --git a/tests/ui/associated-item/ambiguous-associated-type-with-generics.rs b/tests/ui/associated-item/ambiguous-associated-type-with-generics.rs
new file mode 100644 (file)
index 0000000..9c26e33
--- /dev/null
@@ -0,0 +1,14 @@
+// run-rustfix
+trait Trait<A> {}
+
+trait Assoc {
+    type Ty;
+}
+
+impl<A> Assoc for dyn Trait<A> {
+    type Ty = i32;
+}
+
+fn main() {
+    let _x: <dyn Trait<i32>>::Ty; //~ ERROR ambiguous associated type
+}
diff --git a/tests/ui/associated-item/ambiguous-associated-type-with-generics.stderr b/tests/ui/associated-item/ambiguous-associated-type-with-generics.stderr
new file mode 100644 (file)
index 0000000..97088b7
--- /dev/null
@@ -0,0 +1,9 @@
+error[E0223]: ambiguous associated type
+  --> $DIR/ambiguous-associated-type-with-generics.rs:13:13
+   |
+LL |     let _x: <dyn Trait<i32>>::Ty;
+   |             ^^^^^^^^^^^^^^^^^^^^ help: use the fully-qualified path: `<dyn Trait<i32> as Assoc>::Ty`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0223`.
index 7cd349c7507f9048271eb6746f5af861860d6bf4..55096e95df7e06cee280a39f5f477cf81a108c06 100644 (file)
@@ -147,12 +147,7 @@ error[E0223]: ambiguous associated type
   --> $DIR/bad-assoc-ty.rs:33:10
    |
 LL | type H = Fn(u8) -> (u8)::Output;
-   |          ^^^^^^^^^^^^^^^^^^^^^^
-   |
-help: if there were a trait named `Example` with associated type `Output` implemented for `(dyn Fn(u8) -> u8 + 'static)`, you could use the fully-qualified path
-   |
-LL | type H = <(dyn Fn(u8) -> u8 + 'static) as Example>::Output;
-   |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+   |          ^^^^^^^^^^^^^^^^^^^^^^ help: use the fully-qualified path: `<(dyn Fn(u8) -> u8 + 'static) as IntoFuture>::Output`
 
 error[E0223]: ambiguous associated type
   --> $DIR/bad-assoc-ty.rs:39:19