@@ -4,61 +4,80 @@ error: casting `&T` to `&mut T` is undefined behavior, even if the reference is
4
4
LL | let _num = &mut *(num as *const i32 as *mut i32);
5
5
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
6
|
7
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
7
8
= note: `#[deny(invalid_reference_casting)]` on by default
8
9
9
10
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
10
11
--> $DIR/reference_casting.rs:21:16
11
12
|
12
13
LL | let _num = &mut *(num as *const i32).cast_mut();
13
14
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15
+ |
16
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
14
17
15
18
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
16
19
--> $DIR/reference_casting.rs:23:16
17
20
|
18
21
LL | let _num = &mut *std::ptr::from_ref(num).cast_mut();
19
22
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23
+ |
24
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
20
25
21
26
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
22
27
--> $DIR/reference_casting.rs:25:16
23
28
|
24
29
LL | let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
25
30
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31
+ |
32
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
26
33
27
34
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
28
35
--> $DIR/reference_casting.rs:27:16
29
36
|
30
37
LL | let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
31
38
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39
+ |
40
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
32
41
33
42
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
34
43
--> $DIR/reference_casting.rs:29:16
35
44
|
36
45
LL | let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
37
46
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47
+ |
48
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
38
49
39
50
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
40
51
--> $DIR/reference_casting.rs:31:16
41
52
|
42
53
LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut();
43
54
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55
+ |
56
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
44
57
45
58
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
46
59
--> $DIR/reference_casting.rs:33:16
47
60
|
48
61
LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_const().cast_mut();
49
62
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63
+ |
64
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
50
65
51
66
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
52
67
--> $DIR/reference_casting.rs:35:16
53
68
|
54
69
LL | let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i32);
55
70
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71
+ |
72
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
56
73
57
74
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
58
75
--> $DIR/reference_casting.rs:37:16
59
76
|
60
77
LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
61
78
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79
+ |
80
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
62
81
63
82
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
64
83
--> $DIR/reference_casting.rs:41:16
@@ -67,6 +86,8 @@ LL | let deferred = num as *const i32 as *mut i32;
67
86
| ----------------------------- casting happend here
68
87
LL | let _num = &mut *deferred;
69
88
| ^^^^^^^^^^^^^^
89
+ |
90
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
70
91
71
92
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
72
93
--> $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
75
96
| ---------------------------------------------------------------------------- casting happend here
76
97
LL | let _num = &mut *deferred;
77
98
| ^^^^^^^^^^^^^^
99
+ |
100
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
78
101
79
102
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
80
103
--> $DIR/reference_casting.rs:46:16
81
104
|
82
105
LL | let _num = &mut *(num as *const _ as usize as *mut i32);
83
106
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107
+ |
108
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
84
109
85
110
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
86
111
--> $DIR/reference_casting.rs:50:9
87
112
|
88
113
LL | &mut *((this as *const _) as *mut _)
89
114
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115
+ |
116
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
90
117
91
118
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
92
119
--> $DIR/reference_casting.rs:60:5
93
120
|
94
121
LL | *(a as *const _ as *mut _) = String::from("Replaced");
95
122
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123
+ |
124
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
96
125
97
126
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
98
127
--> $DIR/reference_casting.rs:62:5
99
128
|
100
129
LL | *(a as *const _ as *mut String) += " world";
101
130
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
131
+ |
132
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
102
133
103
134
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
104
135
--> $DIR/reference_casting.rs:64:5
105
136
|
106
137
LL | *std::ptr::from_ref(num).cast_mut() += 1;
107
138
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139
+ |
140
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
108
141
109
142
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
110
143
--> $DIR/reference_casting.rs:66:5
111
144
|
112
145
LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
113
146
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147
+ |
148
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
114
149
115
150
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
116
151
--> $DIR/reference_casting.rs:68:5
117
152
|
118
153
LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
119
154
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155
+ |
156
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
120
157
121
158
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
122
159
--> $DIR/reference_casting.rs:70:5
123
160
|
124
161
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
125
162
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
163
+ |
164
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
126
165
127
166
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
128
167
--> $DIR/reference_casting.rs:72:5
129
168
|
130
169
LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
131
170
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
171
+ |
172
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
132
173
133
174
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
134
175
--> $DIR/reference_casting.rs:74:5
@@ -147,18 +188,24 @@ LL | let value = num as *const i32 as *mut i32;
147
188
| ----------------------------- casting happend here
148
189
LL | *value = 1;
149
190
| ^^^^^^^^^^
191
+ |
192
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
150
193
151
194
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
152
195
--> $DIR/reference_casting.rs:83:5
153
196
|
154
197
LL | *(num as *const i32).cast::<i32>().cast_mut() = 2;
155
198
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
199
+ |
200
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
156
201
157
202
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
158
203
--> $DIR/reference_casting.rs:85:5
159
204
|
160
205
LL | *(num as *const _ as usize as *mut i32) = 2;
161
206
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
207
+ |
208
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
162
209
163
210
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
164
211
--> $DIR/reference_casting.rs:87:5
@@ -192,6 +239,8 @@ error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
192
239
|
193
240
LL | *(this as *const _ as *mut _) = a;
194
241
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
242
+ |
243
+ = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
195
244
196
245
error: aborting due to 29 previous errors
197
246
0 commit comments