Skip to content

a couple more error explanations for posterity #43519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/librustc_borrowck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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...
}
93 changes: 72 additions & 21 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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`: {}
Expand Down