about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-06-22 15:11:07 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-06-22 15:36:42 +0000
commita71628c1147ce8b739799e33da352b3fa11559bb (patch)
tree386850f6d39c680a267f2a8caaa8fadb17f3ea8a
parent41881aece2aac46b21c509dadb0b101da1f7d6bb (diff)
downloadrust-a71628c1147ce8b739799e33da352b3fa11559bb.tar.gz
rust-a71628c1147ce8b739799e33da352b3fa11559bb.zip
Treat opaque types failing the signature defining scope check as defining, as we already errored and can hide subsequent errors this way.
-rw-r--r--compiler/rustc_ty_utils/src/opaque_types.rs5
-rw-r--r--tests/ui/generic-associated-types/issue-88595.rs1
-rw-r--r--tests/ui/generic-associated-types/issue-88595.stderr22
-rw-r--r--tests/ui/type-alias-impl-trait/multi-error.rs1
-rw-r--r--tests/ui/type-alias-impl-trait/multi-error.stderr20
-rw-r--r--tests/ui/type-alias-impl-trait/non-defining-method.rs1
-rw-r--r--tests/ui/type-alias-impl-trait/non-defining-method.stderr21
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<TyCtxt<'tcx>> 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 `<C as A<'a>>::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 2 previous errors
+error: aborting due to previous error
 
-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<u32>, 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<T> = impl Sized;
    |                   ^^^^^^^^^^
 
-error[E0308]: mismatched types
-  --> $DIR/multi-error.rs:19:10
-   |
-LL |     type Bar<T> = impl Sized;
-   |                   ---------- the expected opaque type
-...
-LL |         ((), ())
-   |          ^^ expected opaque type, found `()`
-   |
-   = note: expected opaque type `<() as Foo>::Bar<u32>`
-                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<u32>, Self::Baz) {
-   |        ^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
-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<T> = impl Sized;
     fn foo() -> Self::Bar<u32> {}
     //~^ ERROR non-defining opaque type use
-    //~| ERROR mismatched types
     fn bar<T>() -> Self::Bar<T> {}
 }
 
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<T> = impl Sized;
    |                   ^^^^^^^^^^
 
-error[E0308]: mismatched types
-  --> $DIR/non-defining-method.rs:16:17
-   |
-LL |     type Bar<T> = impl Sized;
-   |                   ---------- the expected opaque type
-LL |     fn foo() -> Self::Bar<u32> {}
-   |        ---      ^^^^^^^^^^^^^^ expected opaque type, found `()`
-   |        |
-   |        implicitly returns `()` as its body has no tail or `return` expression
-   |
-   = note: expected opaque type `<() as Foo>::Bar<u32>`
-                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<u32> {}
-   |        ^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0308`.