Skip to content

Commit 70b2f47

Browse files
committed
Auto merge of #26542 - GuillaumeGomez:patch-2, r=Manishearth
2 parents cfb7778 + 7b4eb1a commit 70b2f47

File tree

2 files changed

+88
-4
lines changed

2 files changed

+88
-4
lines changed

src/librustc/diagnostics.rs

+52-3
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,57 @@ From [RFC 246]:
984984
[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
985985
"##,
986986

987+
E0395: r##"
988+
The value assigned to a constant expression must be known at compile time,
989+
which is not the case when comparing raw pointers. Erroneous code example:
990+
991+
```
992+
static foo: i32 = 42;
993+
static bar: i32 = 43;
994+
995+
static baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
996+
// error: raw pointers cannot be compared in statics!
997+
```
998+
999+
Please check that the result of the comparison can be determined at compile time
1000+
or isn't assigned to a constant expression. Example:
1001+
1002+
```
1003+
static foo: i32 = 42;
1004+
static bar: i32 = 43;
1005+
1006+
let baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
1007+
// baz isn't a constant expression so it's ok
1008+
```
1009+
"##,
1010+
1011+
E0396: r##"
1012+
The value assigned to a constant expression must be known at compile time,
1013+
which is not the case when dereferencing raw pointers. Erroneous code
1014+
example:
1015+
1016+
```
1017+
const foo: i32 = 42;
1018+
const baz: *const i32 = (&foo as *const i32);
1019+
1020+
const deref: i32 = *baz;
1021+
// error: raw pointers cannot be dereferenced in constants
1022+
```
1023+
1024+
To fix this error, please do not assign this value to a constant expression.
1025+
Example:
1026+
1027+
```
1028+
const foo: i32 = 42;
1029+
const baz: *const i32 = (&foo as *const i32);
1030+
1031+
unsafe { let deref: i32 = *baz; }
1032+
// baz isn't a constant expression so it's ok
1033+
```
1034+
1035+
You'll also note that this assignment must be done in an unsafe block!
1036+
"##,
1037+
9871038
E0397: r##"
9881039
It is not allowed for a mutable static to allocate or have destructors. For
9891040
example:
@@ -1039,7 +1090,5 @@ register_diagnostics! {
10391090
E0314, // closure outlives stack frame
10401091
E0315, // cannot invoke closure outside of its lifetime
10411092
E0316, // nested quantification of lifetimes
1042-
E0370, // discriminant overflow
1043-
E0395, // pointer comparison in const-expr
1044-
E0396 // pointer dereference in const-expr
1093+
E0370 // discriminant overflow
10451094
}

src/librustc_typeck/diagnostics.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,42 @@ impl Foo for Bar {
14581458
```
14591459
"##,
14601460

1461+
E0327: r##"
1462+
You cannot use associated items other than constant items as patterns. This
1463+
includes method items. Example of erroneous code:
1464+
1465+
```
1466+
enum B {}
1467+
1468+
impl B {
1469+
fn bb() -> i32 { 0 }
1470+
}
1471+
1472+
fn main() {
1473+
match 0 {
1474+
B::bb => {} // error: associated items in match patterns must
1475+
// be constants
1476+
}
1477+
}
1478+
```
1479+
1480+
Please check that you're not using a method as a pattern. Example:
1481+
1482+
```
1483+
enum B {
1484+
ba,
1485+
bb
1486+
}
1487+
1488+
fn main() {
1489+
match B::ba {
1490+
B::bb => {} // ok!
1491+
_ => {}
1492+
}
1493+
}
1494+
```
1495+
"##,
1496+
14611497
E0368: r##"
14621498
This error indicates that a binary assignment operator like `+=` or `^=` was
14631499
applied to the wrong types. For example:
@@ -1640,7 +1676,6 @@ register_diagnostics! {
16401676
E0323, // implemented an associated const when another trait item expected
16411677
E0324, // implemented a method when another trait item expected
16421678
E0325, // implemented an associated type when another trait item expected
1643-
E0327, // referred to method instead of constant in match pattern
16441679
E0328, // cannot implement Unsize explicitly
16451680
E0329, // associated const depends on type parameter or Self.
16461681
E0366, // dropck forbid specialization to concrete type or region

0 commit comments

Comments
 (0)