-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #112876 - compiler-errors:check-subst-compat-in-Opaqu…
…eTypeCollector, r=oli-obk Don't substitute a GAT that has mismatched generics in `OpaqueTypeCollector` Fixes #111828 I didn't put up minimized UI tests for #112510 or #112873 because they'd minimize to literally the same code, but with different substs on the trait/impl. I don't think that warrants duplicate tests given the nature of the fix. r? `@oli-obk` ---- Side-note: I checked, and this isn't fixed by #112652 -- I think we discussed whether or not that PR fixed it either intentionally or by accident. The code here isn't really touched by that PR either as far as I can tell? Also, sorry, did some other drive-bys. Hope it doesn't make rebasing #112652 too difficult 😅
- Loading branch information
Showing
8 changed files
with
199 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#![feature(impl_trait_in_assoc_type)] | ||
|
||
// We weren't checking that the trait and impl generics line up in the | ||
// normalization-shortcut code in `OpaqueTypeCollector`. | ||
|
||
use std::ops::Deref; | ||
|
||
trait Foo { | ||
type Bar<'a>; | ||
|
||
type Baz<'a>; | ||
|
||
fn test<'a>() -> Self::Bar<'a>; | ||
} | ||
|
||
impl Foo for () { | ||
type Bar<'a> = impl Deref<Target = Self::Baz<'a>>; | ||
|
||
type Baz<T> = impl Sized; | ||
//~^ ERROR type `Baz` has 1 type parameter but its trait declaration has 0 type parameters | ||
//~| ERROR unconstrained opaque type | ||
|
||
fn test<'a>() -> Self::Bar<'a> { | ||
&() | ||
} | ||
} | ||
|
||
fn main() {} |
20 changes: 20 additions & 0 deletions
20
tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error[E0049]: type `Baz` has 1 type parameter but its trait declaration has 0 type parameters | ||
--> $DIR/impl-trait-in-type-alias-with-bad-substs.rs:19:14 | ||
| | ||
LL | type Baz<'a>; | ||
| -- expected 0 type parameters | ||
... | ||
LL | type Baz<T> = impl Sized; | ||
| ^ found 1 type parameter | ||
|
||
error: unconstrained opaque type | ||
--> $DIR/impl-trait-in-type-alias-with-bad-substs.rs:19:19 | ||
| | ||
LL | type Baz<T> = impl Sized; | ||
| ^^^^^^^^^^ | ||
| | ||
= note: `Baz` must be used in combination with a concrete type within the same impl | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0049`. |
33 changes: 33 additions & 0 deletions
33
tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#![feature(impl_trait_in_assoc_type)] | ||
|
||
trait Foo<T> { | ||
type Assoc; | ||
|
||
fn test() -> u32; | ||
} | ||
|
||
struct DefinesOpaque; | ||
impl Foo<DefinesOpaque> for () { | ||
type Assoc = impl Sized; | ||
|
||
// This test's return type is `u32`, *not* the opaque that is defined above. | ||
// Previously we were only checking that the self type of the assoc matched, | ||
// but this doesn't account for other impls with different trait substs. | ||
fn test() -> <() as Foo<NoOpaques>>::Assoc { | ||
let _: <Self as Foo<DefinesOpaque>>::Assoc = ""; | ||
//~^ ERROR mismatched types | ||
|
||
1 | ||
} | ||
} | ||
|
||
struct NoOpaques; | ||
impl Foo<NoOpaques> for () { | ||
type Assoc = u32; | ||
|
||
fn test() -> u32 { | ||
1 | ||
} | ||
} | ||
|
||
fn main() {} |
22 changes: 22 additions & 0 deletions
22
tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/not-matching-trait-refs-isnt-defining.rs:17:54 | ||
| | ||
LL | type Assoc = impl Sized; | ||
| ---------- the expected opaque type | ||
... | ||
LL | let _: <Self as Foo<DefinesOpaque>>::Assoc = ""; | ||
| ----------------------------------- ^^ expected opaque type, found `&str` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected opaque type `<() as Foo<DefinesOpaque>>::Assoc` | ||
found reference `&'static str` | ||
note: this item must have the opaque type in its signature in order to be able to register hidden types | ||
--> $DIR/not-matching-trait-refs-isnt-defining.rs:16:5 | ||
| | ||
LL | fn test() -> <() as Foo<NoOpaques>>::Assoc { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |