Skip to content

Commit 4279f79

Browse files
---
yaml --- r: 234901 b: refs/heads/stable c: b7e41d9 h: refs/heads/master i: 234899: 3c4391d v: v3
1 parent d73bc20 commit 4279f79

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
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 47c3dc2e7eda06c5637685597359bb23939cbfe4
32+
refs/heads/stable: b7e41d9aeaade8a42ee9e71de34fdf2d982c664f
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

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