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 c40e242 commit 6e6e267
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 @@ -270,6 +270,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: &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 6e6e267

Please sign in to comment.