Skip to content

Commit c6f322b

Browse files
committed
review comments: account for generics
1 parent 147c9bf commit c6f322b

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2147,8 +2147,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21472147
.is_accessible_from(self.item_def_id(), tcx)
21482148
&& tcx.all_impls(*trait_def_id)
21492149
.any(|impl_def_id| {
2150-
let trait_ref = tcx.impl_trait_ref(impl_def_id);
2151-
trait_ref.map_or(false, |impl_| {
2150+
let trait_ref = tcx.bound_impl_trait_ref(impl_def_id);
2151+
trait_ref.map_or(false, |trait_ref| {
2152+
let impl_ = trait_ref.subst(
2153+
tcx,
2154+
infcx.fresh_substs_for_item(span, impl_def_id),
2155+
);
21522156
infcx
21532157
.can_eq(
21542158
param_env,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-rustfix
2+
trait Trait<A> {}
3+
4+
trait Assoc {
5+
type Ty;
6+
}
7+
8+
impl<A> Assoc for dyn Trait<A> {
9+
type Ty = i32;
10+
}
11+
12+
fn main() {
13+
let _x: <dyn Trait<i32> as Assoc>::Ty; //~ ERROR ambiguous associated type
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-rustfix
2+
trait Trait<A> {}
3+
4+
trait Assoc {
5+
type Ty;
6+
}
7+
8+
impl<A> Assoc for dyn Trait<A> {
9+
type Ty = i32;
10+
}
11+
12+
fn main() {
13+
let _x: <dyn Trait<i32>>::Ty; //~ ERROR ambiguous associated type
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0223]: ambiguous associated type
2+
--> $DIR/ambiguous-associated-type-with-generics.rs:13:13
3+
|
4+
LL | let _x: <dyn Trait<i32>>::Ty;
5+
| ^^^^^^^^^^^^^^^^^^^^ help: use the fully-qualified path: `<dyn Trait<i32> as Assoc>::Ty`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0223`.

tests/ui/did_you_mean/bad-assoc-ty.stderr

+1-6
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,7 @@ error[E0223]: ambiguous associated type
147147
--> $DIR/bad-assoc-ty.rs:33:10
148148
|
149149
LL | type H = Fn(u8) -> (u8)::Output;
150-
| ^^^^^^^^^^^^^^^^^^^^^^
151-
|
152-
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
153-
|
154-
LL | type H = <(dyn Fn(u8) -> u8 + 'static) as Example>::Output;
155-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150+
| ^^^^^^^^^^^^^^^^^^^^^^ help: use the fully-qualified path: `<(dyn Fn(u8) -> u8 + 'static) as IntoFuture>::Output`
156151

157152
error[E0223]: ambiguous associated type
158153
--> $DIR/bad-assoc-ty.rs:39:19

0 commit comments

Comments
 (0)