Skip to content

Commit

Permalink
Add test for needless_pass_by_ref_mut to ensure that the lint is no…
Browse files Browse the repository at this point in the history
…t emitted if variable is used in an unsafe block or function
  • Loading branch information
GuillaumeGomez committed Oct 6, 2023
1 parent 8cefb89 commit 15d012c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/ui/needless_pass_by_ref_mut.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![allow(clippy::if_same_then_else, clippy::no_effect, clippy::redundant_closure_call)]
#![allow(
clippy::if_same_then_else,
clippy::no_effect,
clippy::redundant_closure_call,
clippy::mut_from_ref
)]
#![warn(clippy::needless_pass_by_ref_mut)]
#![feature(lint_reasons)]
//@no-rustfix
Expand Down Expand Up @@ -270,6 +275,18 @@ pub async fn closure4(n: &mut usize) {
})();
}

struct Data<T: ?Sized> {
value: T,
}
// Unsafe functions should not warn.
unsafe fn get_mut_unchecked<T>(ptr: &NonNull<Data<T>>) -> &mut T {
&mut (*ptr.as_ptr()).value
}
// Unsafe blocks should not warn.
fn get_mut_unchecked2<T>(ptr: &NonNull<Data<T>>) -> &mut T {
unsafe { &mut (*ptr.as_ptr()).value }
}

fn main() {
let mut u = 0;
let mut v = vec![0];
Expand Down

0 comments on commit 15d012c

Please sign in to comment.