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 17, 2023
1 parent bc97f7d commit 80a092c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/ui/needless_pass_by_ref_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ async fn _f(v: &mut Vec<()>) {
_ = || || x;
}

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

Please sign in to comment.