mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 19:53:46 +00:00
Auto merge of #43519 - zackmdavis:long_diagnostics_ever_after, r=GuillaumeGomez
a couple more error explanations for posterity E0436, E0595, and moving E0569 to where it belongs in the file rather than being bizarrely out of numerical order r? @GuillaumeGomez
This commit is contained in:
commit
2789db2720
@ -1132,6 +1132,24 @@ fn main() {
|
||||
```
|
||||
"##,
|
||||
|
||||
E0595: r##"
|
||||
Closures cannot mutate immutable captured variables.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0595
|
||||
let x = 3; // error: closure cannot assign to immutable local variable `x`
|
||||
let mut c = || { x += 1 };
|
||||
```
|
||||
|
||||
Make the variable binding mutable:
|
||||
|
||||
```
|
||||
let mut x = 3; // ok!
|
||||
let mut c = || { x += 1 };
|
||||
```
|
||||
"##,
|
||||
|
||||
E0596: r##"
|
||||
This error occurs because you tried to mutably borrow a non-mutable variable.
|
||||
|
||||
@ -1189,6 +1207,5 @@ register_diagnostics! {
|
||||
// E0385, // {} in an aliasable location
|
||||
E0524, // two closures require unique access to `..` at the same time
|
||||
E0594, // cannot assign to {}
|
||||
E0595, // closure cannot assign to {}
|
||||
E0598, // lifetime of {} is too short to guarantee its contents can be...
|
||||
}
|
||||
|
@ -2631,26 +2631,6 @@ struct Bar<S, T> { x: Foo<S, T> }
|
||||
```
|
||||
"##,
|
||||
|
||||
E0569: r##"
|
||||
If an impl has a generic parameter with the `#[may_dangle]` attribute, then
|
||||
that impl must be declared as an `unsafe impl. For example:
|
||||
|
||||
```compile_fail,E0569
|
||||
#![feature(generic_param_attrs)]
|
||||
#![feature(dropck_eyepatch)]
|
||||
|
||||
struct Foo<X>(X);
|
||||
impl<#[may_dangle] X> Drop for Foo<X> {
|
||||
fn drop(&mut self) { }
|
||||
}
|
||||
```
|
||||
|
||||
In this example, we are asserting that the destructor for `Foo` will not
|
||||
access any data of type `X`, and require this assertion to be true for
|
||||
overall safety in our program. The compiler does not currently attempt to
|
||||
verify this assertion; therefore we must tag this `impl` as unsafe.
|
||||
"##,
|
||||
|
||||
E0318: r##"
|
||||
Default impls for a trait must be located in the same crate where the trait was
|
||||
defined. For more information see the [opt-in builtin traits RFC][RFC 19].
|
||||
@ -3457,6 +3437,56 @@ impl Foo for i32 {
|
||||
```
|
||||
"##,
|
||||
|
||||
E0436: r##"
|
||||
The functional record update syntax is only allowed for structs. (Struct-like
|
||||
enum variants don't qualify, for example.)
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0436
|
||||
enum PublicationFrequency {
|
||||
Weekly,
|
||||
SemiMonthly { days: (u8, u8), annual_special: bool },
|
||||
}
|
||||
|
||||
fn one_up_competitor(competitor_frequency: PublicationFrequency)
|
||||
-> PublicationFrequency {
|
||||
match competitor_frequency {
|
||||
PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
|
||||
days: (1, 15), annual_special: false
|
||||
},
|
||||
c @ PublicationFrequency::SemiMonthly{ .. } =>
|
||||
PublicationFrequency::SemiMonthly {
|
||||
annual_special: true, ..c // error: functional record update
|
||||
// syntax requires a struct
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Rewrite the expression without functional record update syntax:
|
||||
|
||||
```
|
||||
enum PublicationFrequency {
|
||||
Weekly,
|
||||
SemiMonthly { days: (u8, u8), annual_special: bool },
|
||||
}
|
||||
|
||||
fn one_up_competitor(competitor_frequency: PublicationFrequency)
|
||||
-> PublicationFrequency {
|
||||
match competitor_frequency {
|
||||
PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
|
||||
days: (1, 15), annual_special: false
|
||||
},
|
||||
PublicationFrequency::SemiMonthly{ days, .. } =>
|
||||
PublicationFrequency::SemiMonthly {
|
||||
days, annual_special: true // ok!
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0439: r##"
|
||||
The length of the platform-intrinsic function `simd_shuffle`
|
||||
wasn't specified. Erroneous code example:
|
||||
@ -3926,6 +3956,28 @@ See [RFC 1522] for more details.
|
||||
[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
|
||||
"##,
|
||||
|
||||
E0569: r##"
|
||||
If an impl has a generic parameter with the `#[may_dangle]` attribute, then
|
||||
that impl must be declared as an `unsafe impl.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0569
|
||||
#![feature(generic_param_attrs)]
|
||||
#![feature(dropck_eyepatch)]
|
||||
|
||||
struct Foo<X>(X);
|
||||
impl<#[may_dangle] X> Drop for Foo<X> {
|
||||
fn drop(&mut self) { }
|
||||
}
|
||||
```
|
||||
|
||||
In this example, we are asserting that the destructor for `Foo` will not
|
||||
access any data of type `X`, and require this assertion to be true for
|
||||
overall safety in our program. The compiler does not currently attempt to
|
||||
verify this assertion; therefore we must tag this `impl` as unsafe.
|
||||
"##,
|
||||
|
||||
E0570: r##"
|
||||
The requested ABI is unsupported by the current target.
|
||||
|
||||
@ -4655,7 +4707,6 @@ register_diagnostics! {
|
||||
// E0372, // coherence not object safe
|
||||
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
|
||||
// between structures with the same definition
|
||||
E0436, // functional record update requires a struct
|
||||
E0521, // redundant default implementations of trait
|
||||
E0533, // `{}` does not name a unit variant, unit struct or a constant
|
||||
E0563, // cannot determine a type for this `impl Trait`: {}
|
||||
|
Loading…
Reference in New Issue
Block a user