Treat opaque types failing the signature defining scope check as defining, as we already errored and can hide subsequent errors this way.

This commit is contained in:
Oli Scherer 2023-06-22 15:11:07 +00:00
parent 41881aece2
commit a71628c114
7 changed files with 6 additions and 65 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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 previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -17,7 +17,6 @@ impl Foo for () {
fn foo() -> (Self::Bar<u32>, Self::Baz) {
//~^ ERROR non-defining opaque type use
((), ())
//~^ ERROR mismatched types
}
}

View File

@ -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 previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -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> {}
}

View File

@ -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 previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.