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.
Rollup merge of rust-lang#106931 - Ezrashaw:docs-e0208, r=compiler-er…
…rors document + UI test `E0208` and make its output more user-friendly Cleans up `E0208`'s output a lot. It could actually be useful for someone learning about variance now. I also added a UI test for it in `tests/ui/error-codes/` and wrote some docs for it. r? `@GuillaumeGomez` another error code, can't be bothered to find the issue :P. Obviously there's some compiler stuff, so you'll have to hand it off. Part of rust-lang#61137.
- Loading branch information
Showing
14 changed files
with
96 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
#### This error code is internal to the compiler and will not be emitted with normal Rust code. | ||
#### Note: this error code is no longer emitted by the compiler. | ||
|
||
This error code shows the variance of a type's generic parameters. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail | ||
// NOTE: this feature is perma-unstable and should *only* be used for | ||
// testing purposes. | ||
#![feature(rustc_attrs)] | ||
#[rustc_variance] | ||
struct Foo<'a, T> { // error: deliberate error to display type's variance | ||
t: &'a mut T, | ||
} | ||
``` | ||
|
||
which produces the following error: | ||
|
||
```text | ||
error: [-, o] | ||
--> <anon>:4:1 | ||
| | ||
4 | struct Foo<'a, T> { | ||
| ^^^^^^^^^^^^^^^^^ | ||
``` | ||
|
||
*Note that while `#[rustc_variance]` still exists and is used within the* | ||
*compiler, it no longer is marked as `E0208` and instead has no error code.* | ||
|
||
This error is deliberately triggered with the `#[rustc_variance]` attribute | ||
(`#![feature(rustc_attrs)]` must be enabled) and helps to show you the variance | ||
of the type's generic parameters. You can read more about variance and | ||
subtyping in [this section of the Rustnomicon]. For a more in depth look at | ||
variance (including a more complete list of common variances) see | ||
[this section of the Reference]. For information on how variance is implemented | ||
in the compiler, see [this section of `rustc-dev-guide`]. | ||
|
||
This error can be easily fixed by removing the `#[rustc_variance]` attribute, | ||
the compiler's suggestion to comment it out can be applied automatically with | ||
`rustfix`. | ||
|
||
[this section of the Rustnomicon]: https://doc.rust-lang.org/nomicon/subtyping.html | ||
[this section of the Reference]: https://doc.rust-lang.org/reference/subtyping.html#variance | ||
[this section of `rustc-dev-guide`]: https://rustc-dev-guide.rust-lang.org/variance.html |
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,8 @@ | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_variance] | ||
struct Foo<'a, T> { //~ ERROR [-, o] | ||
t: &'a mut T, | ||
} | ||
|
||
fn main() {} |
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,8 @@ | ||
error: [-, o] | ||
--> $DIR/E0208.rs:4:1 | ||
| | ||
LL | struct Foo<'a, T> { | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
error[E0208]: [o] | ||
error: [o] | ||
--> $DIR/variance-associated-consts.rs:13:1 | ||
| | ||
LL | struct Foo<T: Trait> { | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0208`. |
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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
error[E0208]: [-, +] | ||
error: [-, +] | ||
--> $DIR/variance-associated-types.rs:13:1 | ||
| | ||
LL | struct Foo<'a, T : Trait<'a>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [o, o] | ||
error: [o, o] | ||
--> $DIR/variance-associated-types.rs:18:1 | ||
| | ||
LL | struct Bar<'a, T : Trait<'a>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0208`. |
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
error[E0208]: [o] | ||
error: [o] | ||
--> $DIR/variance-object-types.rs:7:1 | ||
| | ||
LL | struct Foo<'a> { | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0208`. |
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 |
---|---|---|
@@ -1,45 +1,44 @@ | ||
error[E0208]: [-, -, -] | ||
error: [-, -, -] | ||
--> $DIR/variance-regions-direct.rs:9:1 | ||
| | ||
LL | struct Test2<'a, 'b, 'c> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [+, +, +] | ||
error: [+, +, +] | ||
--> $DIR/variance-regions-direct.rs:18:1 | ||
| | ||
LL | struct Test3<'a, 'b, 'c> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [-, o] | ||
error: [-, o] | ||
--> $DIR/variance-regions-direct.rs:27:1 | ||
| | ||
LL | struct Test4<'a, 'b:'a> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [+, o] | ||
error: [+, o] | ||
--> $DIR/variance-regions-direct.rs:35:1 | ||
| | ||
LL | struct Test5<'a, 'b:'a> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [-, o] | ||
error: [-, o] | ||
--> $DIR/variance-regions-direct.rs:45:1 | ||
| | ||
LL | struct Test6<'a, 'b:'a> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [*] | ||
error: [*] | ||
--> $DIR/variance-regions-direct.rs:52:1 | ||
| | ||
LL | struct Test7<'a> { | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [+, -, o] | ||
error: [+, -, o] | ||
--> $DIR/variance-regions-direct.rs:59:1 | ||
| | ||
LL | enum Test8<'a, 'b, 'c:'b> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0208`. |
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 |
---|---|---|
@@ -1,33 +1,32 @@ | ||
error[E0208]: [+, -, o, *] | ||
error: [+, -, o, *] | ||
--> $DIR/variance-regions-indirect.rs:8:1 | ||
| | ||
LL | enum Base<'a, 'b, 'c:'b, 'd> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [*, o, -, +] | ||
error: [*, o, -, +] | ||
--> $DIR/variance-regions-indirect.rs:15:1 | ||
| | ||
LL | struct Derived1<'w, 'x:'y, 'y, 'z> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [o, o, *] | ||
error: [o, o, *] | ||
--> $DIR/variance-regions-indirect.rs:20:1 | ||
| | ||
LL | struct Derived2<'a, 'b:'a, 'c> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [o, -, *] | ||
error: [o, -, *] | ||
--> $DIR/variance-regions-indirect.rs:25:1 | ||
| | ||
LL | struct Derived3<'a:'b, 'b, 'c> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [+, -, o] | ||
error: [+, -, o] | ||
--> $DIR/variance-regions-indirect.rs:30:1 | ||
| | ||
LL | struct Derived4<'a, 'b, 'c:'b> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0208`. |
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 |
---|---|---|
@@ -1,27 +1,26 @@ | ||
error[E0208]: [+, +] | ||
error: [+, +] | ||
--> $DIR/variance-trait-bounds.rs:16:1 | ||
| | ||
LL | struct TestStruct<U,T:Setter<U>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [*, +] | ||
error: [*, +] | ||
--> $DIR/variance-trait-bounds.rs:21:1 | ||
| | ||
LL | enum TestEnum<U,T:Setter<U>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [*, +] | ||
error: [*, +] | ||
--> $DIR/variance-trait-bounds.rs:26:1 | ||
| | ||
LL | struct TestContraStruct<U,T:Setter<U>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [*, +] | ||
error: [*, +] | ||
--> $DIR/variance-trait-bounds.rs:31:1 | ||
| | ||
LL | struct TestBox<U,T:Getter<U>+Setter<U>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0208`. |
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
error[E0208]: [-] | ||
error: [-] | ||
--> $DIR/variance-trait-object-bound.rs:14:1 | ||
| | ||
LL | struct TOption<'a> { | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0208`. |
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 |
---|---|---|
@@ -1,33 +1,32 @@ | ||
error[E0208]: [+, +] | ||
error: [+, +] | ||
--> $DIR/variance-types-bounds.rs:7:1 | ||
| | ||
LL | struct TestImm<A, B> { | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [+, o] | ||
error: [+, o] | ||
--> $DIR/variance-types-bounds.rs:13:1 | ||
| | ||
LL | struct TestMut<A, B:'static> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [+, o] | ||
error: [+, o] | ||
--> $DIR/variance-types-bounds.rs:19:1 | ||
| | ||
LL | struct TestIndirect<A:'static, B:'static> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [o, o] | ||
error: [o, o] | ||
--> $DIR/variance-types-bounds.rs:24:1 | ||
| | ||
LL | struct TestIndirect2<A:'static, B:'static> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [o, o] | ||
error: [o, o] | ||
--> $DIR/variance-types-bounds.rs:38:1 | ||
| | ||
LL | struct TestObject<A, R> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0208`. |
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 |
---|---|---|
@@ -1,39 +1,38 @@ | ||
error[E0208]: [-, o, o] | ||
error: [-, o, o] | ||
--> $DIR/variance-types.rs:10:1 | ||
| | ||
LL | struct InvariantMut<'a,A:'a,B:'a> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [o] | ||
error: [o] | ||
--> $DIR/variance-types.rs:15:1 | ||
| | ||
LL | struct InvariantCell<A> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [o] | ||
error: [o] | ||
--> $DIR/variance-types.rs:20:1 | ||
| | ||
LL | struct InvariantIndirect<A> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [+] | ||
error: [+] | ||
--> $DIR/variance-types.rs:25:1 | ||
| | ||
LL | struct Covariant<A> { | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [-] | ||
error: [-] | ||
--> $DIR/variance-types.rs:30:1 | ||
| | ||
LL | struct Contravariant<A> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0208]: [+, -, o] | ||
error: [+, -, o] | ||
--> $DIR/variance-types.rs:35:1 | ||
| | ||
LL | enum Enum<A,B,C> { | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0208`. |