From 689a868a1f6f20b49ea904ca7cda14636b7768b3 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 16 Dec 2021 15:17:16 +0000 Subject: [PATCH] Remove some noise from opaque type errors around associated types --- .../rustc_infer/src/infer/opaque_types.rs | 14 +++++ .../type-alias-impl-trait/bound_reduction2.rs | 4 -- .../bound_reduction2.stderr | 56 +------------------ 3 files changed, 17 insertions(+), 57 deletions(-) diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index c2ef0b41e27bf..eab5e5a5fb4e9 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -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, diff --git a/src/test/ui/type-alias-impl-trait/bound_reduction2.rs b/src/test/ui/type-alias-impl-trait/bound_reduction2.rs index 579067340e85c..cee8186dd8f8c 100644 --- a/src/test/ui/type-alias-impl-trait/bound_reduction2.rs +++ b/src/test/ui/type-alias-impl-trait/bound_reduction2.rs @@ -15,9 +15,5 @@ impl Trait for () {} fn foo_desugared(_: T) -> Foo { //~^ 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 () } diff --git a/src/test/ui/type-alias-impl-trait/bound_reduction2.stderr b/src/test/ui/type-alias-impl-trait/bound_reduction2.stderr index a77c0000f12e1..03e696fe89803 100644 --- a/src/test/ui/type-alias-impl-trait/bound_reduction2.stderr +++ b/src/test/ui/type-alias-impl-trait/bound_reduction2.stderr @@ -1,34 +1,8 @@ -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) -> Foo { - | ____________________________________________________________^ -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) -> Foo { - | ____________________________________________________________^ -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) -> Foo { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ | note: used non-generic type `::Assoc` for generic parameter --> $DIR/bound_reduction2.rs:9:10 @@ -36,35 +10,11 @@ note: used non-generic type `::Assoc` for generic parameter LL | type Foo = impl Trait; | ^ -error: non-defining opaque type use in defining scope - --> $DIR/bound_reduction2.rs:16:1 - | -LL | fn foo_desugared(_: T) -> Foo { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: used non-generic type `_` for generic parameter - --> $DIR/bound_reduction2.rs:9:10 - | -LL | type Foo = impl Trait; - | ^ - -error: non-defining opaque type use in defining scope - --> $DIR/bound_reduction2.rs:16:1 - | -LL | fn foo_desugared(_: T) -> Foo { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: used non-generic type `_` for generic parameter - --> $DIR/bound_reduction2.rs:9:10 - | -LL | type Foo = impl Trait; - | ^ - error: could not find defining uses --> $DIR/bound_reduction2.rs:9:15 | LL | type Foo = impl Trait; | ^^^^^^^^^^^^^ -error: aborting due to 6 previous errors +error: aborting due to 2 previous errors