diff --git a/compiler/rustc_error_codes/src/error_codes/E0208.md b/compiler/rustc_error_codes/src/error_codes/E0208.md index 7edd93e56a945..1ae01106f2014 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0208.md +++ b/compiler/rustc_error_codes/src/error_codes/E0208.md @@ -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] + --> :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 diff --git a/compiler/rustc_hir_analysis/src/variance/test.rs b/compiler/rustc_hir_analysis/src/variance/test.rs index 83ed3e44b3d73..5feeb92d33782 100644 --- a/compiler/rustc_hir_analysis/src/variance/test.rs +++ b/compiler/rustc_hir_analysis/src/variance/test.rs @@ -1,4 +1,3 @@ -use rustc_errors::struct_span_err; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::sym; @@ -8,8 +7,8 @@ pub fn test_variance(tcx: TyCtxt<'_>) { for id in tcx.hir().items() { if tcx.has_attr(id.owner_id.to_def_id(), sym::rustc_variance) { let variances_of = tcx.variances_of(id.owner_id); - struct_span_err!(tcx.sess, tcx.def_span(id.owner_id), E0208, "{:?}", variances_of) - .emit(); + + tcx.sess.struct_span_err(tcx.def_span(id.owner_id), format!("{variances_of:?}")).emit(); } } } diff --git a/src/tools/tidy/src/error_codes.rs b/src/tools/tidy/src/error_codes.rs index bc9fd35ecde37..5b84b51a035d4 100644 --- a/src/tools/tidy/src/error_codes.rs +++ b/src/tools/tidy/src/error_codes.rs @@ -27,8 +27,7 @@ const ERROR_DOCS_PATH: &str = "compiler/rustc_error_codes/src/error_codes/"; const ERROR_TESTS_PATH: &str = "tests/ui/error-codes/"; // Error codes that (for some reason) can't have a doctest in their explanation. Error codes are still expected to provide a code example, even if untested. -const IGNORE_DOCTEST_CHECK: &[&str] = - &["E0208", "E0464", "E0570", "E0601", "E0602", "E0640", "E0717"]; +const IGNORE_DOCTEST_CHECK: &[&str] = &["E0464", "E0570", "E0601", "E0602", "E0640", "E0717"]; // Error codes that don't yet have a UI test. This list will eventually be removed. const IGNORE_UI_TEST_CHECK: &[&str] = diff --git a/tests/ui/error-codes/E0208.rs b/tests/ui/error-codes/E0208.rs new file mode 100644 index 0000000000000..c67d42889d69b --- /dev/null +++ b/tests/ui/error-codes/E0208.rs @@ -0,0 +1,8 @@ +#![feature(rustc_attrs)] + +#[rustc_variance] +struct Foo<'a, T> { //~ ERROR [-, o] + t: &'a mut T, +} + +fn main() {} diff --git a/tests/ui/error-codes/E0208.stderr b/tests/ui/error-codes/E0208.stderr new file mode 100644 index 0000000000000..dbbb41e79500c --- /dev/null +++ b/tests/ui/error-codes/E0208.stderr @@ -0,0 +1,8 @@ +error: [-, o] + --> $DIR/E0208.rs:4:1 + | +LL | struct Foo<'a, T> { + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/ui/variance/variance-associated-consts.stderr b/tests/ui/variance/variance-associated-consts.stderr index f9732d02cb285..4df2d8da3d680 100644 --- a/tests/ui/variance/variance-associated-consts.stderr +++ b/tests/ui/variance/variance-associated-consts.stderr @@ -1,4 +1,4 @@ -error[E0208]: [o] +error: [o] --> $DIR/variance-associated-consts.rs:13:1 | LL | struct Foo { @@ -6,4 +6,3 @@ LL | struct Foo { error: aborting due to previous error -For more information about this error, try `rustc --explain E0208`. diff --git a/tests/ui/variance/variance-associated-types.stderr b/tests/ui/variance/variance-associated-types.stderr index 5ce62884e1d83..51f17c7c22887 100644 --- a/tests/ui/variance/variance-associated-types.stderr +++ b/tests/ui/variance/variance-associated-types.stderr @@ -1,10 +1,10 @@ -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>> { @@ -12,4 +12,3 @@ LL | struct Bar<'a, T : Trait<'a>> { error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0208`. diff --git a/tests/ui/variance/variance-object-types.stderr b/tests/ui/variance/variance-object-types.stderr index 1c3c1a6d1f223..55a760425ee59 100644 --- a/tests/ui/variance/variance-object-types.stderr +++ b/tests/ui/variance/variance-object-types.stderr @@ -1,4 +1,4 @@ -error[E0208]: [o] +error: [o] --> $DIR/variance-object-types.rs:7:1 | LL | struct Foo<'a> { @@ -6,4 +6,3 @@ LL | struct Foo<'a> { error: aborting due to previous error -For more information about this error, try `rustc --explain E0208`. diff --git a/tests/ui/variance/variance-regions-direct.stderr b/tests/ui/variance/variance-regions-direct.stderr index 27d69b6e82575..eda02e9b03bb8 100644 --- a/tests/ui/variance/variance-regions-direct.stderr +++ b/tests/ui/variance/variance-regions-direct.stderr @@ -1,40 +1,40 @@ -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> { @@ -42,4 +42,3 @@ LL | enum Test8<'a, 'b, 'c:'b> { error: aborting due to 7 previous errors -For more information about this error, try `rustc --explain E0208`. diff --git a/tests/ui/variance/variance-regions-indirect.stderr b/tests/ui/variance/variance-regions-indirect.stderr index 535e97db3fb10..fa2f4d507f3d5 100644 --- a/tests/ui/variance/variance-regions-indirect.stderr +++ b/tests/ui/variance/variance-regions-indirect.stderr @@ -1,28 +1,28 @@ -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> { @@ -30,4 +30,3 @@ LL | struct Derived4<'a, 'b, 'c:'b> { error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0208`. diff --git a/tests/ui/variance/variance-trait-bounds.stderr b/tests/ui/variance/variance-trait-bounds.stderr index 3f6ca62a64069..5a73e541c3a17 100644 --- a/tests/ui/variance/variance-trait-bounds.stderr +++ b/tests/ui/variance/variance-trait-bounds.stderr @@ -1,22 +1,22 @@ -error[E0208]: [+, +] +error: [+, +] --> $DIR/variance-trait-bounds.rs:16:1 | LL | struct TestStruct> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0208]: [*, +] +error: [*, +] --> $DIR/variance-trait-bounds.rs:21:1 | LL | enum TestEnum> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0208]: [*, +] +error: [*, +] --> $DIR/variance-trait-bounds.rs:26:1 | LL | struct TestContraStruct> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0208]: [*, +] +error: [*, +] --> $DIR/variance-trait-bounds.rs:31:1 | LL | struct TestBox+Setter> { @@ -24,4 +24,3 @@ LL | struct TestBox+Setter> { error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0208`. diff --git a/tests/ui/variance/variance-trait-object-bound.stderr b/tests/ui/variance/variance-trait-object-bound.stderr index 9a2c924b96a95..7c46b553f4394 100644 --- a/tests/ui/variance/variance-trait-object-bound.stderr +++ b/tests/ui/variance/variance-trait-object-bound.stderr @@ -1,4 +1,4 @@ -error[E0208]: [-] +error: [-] --> $DIR/variance-trait-object-bound.rs:14:1 | LL | struct TOption<'a> { @@ -6,4 +6,3 @@ LL | struct TOption<'a> { error: aborting due to previous error -For more information about this error, try `rustc --explain E0208`. diff --git a/tests/ui/variance/variance-types-bounds.stderr b/tests/ui/variance/variance-types-bounds.stderr index 523763b8a07b4..bb81644347693 100644 --- a/tests/ui/variance/variance-types-bounds.stderr +++ b/tests/ui/variance/variance-types-bounds.stderr @@ -1,28 +1,28 @@ -error[E0208]: [+, +] +error: [+, +] --> $DIR/variance-types-bounds.rs:7:1 | LL | struct TestImm { | ^^^^^^^^^^^^^^^^^^^^ -error[E0208]: [+, o] +error: [+, o] --> $DIR/variance-types-bounds.rs:13:1 | LL | struct TestMut { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0208]: [+, o] +error: [+, o] --> $DIR/variance-types-bounds.rs:19:1 | LL | struct TestIndirect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0208]: [o, o] +error: [o, o] --> $DIR/variance-types-bounds.rs:24:1 | LL | struct TestIndirect2 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0208]: [o, o] +error: [o, o] --> $DIR/variance-types-bounds.rs:38:1 | LL | struct TestObject { @@ -30,4 +30,3 @@ LL | struct TestObject { error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0208`. diff --git a/tests/ui/variance/variance-types.stderr b/tests/ui/variance/variance-types.stderr index 5a5aaecffc5eb..9f7f1d9b0e332 100644 --- a/tests/ui/variance/variance-types.stderr +++ b/tests/ui/variance/variance-types.stderr @@ -1,34 +1,34 @@ -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 { | ^^^^^^^^^^^^^^^^^^^^^^^ -error[E0208]: [o] +error: [o] --> $DIR/variance-types.rs:20:1 | LL | struct InvariantIndirect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0208]: [+] +error: [+] --> $DIR/variance-types.rs:25:1 | LL | struct Covariant { | ^^^^^^^^^^^^^^^^^^^ -error[E0208]: [-] +error: [-] --> $DIR/variance-types.rs:30:1 | LL | struct Contravariant { | ^^^^^^^^^^^^^^^^^^^^^^^ -error[E0208]: [+, -, o] +error: [+, -, o] --> $DIR/variance-types.rs:35:1 | LL | enum Enum { @@ -36,4 +36,3 @@ LL | enum Enum { error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0208`.