Skip to content

Add E0327, E0395 and E0396 error explanations #26542

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
Jun 25, 2015
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
55 changes: 52 additions & 3 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,57 @@ From [RFC 246]:
[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
"##,

E0395: r##"
The value assigned to a constant expression must be known at compile time,
which is not the case when comparing raw pointers. Erroneous code example:

```
static foo: i32 = 42;
static bar: i32 = 43;

static baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
// error: raw pointers cannot be compared in statics!
```

Please check that the result of the comparison can be determined at compile time
or isn't assigned to a constant expression. Example:

```
static foo: i32 = 42;
static bar: i32 = 43;

let baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
// baz isn't a constant expression so it's ok
```
"##,

E0396: r##"
The value assigned to a constant expression must be known at compile time,
which is not the case when dereferencing raw pointers. Erroneous code
example:

```
const foo: i32 = 42;
const baz: *const i32 = (&foo as *const i32);

const deref: i32 = *baz;
// error: raw pointers cannot be dereferenced in constants
```

To fix this error, please do not assign this value to a constant expression.
Example:

```
const foo: i32 = 42;
const baz: *const i32 = (&foo as *const i32);

unsafe { let deref: i32 = *baz; }
// baz isn't a constant expression so it's ok
```

You'll also note that this assignment must be done in an unsafe block!
"##,

E0397: r##"
It is not allowed for a mutable static to allocate or have destructors. For
example:
Expand Down Expand Up @@ -1039,7 +1090,5 @@ register_diagnostics! {
E0314, // closure outlives stack frame
E0315, // cannot invoke closure outside of its lifetime
E0316, // nested quantification of lifetimes
E0370, // discriminant overflow
E0395, // pointer comparison in const-expr
E0396 // pointer dereference in const-expr
E0370 // discriminant overflow
}
37 changes: 36 additions & 1 deletion src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,42 @@ impl Foo for Bar {
```
"##,

E0327: r##"
You cannot use associated items other than constant items as patterns. This
includes method items. Example of erroneous code:

```
enum B {}

impl B {
fn bb() -> i32 { 0 }
}

fn main() {
match 0 {
B::bb => {} // error: associated items in match patterns must
// be constants
}
}
```

Please check that you're not using a method as a pattern. Example:

```
enum B {
ba,
bb
}

fn main() {
match B::ba {
B::bb => {} // ok!
_ => {}
}
}
```
"##,

E0368: r##"
This error indicates that a binary assignment operator like `+=` or `^=` was
applied to the wrong types. For example:
Expand Down Expand Up @@ -1639,7 +1675,6 @@ register_diagnostics! {
E0323, // implemented an associated const when another trait item expected
E0324, // implemented a method when another trait item expected
E0325, // implemented an associated type when another trait item expected
E0327, // referred to method instead of constant in match pattern
E0328, // cannot implement Unsize explicitly
E0329, // associated const depends on type parameter or Self.
E0366, // dropck forbid specialization to concrete type or region
Expand Down