Skip to content

Commit 15d012c

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 8cefb89 commit 15d012c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tests/ui/needless_pass_by_ref_mut.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#![allow(clippy::if_same_then_else, clippy::no_effect, clippy::redundant_closure_call)]
1+
#![allow(
2+
clippy::if_same_then_else,
3+
clippy::no_effect,
4+
clippy::redundant_closure_call,
5+
clippy::mut_from_ref
6+
)]
27
#![warn(clippy::needless_pass_by_ref_mut)]
38
#![feature(lint_reasons)]
49
//@no-rustfix
@@ -270,6 +275,18 @@ pub async fn closure4(n: &mut usize) {
270275
})();
271276
}
272277

278+
struct Data<T: ?Sized> {
279+
value: T,
280+
}
281+
// Unsafe functions should not warn.
282+
unsafe fn get_mut_unchecked<T>(ptr: &NonNull<Data<T>>) -> &mut T {
283+
&mut (*ptr.as_ptr()).value
284+
}
285+
// Unsafe blocks should not warn.
286+
fn get_mut_unchecked2<T>(ptr: &NonNull<Data<T>>) -> &mut T {
287+
unsafe { &mut (*ptr.as_ptr()).value }
288+
}
289+
273290
fn main() {
274291
let mut u = 0;
275292
let mut v = vec![0];

0 commit comments

Comments
 (0)