diff options
| author | Christoph Schmidler <c.schmidler@gmail.com> | 2019-12-09 07:46:10 +0100 |
|---|---|---|
| committer | Christoph Schmidler <c.schmidler@gmail.com> | 2019-12-09 07:46:10 +0100 |
| commit | abf053d238e051390d5a1cfb62269a5853e77437 (patch) | |
| tree | d1c98f5b876a0d8f092f7003cab372b5dbe00f16 /src/librustc_error_codes/error_codes | |
| parent | 969926fcfe68787595d384f53d19cf6b8c9df3e3 (diff) | |
| parent | e862c01aadb2d029864f7bb256cf6c85bbb5d7e4 (diff) | |
| download | rust-abf053d238e051390d5a1cfb62269a5853e77437.tar.gz rust-abf053d238e051390d5a1cfb62269a5853e77437.zip | |
Merge branch 'master' of github.com:TheSamsa/rust
Diffstat (limited to 'src/librustc_error_codes/error_codes')
38 files changed, 220 insertions, 162 deletions
diff --git a/src/librustc_error_codes/error_codes/E0015.md b/src/librustc_error_codes/error_codes/E0015.md index 361cb425809..021a0219d13 100644 --- a/src/librustc_error_codes/error_codes/E0015.md +++ b/src/librustc_error_codes/error_codes/E0015.md @@ -1,4 +1,5 @@ -A constant item was initialized with something that is not a constant expression. +A constant item was initialized with something that is not a constant +expression. Erroneous code example: diff --git a/src/librustc_error_codes/error_codes/E0017.md b/src/librustc_error_codes/error_codes/E0017.md deleted file mode 100644 index d5e6857b4d6..00000000000 --- a/src/librustc_error_codes/error_codes/E0017.md +++ /dev/null @@ -1,20 +0,0 @@ -References in statics and constants may only refer to immutable values. - -Erroneous code example: - -```compile_fail,E0017 -static X: i32 = 1; -const C: i32 = 2; - -// these three are not allowed: -const CR: &mut i32 = &mut C; -static STATIC_REF: &'static mut i32 = &mut X; -static CONST_REF: &'static mut i32 = &mut C; -``` - -Statics are shared everywhere, and if they refer to mutable data one might -violate memory safety since holding multiple mutable references to shared data -is not allowed. - -If you really want global mutable state, try using `static mut` or a global -`UnsafeCell`. diff --git a/src/librustc_error_codes/error_codes/E0062.md b/src/librustc_error_codes/error_codes/E0062.md index 0ebeb1bd78e..64fc027b885 100644 --- a/src/librustc_error_codes/error_codes/E0062.md +++ b/src/librustc_error_codes/error_codes/E0062.md @@ -1,6 +1,6 @@ -This error indicates that during an attempt to build a struct or struct-like -enum variant, one of the fields was specified more than once. Erroneous code -example: +A struct's or struct-like enum variant's field was specified more than once. + +Erroneous code example: ```compile_fail,E0062 struct Foo { @@ -15,7 +15,9 @@ fn main() { } ``` -Each field should be specified exactly one time. Example: +This error indicates that during an attempt to build a struct or struct-like +enum variant, one of the fields was specified more than once. Each field should +be specified exactly one time. Example: ``` struct Foo { diff --git a/src/librustc_error_codes/error_codes/E0063.md b/src/librustc_error_codes/error_codes/E0063.md index 0d1f60437ac..0e611deac42 100644 --- a/src/librustc_error_codes/error_codes/E0063.md +++ b/src/librustc_error_codes/error_codes/E0063.md @@ -1,5 +1,6 @@ -This error indicates that during an attempt to build a struct or struct-like -enum variant, one of the fields was not provided. Erroneous code example: +A struct's or struct-like enum variant's field was not provided. + +Erroneous code example: ```compile_fail,E0063 struct Foo { diff --git a/src/librustc_error_codes/error_codes/E0067.md b/src/librustc_error_codes/error_codes/E0067.md index 101b96f7983..11041bb53ee 100644 --- a/src/librustc_error_codes/error_codes/E0067.md +++ b/src/librustc_error_codes/error_codes/E0067.md @@ -1,33 +1,15 @@ -The left-hand side of a compound assignment expression must be a place -expression. A place expression represents a memory location and includes -item paths (ie, namespaced variables), dereferences, indexing expressions, -and field references. +An invalid left-hand side expression was used on an assignment operation. -Let's start with some erroneous code examples: +Erroneous code example: ```compile_fail,E0067 -use std::collections::LinkedList; - -// Bad: assignment to non-place expression -LinkedList::new() += 1; - -// ... - -fn some_func(i: &mut i32) { - i += 12; // Error : '+=' operation cannot be applied on a reference ! -} +12 += 1; // error! ``` -And now some working examples: +You need to have a place expression to be able to assign it something. For +example: ``` -let mut i : i32 = 0; - -i += 12; // Good ! - -// ... - -fn some_func(i: &mut i32) { - *i += 12; // Good ! -} +let mut x: i8 = 12; +x += 1; // ok! ``` diff --git a/src/librustc_error_codes/error_codes/E0069.md b/src/librustc_error_codes/error_codes/E0069.md index ad3b1803b54..7367a5c0922 100644 --- a/src/librustc_error_codes/error_codes/E0069.md +++ b/src/librustc_error_codes/error_codes/E0069.md @@ -1,5 +1,7 @@ The compiler found a function whose body contains a `return;` statement but -whose return type is not `()`. An example of this is: +whose return type is not `()`. + +Erroneous code example: ```compile_fail,E0069 // error diff --git a/src/librustc_error_codes/error_codes/E0070.md b/src/librustc_error_codes/error_codes/E0070.md index 1a56080a097..97522af3da8 100644 --- a/src/librustc_error_codes/error_codes/E0070.md +++ b/src/librustc_error_codes/error_codes/E0070.md @@ -1,41 +1,43 @@ -The left-hand side of an assignment operator must be a place expression. A -place expression represents a memory location and can be a variable (with -optional namespacing), a dereference, an indexing expression or a field -reference. +An assignment operator was used on a non-place expression. -More details can be found in the [Expressions] section of the Reference. - -[Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries - -Now, we can go further. Here are some erroneous code examples: +Erroneous code examples: ```compile_fail,E0070 struct SomeStruct { x: i32, - y: i32 + y: i32, } -const SOME_CONST : i32 = 12; +const SOME_CONST: i32 = 12; fn some_other_func() {} fn some_function() { - SOME_CONST = 14; // error : a constant value cannot be changed! - 1 = 3; // error : 1 isn't a valid place! - some_other_func() = 4; // error : we cannot assign value to a function! - SomeStruct.x = 12; // error : SomeStruct a structure name but it is used - // like a variable! + SOME_CONST = 14; // error: a constant value cannot be changed! + 1 = 3; // error: 1 isn't a valid place! + some_other_func() = 4; // error: we cannot assign value to a function! + SomeStruct::x = 12; // error: SomeStruct a structure name but it is used + // like a variable! } ``` +The left-hand side of an assignment operator must be a place expression. A +place expression represents a memory location and can be a variable (with +optional namespacing), a dereference, an indexing expression or a field +reference. + +More details can be found in the [Expressions] section of the Reference. + +[Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries + And now let's give working examples: ``` struct SomeStruct { x: i32, - y: i32 + y: i32, } -let mut s = SomeStruct {x: 0, y: 0}; +let mut s = SomeStruct { x: 0, y: 0 }; s.x = 3; // that's good ! diff --git a/src/librustc_error_codes/error_codes/E0071.md b/src/librustc_error_codes/error_codes/E0071.md index 768dd0c7a48..bc2c03a0220 100644 --- a/src/librustc_error_codes/error_codes/E0071.md +++ b/src/librustc_error_codes/error_codes/E0071.md @@ -1,5 +1,5 @@ -You tried to use structure-literal syntax to create an item that is -not a structure or enum variant. +A structure-literal syntax was used to create an item that is not a structure +or enum variant. Example of erroneous code: @@ -9,8 +9,8 @@ let t = U32 { value: 4 }; // error: expected struct, variant or union type, // found builtin type `u32` ``` -To fix this, ensure that the name was correctly spelled, and that -the correct form of initializer was used. +To fix this, ensure that the name was correctly spelled, and that the correct +form of initializer was used. For example, the code above can be fixed to: diff --git a/src/librustc_error_codes/error_codes/E0072.md b/src/librustc_error_codes/error_codes/E0072.md index e461d45f30c..8f7749abab1 100644 --- a/src/librustc_error_codes/error_codes/E0072.md +++ b/src/librustc_error_codes/error_codes/E0072.md @@ -1,20 +1,23 @@ -When defining a recursive struct or enum, any use of the type being defined -from inside the definition must occur behind a pointer (like `Box` or `&`). -This is because structs and enums must have a well-defined size, and without -the pointer, the size of the type would need to be unbounded. +A recursive type has infinite size because it doesn't have an indirection. -Consider the following erroneous definition of a type for a list of bytes: +Erroneous code example: ```compile_fail,E0072 -// error, invalid recursive struct type struct ListNode { head: u8, - tail: Option<ListNode>, + tail: Option<ListNode>, // error: no indirection here so impossible to + // compute the type's size } ``` -This type cannot have a well-defined size, because it needs to be arbitrarily -large (since we would be able to nest `ListNode`s to any depth). Specifically, +When defining a recursive struct or enum, any use of the type being defined +from inside the definition must occur behind a pointer (like `Box`, `&` or +`Rc`). This is because structs and enums must have a well-defined size, and +without the pointer, the size of the type would need to be unbounded. + +In the example, the type cannot have a well-defined size, because it needs to be +arbitrarily large (since we would be able to nest `ListNode`s to any depth). +Specifically, ```plain size of `ListNode` = 1 byte for `head` diff --git a/src/librustc_error_codes/error_codes/E0075.md b/src/librustc_error_codes/error_codes/E0075.md index f15af8150ba..969c1ee7131 100644 --- a/src/librustc_error_codes/error_codes/E0075.md +++ b/src/librustc_error_codes/error_codes/E0075.md @@ -1,21 +1,23 @@ -The `#[simd]` attribute can only be applied to non empty tuple structs, because -it doesn't make sense to try to use SIMD operations when there are no values to -operate on. +A `#[simd]` attribute was applied to an empty tuple struct. -This will cause an error: +Erroneous code example: ```compile_fail,E0075 #![feature(repr_simd)] #[repr(simd)] -struct Bad; +struct Bad; // error! ``` -This will not: +The `#[simd]` attribute can only be applied to non empty tuple structs, because +it doesn't make sense to try to use SIMD operations when there are no values to +operate on. + +Fixed example: ``` #![feature(repr_simd)] #[repr(simd)] -struct Good(u32); +struct Good(u32); // ok! ``` diff --git a/src/librustc_error_codes/error_codes/E0076.md b/src/librustc_error_codes/error_codes/E0076.md index 466e0a96e6b..f293a2a5772 100644 --- a/src/librustc_error_codes/error_codes/E0076.md +++ b/src/librustc_error_codes/error_codes/E0076.md @@ -1,21 +1,24 @@ -When using the `#[simd]` attribute to automatically use SIMD operations in tuple -struct, the types in the struct must all be of the same type, or the compiler -will trigger this error. +All types in a tuple struct aren't the same when using the `#[simd]` +attribute. -This will cause an error: +Erroneous code example: ```compile_fail,E0076 #![feature(repr_simd)] #[repr(simd)] -struct Bad(u16, u32, u32); +struct Bad(u16, u32, u32); // error! ``` -This will not: +When using the `#[simd]` attribute to automatically use SIMD operations in tuple +struct, the types in the struct must all be of the same type, or the compiler +will trigger this error. + +Fixed example: ``` #![feature(repr_simd)] #[repr(simd)] -struct Good(u32, u32, u32); +struct Good(u32, u32, u32); // ok! ``` diff --git a/src/librustc_error_codes/error_codes/E0077.md b/src/librustc_error_codes/error_codes/E0077.md index 6ae35a6aa17..b14513c6ccf 100644 --- a/src/librustc_error_codes/error_codes/E0077.md +++ b/src/librustc_error_codes/error_codes/E0077.md @@ -1,20 +1,23 @@ -When using the `#[simd]` attribute on a tuple struct, the elements in the tuple -must be machine types so SIMD operations can be applied to them. +A tuple struct's element isn't a machine type when using the `#[simd]` +attribute. -This will cause an error: +Erroneous code example: ```compile_fail,E0077 #![feature(repr_simd)] #[repr(simd)] -struct Bad(String); +struct Bad(String); // error! ``` -This will not: +When using the `#[simd]` attribute on a tuple struct, the elements in the tuple +must be machine types so SIMD operations can be applied to them. + +Fixed example: ``` #![feature(repr_simd)] #[repr(simd)] -struct Good(u32, u32, u32); +struct Good(u32, u32, u32); // ok! ``` diff --git a/src/librustc_error_codes/error_codes/E0080.md b/src/librustc_error_codes/error_codes/E0080.md index 262bf00d385..273238a943b 100644 --- a/src/librustc_error_codes/error_codes/E0080.md +++ b/src/librustc_error_codes/error_codes/E0080.md @@ -1,14 +1,18 @@ -This error indicates that the compiler was unable to sensibly evaluate a -constant expression that had to be evaluated. Attempting to divide by 0 -or causing integer overflow are two ways to induce this error. For example: +A constant value failed to get evaluated. + +Erroneous code example: ```compile_fail,E0080 enum Enum { X = (1 << 500), - Y = (1 / 0) + Y = (1 / 0), } ``` +This error indicates that the compiler was unable to sensibly evaluate a +constant expression that had to be evaluated. Attempting to divide by 0 +or causing an integer overflow are two ways to induce this error. + Ensure that the expressions given can be evaluated as the desired integer type. See the FFI section of the Reference for more information about using a custom integer type: diff --git a/src/librustc_error_codes/error_codes/E0081.md b/src/librustc_error_codes/error_codes/E0081.md index ec88ca9765e..fd5eca68e21 100644 --- a/src/librustc_error_codes/error_codes/E0081.md +++ b/src/librustc_error_codes/error_codes/E0081.md @@ -1,21 +1,23 @@ -Enum discriminants are used to differentiate enum variants stored in memory. -This error indicates that the same value was used for two or more variants, -making them impossible to tell apart. +A discrimant value is present more than once. + +Erroneous code example: ```compile_fail,E0081 -// Bad. enum Enum { P = 3, - X = 3, + X = 3, // error! Y = 5, } ``` +Enum discriminants are used to differentiate enum variants stored in memory. +This error indicates that the same value was used for two or more variants, +making it impossible to distinguish them. + ``` -// Good. enum Enum { P, - X = 3, + X = 3, // ok! Y = 5, } ``` @@ -27,7 +29,7 @@ variants. ```compile_fail,E0081 enum Bad { X, - Y = 0 + Y = 0, // error! } ``` diff --git a/src/librustc_error_codes/error_codes/E0091.md b/src/librustc_error_codes/error_codes/E0091.md index 2a092402429..03cb3280371 100644 --- a/src/librustc_error_codes/error_codes/E0091.md +++ b/src/librustc_error_codes/error_codes/E0091.md @@ -1,5 +1,6 @@ -You gave an unnecessary type or const parameter in a type alias. Erroneous -code example: +An unnecessary type or const parameter was given in a type alias. + +Erroneous code example: ```compile_fail,E0091 type Foo<T> = u32; // error: type parameter `T` is unused diff --git a/src/librustc_error_codes/error_codes/E0092.md b/src/librustc_error_codes/error_codes/E0092.md index 2750a7d45b4..e289534bf7a 100644 --- a/src/librustc_error_codes/error_codes/E0092.md +++ b/src/librustc_error_codes/error_codes/E0092.md @@ -1,4 +1,5 @@ -You tried to declare an undefined atomic operation function. +An undefined atomic operation function was declared. + Erroneous code example: ```compile_fail,E0092 @@ -11,8 +12,8 @@ extern "rust-intrinsic" { ``` Please check you didn't make a mistake in the function's name. All intrinsic -functions are defined in librustc_codegen_llvm/intrinsic.rs and in -libcore/intrinsics.rs in the Rust source code. Example: +functions are defined in `librustc_codegen_llvm/intrinsic.rs` and in +`libcore/intrinsics.rs` in the Rust source code. Example: ``` #![feature(intrinsics)] diff --git a/src/librustc_error_codes/error_codes/E0093.md b/src/librustc_error_codes/error_codes/E0093.md index 9633f794d8b..8e7de1a9d37 100644 --- a/src/librustc_error_codes/error_codes/E0093.md +++ b/src/librustc_error_codes/error_codes/E0093.md @@ -1,4 +1,6 @@ -You declared an unknown intrinsic function. Erroneous code example: +An unknown intrinsic function was declared. + +Erroneous code example: ```compile_fail,E0093 #![feature(intrinsics)] @@ -15,8 +17,8 @@ fn main() { ``` Please check you didn't make a mistake in the function's name. All intrinsic -functions are defined in librustc_codegen_llvm/intrinsic.rs and in -libcore/intrinsics.rs in the Rust source code. Example: +functions are defined in `librustc_codegen_llvm/intrinsic.rs` and in +`libcore/intrinsics.rs` in the Rust source code. Example: ``` #![feature(intrinsics)] diff --git a/src/librustc_error_codes/error_codes/E0094.md b/src/librustc_error_codes/error_codes/E0094.md index 4d27f616d2d..42baa65bf9f 100644 --- a/src/librustc_error_codes/error_codes/E0094.md +++ b/src/librustc_error_codes/error_codes/E0094.md @@ -1,4 +1,5 @@ -You gave an invalid number of type parameters to an intrinsic function. +An invalid number of type parameters was given to an intrinsic function. + Erroneous code example: ```compile_fail,E0094 diff --git a/src/librustc_error_codes/error_codes/E0106.md b/src/librustc_error_codes/error_codes/E0106.md index 8a49c1f79e4..60ca1ddc283 100644 --- a/src/librustc_error_codes/error_codes/E0106.md +++ b/src/librustc_error_codes/error_codes/E0106.md @@ -2,7 +2,7 @@ This error indicates that a lifetime is missing from a type. If it is an error inside a function signature, the problem may be with failing to adhere to the lifetime elision rules (see below). -Here are some simple examples of where you'll run into this error: +Erroneous code examples: ```compile_fail,E0106 struct Foo1 { x: &bool } @@ -27,7 +27,7 @@ function signatures which allows you to leave out lifetimes in certain cases. For more background on lifetime elision see [the book][book-le]. The lifetime elision rules require that any function signature with an elided -output lifetime must either have +output lifetime must either have: - exactly one input lifetime - or, multiple input lifetimes, but the function must also be a method with a diff --git a/src/librustc_error_codes/error_codes/E0107.md b/src/librustc_error_codes/error_codes/E0107.md index 3a8acba061c..4d22b17fe10 100644 --- a/src/librustc_error_codes/error_codes/E0107.md +++ b/src/librustc_error_codes/error_codes/E0107.md @@ -1,4 +1,6 @@ -This error means that an incorrect number of generic arguments were provided: +An incorrect number of generic arguments were provided. + +Erroneous code example: ```compile_fail,E0107 struct Foo<T> { x: T } @@ -9,6 +11,7 @@ struct Baz<S, T> { x: Foo<S, T> } // error: wrong number of type arguments: // expected 1, found 2 fn foo<T, U>(x: T, y: U) {} +fn f() {} fn main() { let x: bool = true; @@ -16,13 +19,26 @@ fn main() { // expected 2, found 1 foo::<bool, i32, i32>(x, 2, 4); // error: wrong number of type arguments: // expected 2, found 3 + f::<'static>(); // error: wrong number of lifetime arguments + // expected 0, found 1 } +``` +When using/declaring an item with generic arguments, you must provide the exact +same number: + +``` +struct Foo<T> { x: T } + +struct Bar<T> { x: Foo<T> } // ok! +struct Baz<S, T> { x: Foo<S>, y: Foo<T> } // ok! + +fn foo<T, U>(x: T, y: U) {} fn f() {} fn main() { - f::<'static>(); // error: wrong number of lifetime arguments: - // expected 0, found 1 + let x: bool = true; + foo::<bool, u32>(x, 12); // ok! + f(); // ok! } ``` - diff --git a/src/librustc_error_codes/error_codes/E0109.md b/src/librustc_error_codes/error_codes/E0109.md index 5bc229ade52..2eab9725a6f 100644 --- a/src/librustc_error_codes/error_codes/E0109.md +++ b/src/librustc_error_codes/error_codes/E0109.md @@ -1,4 +1,5 @@ You tried to provide a generic argument to a type which doesn't need it. + Erroneous code example: ```compile_fail,E0109 diff --git a/src/librustc_error_codes/error_codes/E0116.md b/src/librustc_error_codes/error_codes/E0116.md index 27759a42343..ca849c2a128 100644 --- a/src/librustc_error_codes/error_codes/E0116.md +++ b/src/librustc_error_codes/error_codes/E0116.md @@ -1,11 +1,15 @@ -You can only define an inherent implementation for a type in the same crate -where the type was defined. For example, an `impl` block as below is not allowed -since `Vec` is defined in the standard library: +An inherent implementation was defined for a type outside the current crate. + +Erroneous code example: ```compile_fail,E0116 impl Vec<u8> { } // error ``` +You can only define an inherent implementation for a type in the same crate +where the type was defined. For example, an `impl` block as above is not allowed +since `Vec` is defined in the standard library. + To fix this problem, you can do either of these things: - define a trait that has the desired associated functions/types/constants and diff --git a/src/librustc_error_codes/error_codes/E0117.md b/src/librustc_error_codes/error_codes/E0117.md index bd362305662..7fa211d4a27 100644 --- a/src/librustc_error_codes/error_codes/E0117.md +++ b/src/librustc_error_codes/error_codes/E0117.md @@ -1,3 +1,11 @@ +The `Drop` trait was implemented on a non-struct type. + +Erroneous code example: + +```compile_fail,E0117 +impl Drop for u32 {} +``` + This error indicates a violation of one of Rust's orphan rules for trait implementations. The rule prohibits any implementation of a foreign trait (a trait defined in another crate) where @@ -6,12 +14,6 @@ trait defined in another crate) where - all of the parameters being passed to the trait (if there are any) are also foreign. -Here's one example of this error: - -```compile_fail,E0117 -impl Drop for u32 {} -``` - To avoid this kind of error, ensure that at least one local type is referenced by the `impl`: diff --git a/src/librustc_error_codes/error_codes/E0118.md b/src/librustc_error_codes/error_codes/E0118.md index baf35ffbb0b..5cb5f506e0a 100644 --- a/src/librustc_error_codes/error_codes/E0118.md +++ b/src/librustc_error_codes/error_codes/E0118.md @@ -1,5 +1,7 @@ -You're trying to write an inherent implementation for something which isn't a -struct nor an enum. Erroneous code example: +An inherent implementation was defined for something which isn't a struct nor +an enum. + +Erroneous code example: ```compile_fail,E0118 impl (u8, u8) { // error: no base type found for inherent implementation diff --git a/src/librustc_error_codes/error_codes/E0119.md b/src/librustc_error_codes/error_codes/E0119.md index 0af3bd4a0de..e596349e5e2 100644 --- a/src/librustc_error_codes/error_codes/E0119.md +++ b/src/librustc_error_codes/error_codes/E0119.md @@ -1,5 +1,6 @@ There are conflicting trait implementations for the same type. -Example of erroneous code: + +Erroneous code example: ```compile_fail,E0119 trait MyTrait { diff --git a/src/librustc_error_codes/error_codes/E0203.md b/src/librustc_error_codes/error_codes/E0203.md new file mode 100644 index 00000000000..1edb519275f --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0203.md @@ -0,0 +1,18 @@ +Having multiple relaxed default bounds is unsupported. + +Erroneous code example: + +```compile_fail,E0203 +struct Bad<T: ?Sized + ?Send>{ + inner: T +} +``` + +Here the type `T` cannot have a relaxed bound for multiple default traits +(`Sized` and `Send`). This can be fixed by only using one relaxed bound. + +``` +struct Good<T: ?Sized>{ + inner: T +} +``` diff --git a/src/librustc_error_codes/error_codes/E0307.md b/src/librustc_error_codes/error_codes/E0307.md index c382f406e4b..1779e5dbb30 100644 --- a/src/librustc_error_codes/error_codes/E0307.md +++ b/src/librustc_error_codes/error_codes/E0307.md @@ -1,5 +1,5 @@ This error indicates that the `self` parameter in a method has an invalid -"reciever type". +"receiver type". Methods take a special first parameter, of which there are three variants: `self`, `&self`, and `&mut self`. These are syntactic sugar for diff --git a/src/librustc_error_codes/error_codes/E0369.md b/src/librustc_error_codes/error_codes/E0369.md index 08db342428c..397979e5641 100644 --- a/src/librustc_error_codes/error_codes/E0369.md +++ b/src/librustc_error_codes/error_codes/E0369.md @@ -26,4 +26,3 @@ left and may require reallocation. This requires ownership of the string on the left. If something should be added to a string literal, move the literal to the heap by allocating it with `to_owned()` like in `"Your text".to_owned()`. - diff --git a/src/librustc_error_codes/error_codes/E0404.md b/src/librustc_error_codes/error_codes/E0404.md index 861a50bfd8c..201107c05a0 100644 --- a/src/librustc_error_codes/error_codes/E0404.md +++ b/src/librustc_error_codes/error_codes/E0404.md @@ -41,4 +41,3 @@ trait Foo { fn bar<T: Foo>(t: T) {} // ok! ``` - diff --git a/src/librustc_error_codes/error_codes/E0458.md b/src/librustc_error_codes/error_codes/E0458.md index e6baeb8f692..385079d403d 100644 --- a/src/librustc_error_codes/error_codes/E0458.md +++ b/src/librustc_error_codes/error_codes/E0458.md @@ -10,4 +10,3 @@ Please specify a valid "kind" value, from one of the following: * static * dylib * framework - diff --git a/src/librustc_error_codes/error_codes/E0631.md b/src/librustc_error_codes/error_codes/E0631.md new file mode 100644 index 00000000000..6188d5f61a7 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0631.md @@ -0,0 +1,27 @@ +This error indicates a type mismatch in closure arguments. + +Erroneous code example: + +```compile_fail,E0631 +fn foo<F: Fn(i32)>(f: F) { +} + +fn main() { + foo(|x: &str| {}); +} +``` + +The error occurs because `foo` accepts a closure that takes an `i32` argument, +but in `main`, it is passed a closure with a `&str` argument. + +This can be resolved by changing the type annotation or removing it entirely +if it can be inferred. + +``` +fn foo<F: Fn(i32)>(f: F) { +} + +fn main() { + foo(|x: i32| {}); +} +``` diff --git a/src/librustc_error_codes/error_codes/E0633.md b/src/librustc_error_codes/error_codes/E0633.md index a68da1188b5..65cdf90036a 100644 --- a/src/librustc_error_codes/error_codes/E0633.md +++ b/src/librustc_error_codes/error_codes/E0633.md @@ -21,4 +21,3 @@ The `#[unwind]` attribute should be used as follows: NB. The default behavior here is "allowed", but this is unspecified and likely to change in the future. - diff --git a/src/librustc_error_codes/error_codes/E0635.md b/src/librustc_error_codes/error_codes/E0635.md index 2382ce0d3ff..a39d2be4f8f 100644 --- a/src/librustc_error_codes/error_codes/E0635.md +++ b/src/librustc_error_codes/error_codes/E0635.md @@ -5,4 +5,3 @@ Erroneous code example: ```compile_fail,E0635 #![feature(nonexistent_rust_feature)] // error: unknown feature ``` - diff --git a/src/librustc_error_codes/error_codes/E0636.md b/src/librustc_error_codes/error_codes/E0636.md index dabf9b64123..57cf72db556 100644 --- a/src/librustc_error_codes/error_codes/E0636.md +++ b/src/librustc_error_codes/error_codes/E0636.md @@ -7,4 +7,3 @@ Erroneous code example: #![feature(rust1)] #![feature(rust1)] // error: the feature `rust1` has already been declared ``` - diff --git a/src/librustc_error_codes/error_codes/E0641.md b/src/librustc_error_codes/error_codes/E0641.md index e39bebce1fe..e2110042c7e 100644 --- a/src/librustc_error_codes/error_codes/E0641.md +++ b/src/librustc_error_codes/error_codes/E0641.md @@ -16,4 +16,4 @@ let a = &(String::from("Hello world!")) as *const _; // Ok let b = 0 as *const i32; // Ok let c: *const i32 = 0 as *const _; // Ok -``` \ No newline at end of file +``` diff --git a/src/librustc_error_codes/error_codes/E0644.md b/src/librustc_error_codes/error_codes/E0644.md index 61acb084a45..7a653bd2264 100644 --- a/src/librustc_error_codes/error_codes/E0644.md +++ b/src/librustc_error_codes/error_codes/E0644.md @@ -27,4 +27,3 @@ closure call itself by capturing a `&Fn()` object or `fn()` pointer that refers to itself. That is permitting, since the closure would be invoking itself via a virtual call, and hence does not directly reference its own *type*. - diff --git a/src/librustc_error_codes/error_codes/E0706.md b/src/librustc_error_codes/error_codes/E0706.md index bee9219af7c..d379b8a2384 100644 --- a/src/librustc_error_codes/error_codes/E0706.md +++ b/src/librustc_error_codes/error_codes/E0706.md @@ -1,4 +1,4 @@ - `async fn`s are not yet supported in traits in Rust. +`async fn`s are not yet supported in traits in Rust. Erroneous code example: @@ -10,7 +10,8 @@ trait T { } ``` -`async fn`s return an `impl Future`, making the following two examples equivalent: +`async fn`s return an `impl Future`, making the following two examples +equivalent: ```edition2018,ignore (example-of-desugaring-equivalence) async fn foo() -> User { @@ -23,8 +24,8 @@ fn foo(&self) -> impl Future<Output = User> + '_ { ``` But when it comes to supporting this in traits, there are [a few implementation -issues][async-is-hard]. One of them is returning `impl Trait` in traits is not supported, -as it would require [Generic Associated Types] to be supported: +issues][async-is-hard]. One of them is returning `impl Trait` in traits is not +supported, as it would require [Generic Associated Types] to be supported: ```edition2018,ignore (example-of-desugaring-equivalence) impl MyDatabase { @@ -40,13 +41,14 @@ impl MyDatabase { } ``` -Until these issues are resolved, you can use the [`async-trait` crate], allowing you to use -`async fn` in traits by desugaring to "boxed futures" +Until these issues are resolved, you can use the [`async-trait` crate], allowing +you to use `async fn` in traits by desugaring to "boxed futures" (`Pin<Box<dyn Future + Send + 'async>>`). -Note that using these trait methods will result in a heap allocation per-function-call. This is not -a significant cost for the vast majority of applications, but should be considered when deciding -whether to use this functionality in the public API of a low-level function that is expected to be +Note that using these trait methods will result in a heap allocation +per-function-call. This is not a significant cost for the vast majority of +applications, but should be considered when deciding whether to use this +functionality in the public API of a low-level function that is expected to be called millions of times a second. You might be interested in visiting the [async book] for further information. diff --git a/src/librustc_error_codes/error_codes/E0745.md b/src/librustc_error_codes/error_codes/E0745.md index 7c478a1e0c8..39bebdcd375 100644 --- a/src/librustc_error_codes/error_codes/E0745.md +++ b/src/librustc_error_codes/error_codes/E0745.md @@ -11,7 +11,7 @@ fn temp_address() { To avoid the error, first bind the temporary to a named local variable. -```ignore +```ignore (not yet implemented) # #![feature(raw_ref_op)] fn temp_address() { let val = 2; |
