-
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.
Normalize trait ref before orphan check
- Loading branch information
Showing
14 changed files
with
275 additions
and
29 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub trait Trait0<T, U, V> {} | ||
pub trait Trait1<T, U> {} |
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,24 @@ | ||
// Projections can cover type parameters if they normalize to a (local) type that covers them. | ||
// This ensures that we don't perform an overly strict check on | ||
// projections like in closed PR #100555 which did a syntactic | ||
// check for type parameters in projections without normalizing | ||
// first which would've lead to real-word regressions. | ||
|
||
// check-pass | ||
// revisions: classic next | ||
//[next] compile-flags: -Ztrait-solver=next | ||
|
||
// aux-crate:foreign=parametrized-trait.rs | ||
// edition:2021 | ||
|
||
trait Project { type Output; } | ||
|
||
impl<T> Project for T { | ||
type Output = Local; | ||
} | ||
|
||
struct Local; | ||
|
||
impl<T> foreign::Trait1<Local, T> for <T as Project>::Output {} | ||
|
||
fn main() {} |
30 changes: 30 additions & 0 deletions
30
tests/ui/coherence/orphan-check-projection-doesnt-cover.classic.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,30 @@ | ||
error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | ||
--> $DIR/orphan-check-projection-doesnt-cover.rs:25:6 | ||
| | ||
LL | impl<T> foreign::Trait0<Local, T, ()> for <T as Identity>::Output {} | ||
| ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | ||
| | ||
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type | ||
= note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last | ||
|
||
error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | ||
--> $DIR/orphan-check-projection-doesnt-cover.rs:28:6 | ||
| | ||
LL | impl<T> foreign::Trait0<<T as Identity>::Output, Local, T> for Option<T> {} | ||
| ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | ||
| | ||
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type | ||
= note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last | ||
|
||
error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | ||
--> $DIR/orphan-check-projection-doesnt-cover.rs:40:6 | ||
| | ||
LL | impl<T: Deferred> foreign::Trait1<Local, T> for <T as Deferred>::Output {} | ||
| ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | ||
| | ||
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type | ||
= note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0210`. |
41 changes: 41 additions & 0 deletions
41
tests/ui/coherence/orphan-check-projection-doesnt-cover.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,41 @@ | ||
// Regression test for issue #99554. | ||
// Projections might not cover type parameters. | ||
|
||
// revisions: classic next | ||
//[next] compile-flags: -Ztrait-solver=next | ||
|
||
// FIXME(-Ztrait-solver=next): This currently passes in the next solver but it shouldn't. | ||
//[next] check-pass | ||
//[next] known-bug: unknown | ||
|
||
// compile-flags: --crate-type=lib | ||
// aux-crate:foreign=parametrized-trait.rs | ||
// edition:2021 | ||
|
||
trait Identity { | ||
type Output; | ||
} | ||
|
||
impl<T> Identity for T { | ||
type Output = T; | ||
} | ||
|
||
struct Local; | ||
|
||
impl<T> foreign::Trait0<Local, T, ()> for <T as Identity>::Output {} | ||
//[classic]~^ ERROR type parameter `T` must be covered by another type | ||
|
||
impl<T> foreign::Trait0<<T as Identity>::Output, Local, T> for Option<T> {} | ||
//[classic]~^ ERROR type parameter `T` must be covered by another type | ||
|
||
pub trait Deferred { | ||
type Output; | ||
} | ||
|
||
// A downstream user could implement | ||
// | ||
// impl<T> Deferred for Type<T> { type Output = T; } | ||
// struct Type<T>(T); | ||
// | ||
impl<T: Deferred> foreign::Trait1<Local, T> for <T as Deferred>::Output {} | ||
//[classic]~^ ERROR type parameter `T` must be covered by another type |
Oops, something went wrong.