diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_error_codes | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_error_codes')
17 files changed, 152 insertions, 64 deletions
diff --git a/compiler/rustc_error_codes/Cargo.toml b/compiler/rustc_error_codes/Cargo.toml index 7d5f3e467..de668b81b 100644 --- a/compiler/rustc_error_codes/Cargo.toml +++ b/compiler/rustc_error_codes/Cargo.toml @@ -2,3 +2,7 @@ name = "rustc_error_codes" version = "0.0.0" edition = "2021" + +[dependencies] +# tidy-alphabetical-start +# tidy-alphabetical-end diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 89c44c6ec..6680e8875 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -514,6 +514,7 @@ E0791: include_str!("./error_codes/E0791.md"), E0792: include_str!("./error_codes/E0792.md"), E0793: include_str!("./error_codes/E0793.md"), E0794: include_str!("./error_codes/E0794.md"), +E0795: include_str!("./error_codes/E0795.md"), } // Undocumented removed error codes. Note that many removed error codes are kept in the list above diff --git a/compiler/rustc_error_codes/src/error_codes/E0282.md b/compiler/rustc_error_codes/src/error_codes/E0282.md index 49d2205f9..5de43982e 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0282.md +++ b/compiler/rustc_error_codes/src/error_codes/E0282.md @@ -3,7 +3,7 @@ The compiler could not infer a type and asked for a type annotation. Erroneous code example: ```compile_fail,E0282 -let x = "hello".chars().rev().collect(); +let x = Vec::new(); ``` This error indicates that type inference did not result in one unique possible @@ -11,21 +11,24 @@ type, and extra information is required. In most cases this can be provided by adding a type annotation. Sometimes you need to specify a generic type parameter manually. -A common example is the `collect` method on `Iterator`. It has a generic type -parameter with a `FromIterator` bound, which for a `char` iterator is -implemented by `Vec` and `String` among others. Consider the following snippet -that reverses the characters of a string: +In the example above, type `Vec` has a type parameter `T`. When calling +`Vec::new`, barring any other later usage of the variable `x` that allows the +compiler to infer what type `T` is, the compiler needs to be told what it is. -In the first code example, the compiler cannot infer what the type of `x` should -be: `Vec<char>` and `String` are both suitable candidates. To specify which type -to use, you can use a type annotation on `x`: +The type can be specified on the variable: ``` -let x: Vec<char> = "hello".chars().rev().collect(); +let x: Vec<i32> = Vec::new(); ``` -It is not necessary to annotate the full type. Once the ambiguity is resolved, -the compiler can infer the rest: +The type can also be specified in the path of the expression: + +``` +let x = Vec::<i32>::new(); +``` + +In cases with more complex types, it is not necessary to annotate the full +type. Once the ambiguity is resolved, the compiler can infer the rest: ``` let x: Vec<_> = "hello".chars().rev().collect(); diff --git a/compiler/rustc_error_codes/src/error_codes/E0283.md b/compiler/rustc_error_codes/src/error_codes/E0283.md index 79d2c8204..b2f0ede6a 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0283.md +++ b/compiler/rustc_error_codes/src/error_codes/E0283.md @@ -1,8 +1,52 @@ -An implementation cannot be chosen unambiguously because of lack of information. +The compiler could not infer a type and asked for a type annotation. Erroneous code example: ```compile_fail,E0283 +let x = "hello".chars().rev().collect(); +``` + +This error indicates that type inference did not result in one unique possible +type, and extra information is required. In most cases this can be provided +by adding a type annotation. Sometimes you need to specify a generic type +parameter manually. + +A common example is the `collect` method on `Iterator`. It has a generic type +parameter with a `FromIterator` bound, which for a `char` iterator is +implemented by `Vec` and `String` among others. Consider the following snippet +that reverses the characters of a string: + +In the first code example, the compiler cannot infer what the type of `x` should +be: `Vec<char>` and `String` are both suitable candidates. To specify which type +to use, you can use a type annotation on `x`: + +``` +let x: Vec<char> = "hello".chars().rev().collect(); +``` + +It is not necessary to annotate the full type. Once the ambiguity is resolved, +the compiler can infer the rest: + +``` +let x: Vec<_> = "hello".chars().rev().collect(); +``` + +Another way to provide the compiler with enough information, is to specify the +generic type parameter: + +``` +let x = "hello".chars().rev().collect::<Vec<char>>(); +``` + +Again, you need not specify the full type if the compiler can infer it: + +``` +let x = "hello".chars().rev().collect::<Vec<_>>(); +``` + +We can see a self-contained example below: + +```compile_fail,E0283 struct Foo; impl Into<u32> for Foo { diff --git a/compiler/rustc_error_codes/src/error_codes/E0457.md b/compiler/rustc_error_codes/src/error_codes/E0457.md index 2c33d1e6a..e2dbf53a0 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0457.md +++ b/compiler/rustc_error_codes/src/error_codes/E0457.md @@ -1,3 +1,5 @@ +#### Note: this error code is no longer emitted by the compiler` + Plugin `..` only found in rlib format, but must be available in dylib format. Erroneous code example: diff --git a/compiler/rustc_error_codes/src/error_codes/E0463.md b/compiler/rustc_error_codes/src/error_codes/E0463.md index d0cd1b1dc..9bd8d0e83 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0463.md +++ b/compiler/rustc_error_codes/src/error_codes/E0463.md @@ -1,16 +1,13 @@ -A plugin/crate was declared but cannot be found. +A crate was declared but cannot be found. Erroneous code example: ```compile_fail,E0463 -#![feature(plugin)] -#![plugin(cookie_monster)] // error: can't find crate for `cookie_monster` -extern crate cake_is_a_lie; // error: can't find crate for `cake_is_a_lie` +extern crate foo; // error: can't find crate ``` You need to link your code to the relevant crate in order to be able to use it -(through Cargo or the `-L` option of rustc example). Plugins are crates as -well, and you link to them the same way. +(through Cargo or the `-L` option of rustc, for example). ## Common causes diff --git a/compiler/rustc_error_codes/src/error_codes/E0498.md b/compiler/rustc_error_codes/src/error_codes/E0498.md index c9ea4a794..a67a9317d 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0498.md +++ b/compiler/rustc_error_codes/src/error_codes/E0498.md @@ -1,8 +1,10 @@ +#### Note: this error code is no longer emitted by the compiler. + The `plugin` attribute was malformed. Erroneous code example: -```compile_fail,E0498 +```ignore (E0498 is no longer emitted) #![feature(plugin)] #![plugin(foo(args))] // error: invalid argument #![plugin(bar="test")] // error: invalid argument diff --git a/compiler/rustc_error_codes/src/error_codes/E0551.md b/compiler/rustc_error_codes/src/error_codes/E0551.md index 53db559a4..0e078fe71 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0551.md +++ b/compiler/rustc_error_codes/src/error_codes/E0551.md @@ -1,8 +1,10 @@ +#### Note: this error code is no longer emitted by the compiler + An invalid meta-item was used inside an attribute. Erroneous code example: -```compile_fail,E0551 +```compile_fail,E0539 #[deprecated(note)] // error! fn i_am_deprecated() {} ``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0626.md b/compiler/rustc_error_codes/src/error_codes/E0626.md index cc6e03d1c..e2534415d 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0626.md +++ b/compiler/rustc_error_codes/src/error_codes/E0626.md @@ -1,11 +1,11 @@ -This error occurs because a borrow in a generator persists across a +This error occurs because a borrow in a coroutine persists across a yield point. Erroneous code example: ```compile_fail,E0626 -# #![feature(generators, generator_trait, pin)] -# use std::ops::Generator; +# #![feature(coroutines, coroutine_trait, pin)] +# use std::ops::Coroutine; # use std::pin::Pin; let mut b = || { let a = &String::new(); // <-- This borrow... @@ -23,8 +23,8 @@ resolve the previous example by removing the borrow and just storing the integer by value: ``` -# #![feature(generators, generator_trait, pin)] -# use std::ops::Generator; +# #![feature(coroutines, coroutine_trait, pin)] +# use std::ops::Coroutine; # use std::pin::Pin; let mut b = || { let a = 3; @@ -41,8 +41,8 @@ in those cases, something like the `Rc` or `Arc` types may be useful. This error also frequently arises with iteration: ```compile_fail,E0626 -# #![feature(generators, generator_trait, pin)] -# use std::ops::Generator; +# #![feature(coroutines, coroutine_trait, pin)] +# use std::ops::Coroutine; # use std::pin::Pin; let mut b = || { let v = vec![1,2,3]; @@ -57,8 +57,8 @@ Such cases can sometimes be resolved by iterating "by value" (or using `into_iter()`) to avoid borrowing: ``` -# #![feature(generators, generator_trait, pin)] -# use std::ops::Generator; +# #![feature(coroutines, coroutine_trait, pin)] +# use std::ops::Coroutine; # use std::pin::Pin; let mut b = || { let v = vec![1,2,3]; @@ -72,8 +72,8 @@ Pin::new(&mut b).resume(()); If taking ownership is not an option, using indices can work too: ``` -# #![feature(generators, generator_trait, pin)] -# use std::ops::Generator; +# #![feature(coroutines, coroutine_trait, pin)] +# use std::ops::Coroutine; # use std::pin::Pin; let mut b = || { let v = vec![1,2,3]; diff --git a/compiler/rustc_error_codes/src/error_codes/E0627.md b/compiler/rustc_error_codes/src/error_codes/E0627.md index 21358e1e5..5d366f78f 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0627.md +++ b/compiler/rustc_error_codes/src/error_codes/E0627.md @@ -1,28 +1,28 @@ -A yield expression was used outside of the generator literal. +A yield expression was used outside of the coroutine literal. Erroneous code example: ```compile_fail,E0627 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] -fn fake_generator() -> &'static str { +fn fake_coroutine() -> &'static str { yield 1; return "foo" } fn main() { - let mut generator = fake_generator; + let mut coroutine = fake_coroutine; } ``` -The error occurs because keyword `yield` can only be used inside the generator -literal. This can be fixed by constructing the generator correctly. +The error occurs because keyword `yield` can only be used inside the coroutine +literal. This can be fixed by constructing the coroutine correctly. ``` -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] fn main() { - let mut generator = || { + let mut coroutine = || { yield 1; return "foo" }; diff --git a/compiler/rustc_error_codes/src/error_codes/E0628.md b/compiler/rustc_error_codes/src/error_codes/E0628.md index 40040c9a5..ce19bcd56 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0628.md +++ b/compiler/rustc_error_codes/src/error_codes/E0628.md @@ -1,13 +1,13 @@ -More than one parameter was used for a generator. +More than one parameter was used for a coroutine. Erroneous code example: ```compile_fail,E0628 -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] fn main() { - let generator = |a: i32, b: i32| { - // error: too many parameters for a generator + let coroutine = |a: i32, b: i32| { + // error: too many parameters for a coroutine // Allowed only 0 or 1 parameter yield a; }; @@ -15,15 +15,15 @@ fn main() { ``` At present, it is not permitted to pass more than one explicit -parameter for a generator.This can be fixed by using -at most 1 parameter for the generator. For example, we might resolve +parameter for a coroutine.This can be fixed by using +at most 1 parameter for the coroutine. For example, we might resolve the previous example by passing only one parameter. ``` -#![feature(generators, generator_trait)] +#![feature(coroutines, coroutine_trait)] fn main() { - let generator = |a: i32| { + let coroutine = |a: i32| { yield a; }; } diff --git a/compiler/rustc_error_codes/src/error_codes/E0698.md b/compiler/rustc_error_codes/src/error_codes/E0698.md index 9bc652e64..d06497129 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0698.md +++ b/compiler/rustc_error_codes/src/error_codes/E0698.md @@ -1,7 +1,7 @@ #### Note: this error code is no longer emitted by the compiler. -When using generators (or async) all type variables must be bound so a -generator can be constructed. +When using coroutines (or async) all type variables must be bound so a +coroutine can be constructed. Erroneous code example: @@ -15,7 +15,7 @@ async fn foo() { In the above example `T` is unknowable by the compiler. To fix this you must bind `T` to a concrete type such as `String` -so that a generator can then be constructed: +so that a coroutine can then be constructed: ```edition2018 async fn bar<T>() -> () {} diff --git a/compiler/rustc_error_codes/src/error_codes/E0706.md b/compiler/rustc_error_codes/src/error_codes/E0706.md index fabd855a2..a09abb59b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0706.md +++ b/compiler/rustc_error_codes/src/error_codes/E0706.md @@ -1,8 +1,10 @@ +#### Note: this error code is no longer emitted by the compiler. + `async fn`s are not yet supported in traits in Rust. Erroneous code example: -```compile_fail,edition2018 +```ignore,edition2018 trait T { // Neither case is currently supported. async fn foo() {} @@ -13,7 +15,7 @@ trait T { `async fn`s return an `impl Future`, making the following two examples equivalent: -```edition2018,ignore (example-of-desugaring-equivalence) +```ignore,edition2018 (example-of-desugaring-equivalence) async fn foo() -> User { unimplemented!() } diff --git a/compiler/rustc_error_codes/src/error_codes/E0727.md b/compiler/rustc_error_codes/src/error_codes/E0727.md index 386daea0c..fde35885c 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0727.md +++ b/compiler/rustc_error_codes/src/error_codes/E0727.md @@ -3,10 +3,10 @@ A `yield` clause was used in an `async` context. Erroneous code example: ```compile_fail,E0727,edition2018 -#![feature(generators)] +#![feature(coroutines)] fn main() { - let generator = || { + let coroutine = || { async { yield; } @@ -20,10 +20,10 @@ which is not yet supported. To fix this error, you have to move `yield` out of the `async` block: ```edition2018 -#![feature(generators)] +#![feature(coroutines)] fn main() { - let generator = || { + let coroutine = || { yield; }; } diff --git a/compiler/rustc_error_codes/src/error_codes/E0790.md b/compiler/rustc_error_codes/src/error_codes/E0790.md index 2aee9dfbd..b52543c48 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0790.md +++ b/compiler/rustc_error_codes/src/error_codes/E0790.md @@ -4,24 +4,24 @@ method. Erroneous code example: ```compile_fail,E0790 -trait Generator { +trait Coroutine { fn create() -> u32; } struct Impl; -impl Generator for Impl { +impl Coroutine for Impl { fn create() -> u32 { 1 } } struct AnotherImpl; -impl Generator for AnotherImpl { +impl Coroutine for AnotherImpl { fn create() -> u32 { 2 } } -let cont: u32 = Generator::create(); -// error, impossible to choose one of Generator trait implementation +let cont: u32 = Coroutine::create(); +// error, impossible to choose one of Coroutine trait implementation // Should it be Impl or AnotherImpl, maybe something else? ``` @@ -30,18 +30,18 @@ information to the compiler. In this case, the solution is to use a concrete type: ``` -trait Generator { +trait Coroutine { fn create() -> u32; } struct AnotherImpl; -impl Generator for AnotherImpl { +impl Coroutine for AnotherImpl { fn create() -> u32 { 2 } } let gen1 = AnotherImpl::create(); // if there are multiple methods with same name (different traits) -let gen2 = <AnotherImpl as Generator>::create(); +let gen2 = <AnotherImpl as Coroutine>::create(); ``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0795.md b/compiler/rustc_error_codes/src/error_codes/E0795.md new file mode 100644 index 000000000..20f51441c --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0795.md @@ -0,0 +1,28 @@ +Invalid argument for the `offset_of!` macro. + +Erroneous code example: + +```compile_fail,E0795 +#![feature(offset_of, offset_of_enum)] + +let x = std::mem::offset_of!(Option<u8>, Some); +``` + +The `offset_of!` macro gives the offset of a field within a type. It can +navigate through enum variants, but the final component of its second argument +must be a field and not a variant. + +The offset of the contained `u8` in the `Option<u8>` can be found by specifying +the field name `0`: + +``` +#![feature(offset_of, offset_of_enum)] + +let x: usize = std::mem::offset_of!(Option<u8>, Some.0); +``` + +The discriminant of an enumeration may be read with `core::mem::discriminant`, +but this is not always a value physically present within the enum. + +Further information about enum layout may be found at +https://rust-lang.github.io/unsafe-code-guidelines/layout/enums.html. diff --git a/compiler/rustc_error_codes/src/lib.rs b/compiler/rustc_error_codes/src/lib.rs index d6b120e4d..81ad66128 100644 --- a/compiler/rustc_error_codes/src/lib.rs +++ b/compiler/rustc_error_codes/src/lib.rs @@ -1,3 +1,6 @@ +#![cfg_attr(not(bootstrap), allow(internal_features))] +#![cfg_attr(not(bootstrap), feature(rustdoc_internals))] +#![cfg_attr(not(bootstrap), doc(rust_logo))] #![deny(rustdoc::invalid_codeblock_attributes)] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] |