forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Orphanck: Consider opaque types to never cover type parameters
- Loading branch information
Showing
7 changed files
with
114 additions
and
36 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
21 changes: 21 additions & 0 deletions
21
tests/ui/coherence/orphan-check-opaque-types-not-covering.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,21 @@ | ||
error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | ||
--> $DIR/orphan-check-opaque-types-not-covering.rs:17:6 | ||
| | ||
LL | impl<T> foreign::Trait0<Local, T, ()> for Identity<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-opaque-types-not-covering.rs:26:6 | ||
| | ||
LL | impl<T> foreign::Trait1<Local, T> for Opaque<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: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0210`. |
21 changes: 21 additions & 0 deletions
21
tests/ui/coherence/orphan-check-opaque-types-not-covering.next.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,21 @@ | ||
error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | ||
--> $DIR/orphan-check-opaque-types-not-covering.rs:17:6 | ||
| | ||
LL | impl<T> foreign::Trait0<Local, T, ()> for Identity<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-opaque-types-not-covering.rs:26:6 | ||
| | ||
LL | impl<T> foreign::Trait1<Local, T> for Opaque<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: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0210`. |
31 changes: 31 additions & 0 deletions
31
tests/ui/coherence/orphan-check-opaque-types-not-covering.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,31 @@ | ||
// Opaque types never cover type parameters. | ||
|
||
//@ revisions: classic next | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
//@ aux-crate:foreign=parametrized-trait.rs | ||
//@ edition:2021 | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
type Identity<T> = impl Sized; | ||
|
||
fn define_identity<T>(x: T) -> Identity<T> { | ||
x | ||
} | ||
|
||
impl<T> foreign::Trait0<Local, T, ()> for Identity<T> {} | ||
//~^ ERROR type parameter `T` must be covered by another type | ||
|
||
type Opaque<T> = impl Sized; | ||
|
||
fn define_local<T>() -> Opaque<T> { | ||
Local | ||
} | ||
|
||
impl<T> foreign::Trait1<Local, T> for Opaque<T> {} | ||
//~^ ERROR type parameter `T` must be covered by another type | ||
|
||
struct Local; | ||
|
||
fn main() {} |
2 changes: 1 addition & 1 deletion
2
...ui/type-alias-impl-trait/coherence.stderr → ...alias-impl-trait/coherence.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
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,14 @@ | ||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types | ||
--> $DIR/coherence.rs:16:1 | ||
| | ||
LL | impl foreign_crate::ForeignTrait for AliasOfForeignType<()> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------- | ||
| | | | ||
| | `AliasOfForeignType<()>` is not defined in the current crate | ||
| impl doesn't use only types from inside the current crate | ||
| | ||
= note: define and implement a trait or new type instead | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0117`. |
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