11error[E0764]: mutable references are not allowed in the final value of constants
2- --> $DIR/mut_ref_in_final.rs:9 :21
2+ --> $DIR/mut_ref_in_final.rs:14 :21
33 |
44LL | const B: *mut i32 = &mut 4;
55 | ^^^^^^
66
77error[E0716]: temporary value dropped while borrowed
8- --> $DIR/mut_ref_in_final.rs:15 :40
8+ --> $DIR/mut_ref_in_final.rs:20 :40
99 |
1010LL | const B3: Option<&mut i32> = Some(&mut 42);
1111 | ----------^^-
@@ -15,7 +15,7 @@ LL | const B3: Option<&mut i32> = Some(&mut 42);
1515 | using this value as a constant requires that borrow lasts for `'static`
1616
1717error[E0716]: temporary value dropped while borrowed
18- --> $DIR/mut_ref_in_final.rs:18 :42
18+ --> $DIR/mut_ref_in_final.rs:23 :42
1919 |
2020LL | const B4: Option<&mut i32> = helper(&mut 42);
2121 | ------------^^-
@@ -24,8 +24,19 @@ LL | const B4: Option<&mut i32> = helper(&mut 42);
2424 | | creates a temporary value which is freed while still in use
2525 | using this value as a constant requires that borrow lasts for `'static`
2626
27+ error[E0080]: it is undefined behavior to use this value
28+ --> $DIR/mut_ref_in_final.rs:26:1
29+ |
30+ LL | const IMMUT_MUT_REF: &mut u16 = unsafe { mem::transmute(&13) };
31+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
32+ |
33+ = 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.
34+ = note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
35+ HEX_DUMP
36+ }
37+
2738error[E0716]: temporary value dropped while borrowed
28- --> $DIR/mut_ref_in_final.rs:40 :65
39+ --> $DIR/mut_ref_in_final.rs:50 :65
2940 |
3041LL | const FOO: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
3142 | -------------------------------^^--
@@ -35,7 +46,7 @@ LL | const FOO: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
3546 | using this value as a constant requires that borrow lasts for `'static`
3647
3748error[E0716]: temporary value dropped while borrowed
38- --> $DIR/mut_ref_in_final.rs:43 :67
49+ --> $DIR/mut_ref_in_final.rs:53 :67
3950 |
4051LL | static FOO2: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
4152 | -------------------------------^^--
@@ -45,7 +56,7 @@ LL | static FOO2: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
4556 | using this value as a static requires that borrow lasts for `'static`
4657
4758error[E0716]: temporary value dropped while borrowed
48- --> $DIR/mut_ref_in_final.rs:46 :71
59+ --> $DIR/mut_ref_in_final.rs:56 :71
4960 |
5061LL | static mut FOO3: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
5162 | -------------------------------^^--
@@ -55,30 +66,30 @@ LL | static mut FOO3: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
5566 | using this value as a static requires that borrow lasts for `'static`
5667
5768error[E0764]: mutable references are not allowed in the final value of statics
58- --> $DIR/mut_ref_in_final.rs:59 :53
69+ --> $DIR/mut_ref_in_final.rs:69 :53
5970 |
6071LL | static RAW_MUT_CAST_S: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
6172 | ^^^^^^^
6273
6374error[E0764]: mutable references are not allowed in the final value of statics
64- --> $DIR/mut_ref_in_final.rs:61 :54
75+ --> $DIR/mut_ref_in_final.rs:71 :54
6576 |
6677LL | static RAW_MUT_COERCE_S: SyncPtr<i32> = SyncPtr { x: &mut 0 };
6778 | ^^^^^^
6879
6980error[E0764]: mutable references are not allowed in the final value of constants
70- --> $DIR/mut_ref_in_final.rs:63 :52
81+ --> $DIR/mut_ref_in_final.rs:73 :52
7182 |
7283LL | const RAW_MUT_CAST_C: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
7384 | ^^^^^^^
7485
7586error[E0764]: mutable references are not allowed in the final value of constants
76- --> $DIR/mut_ref_in_final.rs:65 :53
87+ --> $DIR/mut_ref_in_final.rs:75 :53
7788 |
7889LL | const RAW_MUT_COERCE_C: SyncPtr<i32> = SyncPtr { x: &mut 0 };
7990 | ^^^^^^
8091
81- error: aborting due to 10 previous errors
92+ error: aborting due to 11 previous errors
8293
83- Some errors have detailed explanations: E0716, E0764.
84- For more information about an error, try `rustc --explain E0716 `.
94+ Some errors have detailed explanations: E0080, E0716, E0764.
95+ For more information about an error, try `rustc --explain E0080 `.
0 commit comments