Skip to content

Commit 2789db2

Browse files
committed
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
2 parents 15266f9 + 7dab981 commit 2789db2

File tree

2 files changed

+90
-22
lines changed

2 files changed

+90
-22
lines changed

Diff for: src/librustc_borrowck/diagnostics.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,24 @@ fn main() {
11321132
```
11331133
"##,
11341134

1135+
E0595: r##"
1136+
Closures cannot mutate immutable captured variables.
1137+
1138+
Erroneous code example:
1139+
1140+
```compile_fail,E0595
1141+
let x = 3; // error: closure cannot assign to immutable local variable `x`
1142+
let mut c = || { x += 1 };
1143+
```
1144+
1145+
Make the variable binding mutable:
1146+
1147+
```
1148+
let mut x = 3; // ok!
1149+
let mut c = || { x += 1 };
1150+
```
1151+
"##,
1152+
11351153
E0596: r##"
11361154
This error occurs because you tried to mutably borrow a non-mutable variable.
11371155
@@ -1189,6 +1207,5 @@ register_diagnostics! {
11891207
// E0385, // {} in an aliasable location
11901208
E0524, // two closures require unique access to `..` at the same time
11911209
E0594, // cannot assign to {}
1192-
E0595, // closure cannot assign to {}
11931210
E0598, // lifetime of {} is too short to guarantee its contents can be...
11941211
}

Diff for: src/librustc_typeck/diagnostics.rs

+72-21
Original file line numberDiff line numberDiff line change
@@ -2631,26 +2631,6 @@ struct Bar<S, T> { x: Foo<S, T> }
26312631
```
26322632
"##,
26332633

2634-
E0569: r##"
2635-
If an impl has a generic parameter with the `#[may_dangle]` attribute, then
2636-
that impl must be declared as an `unsafe impl. For example:
2637-
2638-
```compile_fail,E0569
2639-
#![feature(generic_param_attrs)]
2640-
#![feature(dropck_eyepatch)]
2641-
2642-
struct Foo<X>(X);
2643-
impl<#[may_dangle] X> Drop for Foo<X> {
2644-
fn drop(&mut self) { }
2645-
}
2646-
```
2647-
2648-
In this example, we are asserting that the destructor for `Foo` will not
2649-
access any data of type `X`, and require this assertion to be true for
2650-
overall safety in our program. The compiler does not currently attempt to
2651-
verify this assertion; therefore we must tag this `impl` as unsafe.
2652-
"##,
2653-
26542634
E0318: r##"
26552635
Default impls for a trait must be located in the same crate where the trait was
26562636
defined. For more information see the [opt-in builtin traits RFC][RFC 19].
@@ -3457,6 +3437,56 @@ impl Foo for i32 {
34573437
```
34583438
"##,
34593439

3440+
E0436: r##"
3441+
The functional record update syntax is only allowed for structs. (Struct-like
3442+
enum variants don't qualify, for example.)
3443+
3444+
Erroneous code example:
3445+
3446+
```compile_fail,E0436
3447+
enum PublicationFrequency {
3448+
Weekly,
3449+
SemiMonthly { days: (u8, u8), annual_special: bool },
3450+
}
3451+
3452+
fn one_up_competitor(competitor_frequency: PublicationFrequency)
3453+
-> PublicationFrequency {
3454+
match competitor_frequency {
3455+
PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
3456+
days: (1, 15), annual_special: false
3457+
},
3458+
c @ PublicationFrequency::SemiMonthly{ .. } =>
3459+
PublicationFrequency::SemiMonthly {
3460+
annual_special: true, ..c // error: functional record update
3461+
// syntax requires a struct
3462+
}
3463+
}
3464+
}
3465+
```
3466+
3467+
Rewrite the expression without functional record update syntax:
3468+
3469+
```
3470+
enum PublicationFrequency {
3471+
Weekly,
3472+
SemiMonthly { days: (u8, u8), annual_special: bool },
3473+
}
3474+
3475+
fn one_up_competitor(competitor_frequency: PublicationFrequency)
3476+
-> PublicationFrequency {
3477+
match competitor_frequency {
3478+
PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
3479+
days: (1, 15), annual_special: false
3480+
},
3481+
PublicationFrequency::SemiMonthly{ days, .. } =>
3482+
PublicationFrequency::SemiMonthly {
3483+
days, annual_special: true // ok!
3484+
}
3485+
}
3486+
}
3487+
```
3488+
"##,
3489+
34603490
E0439: r##"
34613491
The length of the platform-intrinsic function `simd_shuffle`
34623492
wasn't specified. Erroneous code example:
@@ -3926,6 +3956,28 @@ See [RFC 1522] for more details.
39263956
[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
39273957
"##,
39283958

3959+
E0569: r##"
3960+
If an impl has a generic parameter with the `#[may_dangle]` attribute, then
3961+
that impl must be declared as an `unsafe impl.
3962+
3963+
Erroneous code example:
3964+
3965+
```compile_fail,E0569
3966+
#![feature(generic_param_attrs)]
3967+
#![feature(dropck_eyepatch)]
3968+
3969+
struct Foo<X>(X);
3970+
impl<#[may_dangle] X> Drop for Foo<X> {
3971+
fn drop(&mut self) { }
3972+
}
3973+
```
3974+
3975+
In this example, we are asserting that the destructor for `Foo` will not
3976+
access any data of type `X`, and require this assertion to be true for
3977+
overall safety in our program. The compiler does not currently attempt to
3978+
verify this assertion; therefore we must tag this `impl` as unsafe.
3979+
"##,
3980+
39293981
E0570: r##"
39303982
The requested ABI is unsupported by the current target.
39313983
@@ -4655,7 +4707,6 @@ register_diagnostics! {
46554707
// E0372, // coherence not object safe
46564708
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
46574709
// between structures with the same definition
4658-
E0436, // functional record update requires a struct
46594710
E0521, // redundant default implementations of trait
46604711
E0533, // `{}` does not name a unit variant, unit struct or a constant
46614712
E0563, // cannot determine a type for this `impl Trait`: {}

0 commit comments

Comments
 (0)