From a71628c1147ce8b739799e33da352b3fa11559bb Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 22 Jun 2023 15:11:07 +0000 Subject: [PATCH] Treat opaque types failing the signature defining scope check as defining, as we already errored and can hide subsequent errors this way. --- compiler/rustc_ty_utils/src/opaque_types.rs | 5 +++-- .../generic-associated-types/issue-88595.rs | 1 - .../issue-88595.stderr | 22 +------------------ tests/ui/type-alias-impl-trait/multi-error.rs | 1 - .../type-alias-impl-trait/multi-error.stderr | 20 +---------------- .../non-defining-method.rs | 1 - .../non-defining-method.stderr | 21 +----------------- 7 files changed, 6 insertions(+), 65 deletions(-) diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index d64569db566..ab97406452e 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -72,14 +72,15 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { if !self.seen.insert(alias_ty.def_id.expect_local()) { return ControlFlow::Continue(()); } + + self.opaques.push(alias_ty.def_id.expect_local()); + match self.tcx.uses_unique_generic_params(alias_ty.substs, CheckRegions::Bound) { Ok(()) => { // FIXME: implement higher kinded lifetime bounds on nested opaque types. They are not // supported at all, so this is sound to do, but once we want to support them, you'll // start seeing the error below. - self.opaques.push(alias_ty.def_id.expect_local()); - // Collect opaque types nested within the associated type bounds of this opaque type. for (pred, span) in self .tcx diff --git a/tests/ui/generic-associated-types/issue-88595.rs b/tests/ui/generic-associated-types/issue-88595.rs index 7de906e7ef3..5a40a612972 100644 --- a/tests/ui/generic-associated-types/issue-88595.rs +++ b/tests/ui/generic-associated-types/issue-88595.rs @@ -19,5 +19,4 @@ impl<'a> A<'a> for C { type B<'b> = impl Clone; fn a(&'a self) -> Self::B<'a> {} //~ ERROR: non-defining opaque type use in defining scope - //~^ ERROR: mismatched types } diff --git a/tests/ui/generic-associated-types/issue-88595.stderr b/tests/ui/generic-associated-types/issue-88595.stderr index b0f6864f6ec..2b1a25acfa4 100644 --- a/tests/ui/generic-associated-types/issue-88595.stderr +++ b/tests/ui/generic-associated-types/issue-88595.stderr @@ -10,25 +10,5 @@ note: for this opaque type LL | type B<'b> = impl Clone; | ^^^^^^^^^^ -error[E0308]: mismatched types - --> $DIR/issue-88595.rs:21:23 - | -LL | type B<'b> = impl Clone; - | ---------- the expected opaque type -LL | -LL | fn a(&'a self) -> Self::B<'a> {} - | - ^^^^^^^^^^^ expected opaque type, found `()` - | | - | implicitly returns `()` as its body has no tail or `return` expression - | - = note: expected opaque type `>::B<'a>` - found unit type `()` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/issue-88595.rs:21:8 - | -LL | fn a(&'a self) -> Self::B<'a> {} - | ^ +error: aborting due to previous error -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/multi-error.rs b/tests/ui/type-alias-impl-trait/multi-error.rs index 7cae9a12cb2..b5ff06572d0 100644 --- a/tests/ui/type-alias-impl-trait/multi-error.rs +++ b/tests/ui/type-alias-impl-trait/multi-error.rs @@ -17,7 +17,6 @@ impl Foo for () { fn foo() -> (Self::Bar, Self::Baz) { //~^ ERROR non-defining opaque type use ((), ()) - //~^ ERROR mismatched types } } diff --git a/tests/ui/type-alias-impl-trait/multi-error.stderr b/tests/ui/type-alias-impl-trait/multi-error.stderr index 1b7b96075be..6d8fa0fb021 100644 --- a/tests/ui/type-alias-impl-trait/multi-error.stderr +++ b/tests/ui/type-alias-impl-trait/multi-error.stderr @@ -10,23 +10,5 @@ note: for this opaque type LL | type Bar = impl Sized; | ^^^^^^^^^^ -error[E0308]: mismatched types - --> $DIR/multi-error.rs:19:10 - | -LL | type Bar = impl Sized; - | ---------- the expected opaque type -... -LL | ((), ()) - | ^^ expected opaque type, found `()` - | - = note: expected opaque type `<() as Foo>::Bar` - found unit type `()` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/multi-error.rs:17:8 - | -LL | fn foo() -> (Self::Bar, Self::Baz) { - | ^^^ +error: aborting due to previous error -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/non-defining-method.rs b/tests/ui/type-alias-impl-trait/non-defining-method.rs index 66ceedee8f7..2f4a7052f72 100644 --- a/tests/ui/type-alias-impl-trait/non-defining-method.rs +++ b/tests/ui/type-alias-impl-trait/non-defining-method.rs @@ -15,7 +15,6 @@ impl Foo for () { type Bar = impl Sized; fn foo() -> Self::Bar {} //~^ ERROR non-defining opaque type use - //~| ERROR mismatched types fn bar() -> Self::Bar {} } diff --git a/tests/ui/type-alias-impl-trait/non-defining-method.stderr b/tests/ui/type-alias-impl-trait/non-defining-method.stderr index f203cff9036..61bf2da20db 100644 --- a/tests/ui/type-alias-impl-trait/non-defining-method.stderr +++ b/tests/ui/type-alias-impl-trait/non-defining-method.stderr @@ -10,24 +10,5 @@ note: for this opaque type LL | type Bar = impl Sized; | ^^^^^^^^^^ -error[E0308]: mismatched types - --> $DIR/non-defining-method.rs:16:17 - | -LL | type Bar = impl Sized; - | ---------- the expected opaque type -LL | fn foo() -> Self::Bar {} - | --- ^^^^^^^^^^^^^^ expected opaque type, found `()` - | | - | implicitly returns `()` as its body has no tail or `return` expression - | - = note: expected opaque type `<() as Foo>::Bar` - found unit type `()` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/non-defining-method.rs:16:8 - | -LL | fn foo() -> Self::Bar {} - | ^^^ +error: aborting due to previous error -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`.