Skip to content

Commit

Permalink
Remove some noise from opaque type errors around associated types
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 16, 2021
1 parent f840216 commit 689a868
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 57 deletions.
14 changes: 14 additions & 0 deletions compiler/rustc_infer/src/infer/opaque_types.rs
Expand Up @@ -551,6 +551,20 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
let predicate = predicate.subst(tcx, substs);
debug!(?predicate);

// Replace all other mentions of the same opaque type with the hidden type,
// as the bounds must hold on the hidden type after all.
let predicate = predicate.fold_with(&mut BottomUpFolder {
tcx,
ty_op: |ty| match *ty.kind() {
ty::Opaque(def_id2, substs2) if def_id == def_id2 && substs == substs2 => {
ty_var
}
_ => ty,
},
lt_op: |lt| lt,
ct_op: |ct| ct,
});

// We can't normalize associated types from `rustc_infer`, but we can eagerly register inference variables for them.
let predicate = predicate.fold_with(&mut BottomUpFolder {
tcx,
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/type-alias-impl-trait/bound_reduction2.rs
Expand Up @@ -15,9 +15,5 @@ impl<W> Trait<W> for () {}

fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
//~^ ERROR non-defining opaque type use in defining scope
//~| ERROR non-defining opaque type use in defining scope
//~| ERROR non-defining opaque type use in defining scope
//~| ERROR `T` is part of concrete type but not used in parameter list
//~| ERROR `T` is part of concrete type but not used in parameter list
()
}
56 changes: 3 additions & 53 deletions src/test/ui/type-alias-impl-trait/bound_reduction2.stderr
@@ -1,70 +1,20 @@
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
--> $DIR/bound_reduction2.rs:16:60
|
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
| ____________________________________________________________^
LL | |
LL | |
LL | |
... |
LL | | ()
LL | | }
| |_^

error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
--> $DIR/bound_reduction2.rs:16:60
|
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
| ____________________________________________________________^
LL | |
LL | |
LL | |
... |
LL | | ()
LL | | }
| |_^

error: non-defining opaque type use in defining scope
--> $DIR/bound_reduction2.rs:16:1
--> $DIR/bound_reduction2.rs:16:46
|
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^
|
note: used non-generic type `<T as TraitWithAssoc>::Assoc` for generic parameter
--> $DIR/bound_reduction2.rs:9:10
|
LL | type Foo<V> = impl Trait<V>;
| ^

error: non-defining opaque type use in defining scope
--> $DIR/bound_reduction2.rs:16:1
|
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: used non-generic type `_` for generic parameter
--> $DIR/bound_reduction2.rs:9:10
|
LL | type Foo<V> = impl Trait<V>;
| ^

error: non-defining opaque type use in defining scope
--> $DIR/bound_reduction2.rs:16:1
|
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: used non-generic type `_` for generic parameter
--> $DIR/bound_reduction2.rs:9:10
|
LL | type Foo<V> = impl Trait<V>;
| ^

error: could not find defining uses
--> $DIR/bound_reduction2.rs:9:15
|
LL | type Foo<V> = impl Trait<V>;
| ^^^^^^^^^^^^^

error: aborting due to 6 previous errors
error: aborting due to 2 previous errors

0 comments on commit 689a868

Please sign in to comment.