Skip to content

Commit 689a868

Browse files
committed
Remove some noise from opaque type errors around associated types
1 parent f840216 commit 689a868

File tree

3 files changed

+17
-57
lines changed

3 files changed

+17
-57
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

+14
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,20 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
551551
let predicate = predicate.subst(tcx, substs);
552552
debug!(?predicate);
553553

554+
// Replace all other mentions of the same opaque type with the hidden type,
555+
// as the bounds must hold on the hidden type after all.
556+
let predicate = predicate.fold_with(&mut BottomUpFolder {
557+
tcx,
558+
ty_op: |ty| match *ty.kind() {
559+
ty::Opaque(def_id2, substs2) if def_id == def_id2 && substs == substs2 => {
560+
ty_var
561+
}
562+
_ => ty,
563+
},
564+
lt_op: |lt| lt,
565+
ct_op: |ct| ct,
566+
});
567+
554568
// We can't normalize associated types from `rustc_infer`, but we can eagerly register inference variables for them.
555569
let predicate = predicate.fold_with(&mut BottomUpFolder {
556570
tcx,

src/test/ui/type-alias-impl-trait/bound_reduction2.rs

-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,5 @@ impl<W> Trait<W> for () {}
1515

1616
fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
1717
//~^ ERROR non-defining opaque type use in defining scope
18-
//~| ERROR non-defining opaque type use in defining scope
19-
//~| ERROR non-defining opaque type use in defining scope
20-
//~| ERROR `T` is part of concrete type but not used in parameter list
21-
//~| ERROR `T` is part of concrete type but not used in parameter list
2218
()
2319
}
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,20 @@
1-
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
2-
--> $DIR/bound_reduction2.rs:16:60
3-
|
4-
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
5-
| ____________________________________________________________^
6-
LL | |
7-
LL | |
8-
LL | |
9-
... |
10-
LL | | ()
11-
LL | | }
12-
| |_^
13-
14-
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
15-
--> $DIR/bound_reduction2.rs:16:60
16-
|
17-
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
18-
| ____________________________________________________________^
19-
LL | |
20-
LL | |
21-
LL | |
22-
... |
23-
LL | | ()
24-
LL | | }
25-
| |_^
26-
271
error: non-defining opaque type use in defining scope
28-
--> $DIR/bound_reduction2.rs:16:1
2+
--> $DIR/bound_reduction2.rs:16:46
293
|
304
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^
326
|
337
note: used non-generic type `<T as TraitWithAssoc>::Assoc` for generic parameter
348
--> $DIR/bound_reduction2.rs:9:10
359
|
3610
LL | type Foo<V> = impl Trait<V>;
3711
| ^
3812

39-
error: non-defining opaque type use in defining scope
40-
--> $DIR/bound_reduction2.rs:16:1
41-
|
42-
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
43-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44-
|
45-
note: used non-generic type `_` for generic parameter
46-
--> $DIR/bound_reduction2.rs:9:10
47-
|
48-
LL | type Foo<V> = impl Trait<V>;
49-
| ^
50-
51-
error: non-defining opaque type use in defining scope
52-
--> $DIR/bound_reduction2.rs:16:1
53-
|
54-
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
55-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56-
|
57-
note: used non-generic type `_` for generic parameter
58-
--> $DIR/bound_reduction2.rs:9:10
59-
|
60-
LL | type Foo<V> = impl Trait<V>;
61-
| ^
62-
6313
error: could not find defining uses
6414
--> $DIR/bound_reduction2.rs:9:15
6515
|
6616
LL | type Foo<V> = impl Trait<V>;
6717
| ^^^^^^^^^^^^^
6818

69-
error: aborting due to 6 previous errors
19+
error: aborting due to 2 previous errors
7020

0 commit comments

Comments
 (0)