diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-01-19 11:19:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-19 11:19:35 +0100 |
| commit | 246daa49ee5968966dec192057a9163b94e90601 (patch) | |
| tree | a027b982018ccbdca2c3dc29496e5cb57a9d9e8e /compiler/rustc_error_codes/src | |
| parent | 1a878df2b8d92c702548cb00bcf47b0af8176a97 (diff) | |
| parent | 708861e5b77d2600da523dc817bc831f7d7d7733 (diff) | |
| download | rust-246daa49ee5968966dec192057a9163b94e90601.tar.gz rust-246daa49ee5968966dec192057a9163b94e90601.zip | |
Rollup merge of #106931 - Ezrashaw:docs-e0208, r=compiler-errors
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 https://github.com/rust-lang/rust/issues/61137.
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0208.md | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0208.md b/compiler/rustc_error_codes/src/error_codes/E0208.md index 7edd93e56a9..1ae01106f20 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] + --> <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 |
