Skip to content

Commit

Permalink
review comments: account for generics
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 11, 2023
1 parent 147c9bf commit c6f322b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2147,8 +2147,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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`.
7 changes: 1 addition & 6 deletions tests/ui/did_you_mean/bad-assoc-ty.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c6f322b

Please sign in to comment.