-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
10 changed files
with
143 additions
and
32 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
12 changes: 12 additions & 0 deletions
12
tests/ui/coherence/orphan-check-opaque-types-not-covering-0.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,12 @@ | ||
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-0.rs:17:6 | ||
| | ||
LL | impl<T> foreign::Trait1<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: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0210`. |
12 changes: 12 additions & 0 deletions
12
tests/ui/coherence/orphan-check-opaque-types-not-covering-0.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,12 @@ | ||
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-0.rs:17:6 | ||
| | ||
LL | impl<T> foreign::Trait1<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: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0210`. |
22 changes: 22 additions & 0 deletions
22
tests/ui/coherence/orphan-check-opaque-types-not-covering-0.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,22 @@ | ||
// 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<T>(x: T) -> Identity<T> { | ||
x | ||
} | ||
|
||
impl<T> foreign::Trait1<Local, T> for Identity<T> {} | ||
//~^ ERROR type parameter `T` must be covered by another type | ||
|
||
struct Local; | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
tests/ui/coherence/orphan-check-opaque-types-not-covering-1.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,12 @@ | ||
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-1.rs:17: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 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0210`. |
12 changes: 12 additions & 0 deletions
12
tests/ui/coherence/orphan-check-opaque-types-not-covering-1.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,12 @@ | ||
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-1.rs:17: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 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0210`. |
22 changes: 22 additions & 0 deletions
22
tests/ui/coherence/orphan-check-opaque-types-not-covering-1.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,22 @@ | ||
// 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 Opaque<T> = impl Sized; | ||
|
||
fn define<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,11 @@ | ||
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<()> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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