Skip to content

Commit 5b2c69e

Browse files
---
yaml --- r: 214362 b: refs/heads/auto c: b7e41d9 h: refs/heads/master v: v3
1 parent aad88f6 commit 5b2c69e

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
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 47c3dc2e7eda06c5637685597359bb23939cbfe4
11+
refs/heads/auto: b7e41d9aeaade8a42ee9e71de34fdf2d982c664f
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/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/auto/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)