Skip to content

Commit 62a9cad

Browse files
committed
Add needless_pass_by_ref_mut edition 2021 specific test
There is a specific test that `unsafe fn` are not lint, and that `unsafe` blocks are not lint either. Since in edition 2024 `unsafe` blocks are required inside `unsafe fn` to do unsafe things, set up a specific test for edition 2021.
1 parent cd26de6 commit 62a9cad

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

tests/ui/needless_pass_by_ref_mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ struct Data<T: ?Sized> {
301301
}
302302
// Unsafe functions should not warn.
303303
unsafe fn get_mut_unchecked<T>(ptr: &mut NonNull<Data<T>>) -> &mut T {
304-
&mut (*ptr.as_ptr()).value
304+
unsafe { &mut (*ptr.as_ptr()).value }
305305
}
306306
// Unsafe blocks should not warn.
307307
fn get_mut_unchecked2<T>(ptr: &mut NonNull<Data<T>>) -> &mut T {
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@edition: 2021
2+
//@check-pass
3+
#![warn(clippy::needless_pass_by_ref_mut)]
4+
5+
struct Data<T: ?Sized> {
6+
value: T,
7+
}
8+
9+
// Unsafe functions should not warn.
10+
unsafe fn get_mut_unchecked<T>(ptr: &mut std::ptr::NonNull<Data<T>>) -> &mut T {
11+
&mut (*ptr.as_ptr()).value
12+
}

0 commit comments

Comments
 (0)