Skip to content

Commit 5acc68b

Browse files
committed
go back to testing volatile in the lint
But note we're testing that *it doesn't fire* this time. This partially reverts commit 8368ac9.
1 parent 109260f commit 5acc68b

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

tests/ui/lint/invalid_null_args.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ unsafe fn null_ptr() {
5858
let _a: A = ptr::read_unaligned(ptr::null_mut());
5959
//~^ ERROR calling this function with a null pointer is undefined behavior
6060

61+
// These two should *not* fire the lint.
62+
let _a: A = ptr::read_volatile(ptr::null());
63+
let _a: A = ptr::read_volatile(ptr::null_mut());
64+
6165
let _a: A = ptr::replace(ptr::null_mut(), v);
6266
//~^ ERROR calling this function with a null pointer is undefined behavior
6367

@@ -77,6 +81,12 @@ unsafe fn null_ptr() {
7781
ptr::write_unaligned(ptr::null_mut(), v);
7882
//~^ ERROR calling this function with a null pointer is undefined behavior
7983

84+
// This one should *not* fire the lint.
85+
ptr::write_volatile(ptr::null_mut(), v);
86+
87+
ptr::write_bytes::<usize>(ptr::null_mut(), 42, 0);
88+
//~^ ERROR calling this function with a null pointer is undefined behavior
89+
8090
// with indirections
8191
let const_ptr = null_ptr as *const u8;
8292
let _a: u8 = ptr::read(const_ptr);

tests/ui/lint/invalid_null_args.stderr

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ LL | let _a: A = ptr::read_unaligned(ptr::null_mut());
164164
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
165165

166166
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
167-
--> $DIR/invalid_null_args.rs:61:17
167+
--> $DIR/invalid_null_args.rs:65:17
168168
|
169169
LL | let _a: A = ptr::replace(ptr::null_mut(), v);
170170
| ^^^^^^^^^^^^^---------------^^^^
@@ -174,7 +174,7 @@ LL | let _a: A = ptr::replace(ptr::null_mut(), v);
174174
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
175175

176176
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
177-
--> $DIR/invalid_null_args.rs:64:5
177+
--> $DIR/invalid_null_args.rs:68:5
178178
|
179179
LL | ptr::swap::<A>(ptr::null_mut(), &mut v);
180180
| ^^^^^^^^^^^^^^^---------------^^^^^^^^^
@@ -184,7 +184,7 @@ LL | ptr::swap::<A>(ptr::null_mut(), &mut v);
184184
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
185185

186186
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
187-
--> $DIR/invalid_null_args.rs:66:5
187+
--> $DIR/invalid_null_args.rs:70:5
188188
|
189189
LL | ptr::swap::<A>(&mut v, ptr::null_mut());
190190
| ^^^^^^^^^^^^^^^^^^^^^^^---------------^
@@ -194,7 +194,7 @@ LL | ptr::swap::<A>(&mut v, ptr::null_mut());
194194
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
195195

196196
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
197-
--> $DIR/invalid_null_args.rs:69:5
197+
--> $DIR/invalid_null_args.rs:73:5
198198
|
199199
LL | ptr::swap_nonoverlapping::<A>(ptr::null_mut(), &mut v, 0);
200200
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------^^^^^^^^^^^^
@@ -204,7 +204,7 @@ LL | ptr::swap_nonoverlapping::<A>(ptr::null_mut(), &mut v, 0);
204204
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
205205

206206
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
207-
--> $DIR/invalid_null_args.rs:71:5
207+
--> $DIR/invalid_null_args.rs:75:5
208208
|
209209
LL | ptr::swap_nonoverlapping::<A>(&mut v, ptr::null_mut(), 0);
210210
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------^^^^
@@ -214,7 +214,7 @@ LL | ptr::swap_nonoverlapping::<A>(&mut v, ptr::null_mut(), 0);
214214
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
215215

216216
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
217-
--> $DIR/invalid_null_args.rs:74:5
217+
--> $DIR/invalid_null_args.rs:78:5
218218
|
219219
LL | ptr::write(ptr::null_mut(), v);
220220
| ^^^^^^^^^^^---------------^^^^
@@ -224,7 +224,7 @@ LL | ptr::write(ptr::null_mut(), v);
224224
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
225225

226226
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
227-
--> $DIR/invalid_null_args.rs:77:5
227+
--> $DIR/invalid_null_args.rs:81:5
228228
|
229229
LL | ptr::write_unaligned(ptr::null_mut(), v);
230230
| ^^^^^^^^^^^^^^^^^^^^^---------------^^^^
@@ -234,7 +234,17 @@ LL | ptr::write_unaligned(ptr::null_mut(), v);
234234
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
235235

236236
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
237-
--> $DIR/invalid_null_args.rs:82:18
237+
--> $DIR/invalid_null_args.rs:87:5
238+
|
239+
LL | ptr::write_bytes::<usize>(ptr::null_mut(), 42, 0);
240+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^---------------^^^^^^^^
241+
| |
242+
| null pointer originates from here
243+
|
244+
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
245+
246+
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
247+
--> $DIR/invalid_null_args.rs:92:18
238248
|
239249
LL | let _a: u8 = ptr::read(const_ptr);
240250
| ^^^^^^^^^^^^^^^^^^^^
@@ -247,7 +257,7 @@ LL | let null_ptr = ptr::null_mut();
247257
| ^^^^^^^^^^^^^^^
248258

249259
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
250-
--> $DIR/invalid_null_args.rs:89:5
260+
--> $DIR/invalid_null_args.rs:99:5
251261
|
252262
LL | std::slice::from_raw_parts::<()>(ptr::null(), 0);
253263
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^
@@ -257,7 +267,7 @@ LL | std::slice::from_raw_parts::<()>(ptr::null(), 0);
257267
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
258268

259269
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
260-
--> $DIR/invalid_null_args.rs:91:5
270+
--> $DIR/invalid_null_args.rs:101:5
261271
|
262272
LL | std::slice::from_raw_parts::<Zst>(ptr::null(), 0);
263273
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^
@@ -267,7 +277,7 @@ LL | std::slice::from_raw_parts::<Zst>(ptr::null(), 0);
267277
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
268278

269279
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
270-
--> $DIR/invalid_null_args.rs:93:5
280+
--> $DIR/invalid_null_args.rs:103:5
271281
|
272282
LL | std::slice::from_raw_parts_mut::<()>(ptr::null_mut(), 0);
273283
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------^^^^
@@ -277,7 +287,7 @@ LL | std::slice::from_raw_parts_mut::<()>(ptr::null_mut(), 0);
277287
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
278288

279289
error: calling this function with a null pointer is undefined behavior, even if the result of the function is unused
280-
--> $DIR/invalid_null_args.rs:95:5
290+
--> $DIR/invalid_null_args.rs:105:5
281291
|
282292
LL | std::slice::from_raw_parts_mut::<Zst>(ptr::null_mut(), 0);
283293
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------^^^^
@@ -286,5 +296,5 @@ LL | std::slice::from_raw_parts_mut::<Zst>(ptr::null_mut(), 0);
286296
|
287297
= help: for more information, visit <https://doc.rust-lang.org/std/ptr/index.html> and <https://doc.rust-lang.org/reference/behavior-considered-undefined.html>
288298

289-
error: aborting due to 27 previous errors
299+
error: aborting due to 28 previous errors
290300

0 commit comments

Comments
 (0)