File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -1538,8 +1538,60 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust
1538
1538
-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
1539
1539
"##
1540
1540
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
+
1541
1592
}
1542
1593
1594
+
1543
1595
register_diagnostics ! {
1544
1596
E0068 ,
1545
1597
E0074 ,
You can’t perform that action at this time.
0 commit comments