@@ -4,61 +4,80 @@ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is
44LL | let _num = &mut *(num as *const i32 as *mut i32);
55 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66 |
7+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
78 = note: `#[deny(invalid_reference_casting)]` on by default
89
910error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
1011 --> $DIR/reference_casting.rs:21:16
1112 |
1213LL | let _num = &mut *(num as *const i32).cast_mut();
1314 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+ |
16+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
1417
1518error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
1619 --> $DIR/reference_casting.rs:23:16
1720 |
1821LL | let _num = &mut *std::ptr::from_ref(num).cast_mut();
1922 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+ |
24+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
2025
2126error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
2227 --> $DIR/reference_casting.rs:25:16
2328 |
2429LL | let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
2530 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+ |
32+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
2633
2734error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
2835 --> $DIR/reference_casting.rs:27:16
2936 |
3037LL | let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
3138 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+ |
40+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
3241
3342error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
3443 --> $DIR/reference_casting.rs:29:16
3544 |
3645LL | let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
3746 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47+ |
48+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
3849
3950error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
4051 --> $DIR/reference_casting.rs:31:16
4152 |
4253LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut();
4354 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55+ |
56+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
4457
4558error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
4659 --> $DIR/reference_casting.rs:33:16
4760 |
4861LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_const().cast_mut();
4962 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63+ |
64+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
5065
5166error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
5267 --> $DIR/reference_casting.rs:35:16
5368 |
5469LL | let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i32);
5570 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71+ |
72+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
5673
5774error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
5875 --> $DIR/reference_casting.rs:37:16
5976 |
6077LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
6178 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79+ |
80+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
6281
6382error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
6483 --> $DIR/reference_casting.rs:41:16
@@ -67,6 +86,8 @@ LL | let deferred = num as *const i32 as *mut i32;
6786 | ----------------------------- casting happend here
6887LL | let _num = &mut *deferred;
6988 | ^^^^^^^^^^^^^^
89+ |
90+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
7091
7192error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
7293 --> $DIR/reference_casting.rs:44:16
@@ -75,60 +96,80 @@ LL | let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).ca
7596 | ---------------------------------------------------------------------------- casting happend here
7697LL | let _num = &mut *deferred;
7798 | ^^^^^^^^^^^^^^
99+ |
100+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
78101
79102error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
80103 --> $DIR/reference_casting.rs:46:16
81104 |
82105LL | let _num = &mut *(num as *const _ as usize as *mut i32);
83106 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107+ |
108+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
84109
85110error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
86111 --> $DIR/reference_casting.rs:50:9
87112 |
88113LL | &mut *((this as *const _) as *mut _)
89114 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115+ |
116+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
90117
91118error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
92119 --> $DIR/reference_casting.rs:60:5
93120 |
94121LL | *(a as *const _ as *mut _) = String::from("Replaced");
95122 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123+ |
124+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
96125
97126error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
98127 --> $DIR/reference_casting.rs:62:5
99128 |
100129LL | *(a as *const _ as *mut String) += " world";
101130 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
131+ |
132+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
102133
103134error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
104135 --> $DIR/reference_casting.rs:64:5
105136 |
106137LL | *std::ptr::from_ref(num).cast_mut() += 1;
107138 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139+ |
140+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
108141
109142error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
110143 --> $DIR/reference_casting.rs:66:5
111144 |
112145LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
113146 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147+ |
148+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
114149
115150error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
116151 --> $DIR/reference_casting.rs:68:5
117152 |
118153LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
119154 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155+ |
156+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
120157
121158error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
122159 --> $DIR/reference_casting.rs:70:5
123160 |
124161LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
125162 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
163+ |
164+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
126165
127166error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
128167 --> $DIR/reference_casting.rs:72:5
129168 |
130169LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
131170 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
171+ |
172+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
132173
133174error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
134175 --> $DIR/reference_casting.rs:74:5
@@ -139,6 +180,8 @@ LL | | std::mem::transmute::<*const i32, *mut i32>(num),
139180LL | | -1i32,
140181LL | | );
141182 | |_____^
183+ |
184+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
142185
143186error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
144187 --> $DIR/reference_casting.rs:81:5
@@ -147,18 +190,24 @@ LL | let value = num as *const i32 as *mut i32;
147190 | ----------------------------- casting happend here
148191LL | *value = 1;
149192 | ^^^^^^^^^^
193+ |
194+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
150195
151196error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
152197 --> $DIR/reference_casting.rs:83:5
153198 |
154199LL | *(num as *const i32).cast::<i32>().cast_mut() = 2;
155200 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201+ |
202+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
156203
157204error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
158205 --> $DIR/reference_casting.rs:85:5
159206 |
160207LL | *(num as *const _ as usize as *mut i32) = 2;
161208 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
209+ |
210+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
162211
163212error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
164213 --> $DIR/reference_casting.rs:87:5
@@ -168,6 +217,8 @@ LL | let value = num as *const i32 as *mut i32;
168217...
169218LL | std::ptr::write(value, 2);
170219 | ^^^^^^^^^^^^^^^^^^^^^^^^^
220+ |
221+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
171222
172223error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
173224 --> $DIR/reference_casting.rs:89:5
@@ -177,6 +228,8 @@ LL | let value = num as *const i32 as *mut i32;
177228...
178229LL | std::ptr::write_unaligned(value, 2);
179230 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
231+ |
232+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
180233
181234error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
182235 --> $DIR/reference_casting.rs:91:5
@@ -186,12 +239,16 @@ LL | let value = num as *const i32 as *mut i32;
186239...
187240LL | std::ptr::write_volatile(value, 2);
188241 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
242+ |
243+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
189244
190245error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
191246 --> $DIR/reference_casting.rs:95:9
192247 |
193248LL | *(this as *const _ as *mut _) = a;
194249 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
250+ |
251+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
195252
196253error: aborting due to 29 previous errors
197254
0 commit comments