Skip to content

Commit 6e6e267

Browse files
Add test for needless_pass_by_ref_mut to ensure that the lint is not emitted if variable is used in an unsafe block or function
1 parent c40e242 commit 6e6e267

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/ui/needless_pass_by_ref_mut.rs

+12
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,18 @@ pub async fn closure4(n: &mut usize) {
270270
})();
271271
}
272272

273+
struct Data<T: ?Sized> {
274+
value: T,
275+
}
276+
// Unsafe functions should not warn.
277+
unsafe fn get_mut_unchecked<T>(ptr: &mut NonNull<Data<T>>) -> &mut T {
278+
&mut (*ptr.as_ptr()).value
279+
}
280+
// Unsafe blocks should not warn.
281+
fn get_mut_unchecked2<T>(ptr: &mut NonNull<Data<T>>) -> &mut T {
282+
unsafe { &mut (*ptr.as_ptr()).value }
283+
}
284+
273285
fn main() {
274286
let mut u = 0;
275287
let mut v = vec![0];

0 commit comments

Comments
 (0)