Skip to content

Commit d9bb636

Browse files
---
yaml --- r: 227830 b: refs/heads/try c: b7e41d9 h: refs/heads/master v: v3
1 parent cf7bef6 commit d9bb636

File tree

3 files changed

+53
-55
lines changed

3 files changed

+53
-55
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 47c3dc2e7eda06c5637685597359bb23939cbfe4
4+
refs/heads/try: b7e41d9aeaade8a42ee9e71de34fdf2d982c664f
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/librustc/diagnostics.rs

Lines changed: 52 additions & 3 deletions
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
}

branches/try/src/librustc_typeck/diagnostics.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,57 +1538,6 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust
15381538
-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
15391539
"##
15401540

1541-
E0395: r##"
1542-
The value assigned to a constant expression must be known at compile time,
1543-
which is not the case when comparing raw pointers. Erroneous code example:
1544-
1545-
```
1546-
static foo: i32 = 42;
1547-
static bar: i32 = 43;
1548-
1549-
static baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
1550-
// error: raw pointers cannot be compared in statics!
1551-
```
1552-
1553-
To fix this error, please not assign this value to a constant expression.
1554-
Example:
1555-
1556-
```
1557-
static foo: i32 = 42;
1558-
static bar: i32 = 43;
1559-
1560-
let baz: bool = { (&foo as *const i32) == (&bar as *const i32) };
1561-
// baz isn't a constant expression so it's ok
1562-
```
1563-
"##,
1564-
1565-
E0396: r##"
1566-
The value assigned to a constant expression must be known at compile time,
1567-
which is not the case when dereferencing raw pointers. Erroneous code
1568-
example:
1569-
1570-
```
1571-
const foo: i32 = 42;
1572-
const baz: *const i32 = (&foo as *const i32);
1573-
1574-
const deref: i32 = *baz;
1575-
// error: raw pointers cannot be dereferenced in constants!
1576-
```
1577-
1578-
To fix this error, please not assign this value to a constant expression.
1579-
Example:
1580-
1581-
```
1582-
const foo: i32 = 42;
1583-
const baz: *const i32 = (&foo as *const i32);
1584-
1585-
unsafe { let deref: i32 = *baz; }
1586-
// baz isn't a constant expression so it's ok
1587-
```
1588-
1589-
You'll also note that this assignation must be done in an unsafe block!
1590-
"##
1591-
15921541
}
15931542

15941543

0 commit comments

Comments
 (0)