Skip to content

Commit

Permalink
Handle impl-trait-in-assoc-types separately from type-alias-impl-trait
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Mar 5, 2024
1 parent da32028 commit fbcfe97
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 46 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_ty_utils/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
self.visit_opaque_ty(alias_ty);
}
ty::Alias(ty::Projection, alias_ty) => {
if let CollectionMode::TypeAliasImplTraitTransition = self.mode {
return ControlFlow::Continue(());
}
// This avoids having to do normalization of `Self::AssocTy` by only
// supporting the case of a method defining opaque types from assoc types
// in the same impl block.
Expand Down
1 change: 0 additions & 1 deletion tests/ui/generic-associated-types/issue-88595.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ impl<'a> A<'a> for C {

fn a(&'a self) -> Self::B<'a> {} //~ 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
}
15 changes: 1 addition & 14 deletions tests/ui/generic-associated-types/issue-88595.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ note: for this opaque type
LL | type B<'b> = impl Clone;
| ^^^^^^^^^^

error: non-defining opaque type use in defining scope
--> $DIR/issue-88595.rs:21:23
|
LL | fn a(&'a self) -> Self::B<'a> {}
| ^^^^^^^^^^^ generic argument `'a` used twice
|
note: for this opaque type
--> $DIR/issue-88595.rs:19:18
|
LL | type B<'b> = impl Clone;
| ^^^^^^^^^^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: non-defining opaque type use in defining scope
--> $DIR/issue-88595.rs:21:35
|
Expand All @@ -37,5 +24,5 @@ LL | impl<'a> A<'a> for C {
LL | type B<'b> = impl Clone;
| ^^

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

1 change: 0 additions & 1 deletion tests/ui/type-alias-impl-trait/multi-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ impl Foo for () {
type Baz = impl Sized;
fn foo() -> (Self::Bar<u32>, Self::Baz) {
//~^ ERROR non-defining opaque type use
//~| ERROR non-defining opaque type use
((), ())
//~^ ERROR expected generic type parameter
}
Expand Down
17 changes: 2 additions & 15 deletions tests/ui/type-alias-impl-trait/multi-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,15 @@ note: for this opaque type
LL | type Bar<T> = impl Sized;
| ^^^^^^^^^^

error[E0792]: non-defining opaque type use in defining scope
--> $DIR/multi-error.rs:17:17
|
LL | fn foo() -> (Self::Bar<u32>, Self::Baz) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument `u32` is not a generic parameter
|
note: for this opaque type
--> $DIR/multi-error.rs:15:19
|
LL | type Bar<T> = impl Sized;
| ^^^^^^^^^^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0792]: expected generic type parameter, found `u32`
--> $DIR/multi-error.rs:20:9
--> $DIR/multi-error.rs:19:9
|
LL | type Bar<T> = impl Sized;
| - this generic parameter must be used with a generic type parameter
...
LL | ((), ())
| ^^^^^^^^

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0792`.
1 change: 0 additions & 1 deletion tests/ui/type-alias-impl-trait/non-defining-method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ impl Foo for () {
type Bar<T> = impl Sized;
fn foo() -> Self::Bar<u32> {}
//~^ ERROR non-defining opaque type use
//~| ERROR non-defining opaque type use
//~| ERROR expected generic type parameter, found `u32`
fn bar<T>() -> Self::Bar<T> {}
}
Expand Down
15 changes: 1 addition & 14 deletions tests/ui/type-alias-impl-trait/non-defining-method.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ note: for this opaque type
LL | type Bar<T> = impl Sized;
| ^^^^^^^^^^

error[E0792]: non-defining opaque type use in defining scope
--> $DIR/non-defining-method.rs:16:17
|
LL | fn foo() -> Self::Bar<u32> {}
| ^^^^^^^^^^^^^^ argument `u32` is not a generic parameter
|
note: for this opaque type
--> $DIR/non-defining-method.rs:15:19
|
LL | type Bar<T> = impl Sized;
| ^^^^^^^^^^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0792]: expected generic type parameter, found `u32`
--> $DIR/non-defining-method.rs:16:32
|
Expand All @@ -31,6 +18,6 @@ LL | type Bar<T> = impl Sized;
LL | fn foo() -> Self::Bar<u32> {}
| ^^

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

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

0 comments on commit fbcfe97

Please sign in to comment.