Skip to content

Commit a71628c

Browse files
committed
Treat opaque types failing the signature defining scope check as defining, as we already errored and can hide subsequent errors this way.
1 parent 41881ae commit a71628c

File tree

7 files changed

+6
-65
lines changed

7 files changed

+6
-65
lines changed

compiler/rustc_ty_utils/src/opaque_types.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
7272
if !self.seen.insert(alias_ty.def_id.expect_local()) {
7373
return ControlFlow::Continue(());
7474
}
75+
76+
self.opaques.push(alias_ty.def_id.expect_local());
77+
7578
match self.tcx.uses_unique_generic_params(alias_ty.substs, CheckRegions::Bound) {
7679
Ok(()) => {
7780
// FIXME: implement higher kinded lifetime bounds on nested opaque types. They are not
7881
// supported at all, so this is sound to do, but once we want to support them, you'll
7982
// start seeing the error below.
8083

81-
self.opaques.push(alias_ty.def_id.expect_local());
82-
8384
// Collect opaque types nested within the associated type bounds of this opaque type.
8485
for (pred, span) in self
8586
.tcx

tests/ui/generic-associated-types/issue-88595.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ impl<'a> A<'a> for C {
1919
type B<'b> = impl Clone;
2020

2121
fn a(&'a self) -> Self::B<'a> {} //~ ERROR: non-defining opaque type use in defining scope
22-
//~^ ERROR: mismatched types
2322
}

tests/ui/generic-associated-types/issue-88595.stderr

+1-21
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,5 @@ note: for this opaque type
1010
LL | type B<'b> = impl Clone;
1111
| ^^^^^^^^^^
1212

13-
error[E0308]: mismatched types
14-
--> $DIR/issue-88595.rs:21:23
15-
|
16-
LL | type B<'b> = impl Clone;
17-
| ---------- the expected opaque type
18-
LL |
19-
LL | fn a(&'a self) -> Self::B<'a> {}
20-
| - ^^^^^^^^^^^ expected opaque type, found `()`
21-
| |
22-
| implicitly returns `()` as its body has no tail or `return` expression
23-
|
24-
= note: expected opaque type `<C as A<'a>>::B<'a>`
25-
found unit type `()`
26-
note: this item must have the opaque type in its signature in order to be able to register hidden types
27-
--> $DIR/issue-88595.rs:21:8
28-
|
29-
LL | fn a(&'a self) -> Self::B<'a> {}
30-
| ^
31-
32-
error: aborting due to 2 previous errors
13+
error: aborting due to previous error
3314

34-
For more information about this error, try `rustc --explain E0308`.

tests/ui/type-alias-impl-trait/multi-error.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ impl Foo for () {
1717
fn foo() -> (Self::Bar<u32>, Self::Baz) {
1818
//~^ ERROR non-defining opaque type use
1919
((), ())
20-
//~^ ERROR mismatched types
2120
}
2221
}
2322

tests/ui/type-alias-impl-trait/multi-error.stderr

+1-19
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,5 @@ note: for this opaque type
1010
LL | type Bar<T> = impl Sized;
1111
| ^^^^^^^^^^
1212

13-
error[E0308]: mismatched types
14-
--> $DIR/multi-error.rs:19:10
15-
|
16-
LL | type Bar<T> = impl Sized;
17-
| ---------- the expected opaque type
18-
...
19-
LL | ((), ())
20-
| ^^ expected opaque type, found `()`
21-
|
22-
= note: expected opaque type `<() as Foo>::Bar<u32>`
23-
found unit type `()`
24-
note: this item must have the opaque type in its signature in order to be able to register hidden types
25-
--> $DIR/multi-error.rs:17:8
26-
|
27-
LL | fn foo() -> (Self::Bar<u32>, Self::Baz) {
28-
| ^^^
29-
30-
error: aborting due to 2 previous errors
13+
error: aborting due to previous error
3114

32-
For more information about this error, try `rustc --explain E0308`.

tests/ui/type-alias-impl-trait/non-defining-method.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ impl Foo for () {
1515
type Bar<T> = impl Sized;
1616
fn foo() -> Self::Bar<u32> {}
1717
//~^ ERROR non-defining opaque type use
18-
//~| ERROR mismatched types
1918
fn bar<T>() -> Self::Bar<T> {}
2019
}
2120

tests/ui/type-alias-impl-trait/non-defining-method.stderr

+1-20
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,5 @@ note: for this opaque type
1010
LL | type Bar<T> = impl Sized;
1111
| ^^^^^^^^^^
1212

13-
error[E0308]: mismatched types
14-
--> $DIR/non-defining-method.rs:16:17
15-
|
16-
LL | type Bar<T> = impl Sized;
17-
| ---------- the expected opaque type
18-
LL | fn foo() -> Self::Bar<u32> {}
19-
| --- ^^^^^^^^^^^^^^ expected opaque type, found `()`
20-
| |
21-
| implicitly returns `()` as its body has no tail or `return` expression
22-
|
23-
= note: expected opaque type `<() as Foo>::Bar<u32>`
24-
found unit type `()`
25-
note: this item must have the opaque type in its signature in order to be able to register hidden types
26-
--> $DIR/non-defining-method.rs:16:8
27-
|
28-
LL | fn foo() -> Self::Bar<u32> {}
29-
| ^^^
30-
31-
error: aborting due to 2 previous errors
13+
error: aborting due to previous error
3214

33-
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)