Auto merge of #26542 - GuillaumeGomez:patch-2, r=Manishearth

This commit is contained in:
bors 2015-06-25 17:21:44 +00:00
commit 70b2f4789e
2 changed files with 88 additions and 4 deletions

View File

@ -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:
@ -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
}

View File

@ -1458,6 +1458,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:
@ -1640,7 +1676,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