]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0208.md
Auto merge of #105650 - cassaundra:float-literal-suggestion, r=pnkfelix
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0208.md
1 #### This error code is internal to the compiler and will not be emitted with normal Rust code.
2 #### Note: this error code is no longer emitted by the compiler.
3
4 This error code shows the variance of a type's generic parameters.
5
6 Erroneous code example:
7
8 ```compile_fail
9 // NOTE: this feature is perma-unstable and should *only* be used for
10 //       testing purposes.
11 #![feature(rustc_attrs)]
12
13 #[rustc_variance]
14 struct Foo<'a, T> { // error: deliberate error to display type's variance
15     t: &'a mut T,
16 }
17 ```
18
19 which produces the following error:
20
21 ```text
22 error: [-, o]
23  --> <anon>:4:1
24   |
25 4 | struct Foo<'a, T> {
26   | ^^^^^^^^^^^^^^^^^
27 ```
28
29 *Note that while `#[rustc_variance]` still exists and is used within the*
30 *compiler, it no longer is marked as `E0208` and instead has no error code.*
31
32 This error is deliberately triggered with the `#[rustc_variance]` attribute
33 (`#![feature(rustc_attrs)]` must be enabled) and helps to show you the variance
34 of the type's generic parameters. You can read more about variance and
35 subtyping in [this section of the Rustnomicon]. For a more in depth look at
36 variance (including a more complete list of common variances) see
37 [this section of the Reference]. For information on how variance is implemented
38 in the compiler, see [this section of `rustc-dev-guide`].
39
40 This error can be easily fixed by removing the `#[rustc_variance]` attribute,
41 the compiler's suggestion to comment it out can be applied automatically with
42 `rustfix`.
43
44 [this section of the Rustnomicon]: https://doc.rust-lang.org/nomicon/subtyping.html
45 [this section of the Reference]: https://doc.rust-lang.org/reference/subtyping.html#variance
46 [this section of `rustc-dev-guide`]: https://rustc-dev-guide.rust-lang.org/variance.html