You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#121782 - RalfJung:mutable-ref-in-static, r=oli-obk
allow statics pointing to mutable statics
Fixesrust-lang#120450 for good. We can even simplify our checks: no need to specifically go looking for mutable references in const, we can just reject any reference that points to something mutable.
r? `@oli-obk`
Copy file name to clipboardExpand all lines: tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.stderr
+6-28
Original file line number
Diff line number
Diff line change
@@ -2,26 +2,15 @@ error[E0080]: it is undefined behavior to use this value
2
2
--> $DIR/mut_ref_in_final_dynamic_check.rs:20:1
3
3
|
4
4
LL | const MUT: Option<&mut i32> = helper();
5
-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0: encountered mutable reference in a `const` or `static`
5
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0: encountered reference to mutable memory in `const`
6
6
|
7
7
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8
8
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
9
9
HEX_DUMP
10
10
}
11
11
12
12
error[E0080]: it is undefined behavior to use this value
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0: encountered mutable reference in a `const` or `static`
17
-
|
18
-
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
19
-
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
20
-
HEX_DUMP
21
-
}
22
-
23
-
error[E0080]: it is undefined behavior to use this value
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0: encountered a dangling reference (0x2a[noalloc] has no provenance)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0: encountered a dangling reference (0x2a[noalloc] has no provenance)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .data.value: encountered mutable reference in a `const` or `static`
62
-
|
63
-
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
64
-
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
65
-
HEX_DUMP
66
-
}
67
-
68
-
error: aborting due to 7 previous errors
46
+
error: aborting due to 5 previous errors
69
47
70
48
For more information about this error, try `rustc --explain E0080`.
0 commit comments