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

This commit is contained in:
Guillaume Gomez 2023-10-06 12:01:23 +02:00
parent bc97f7d0c9
commit 80a092c6df

View file

@ -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];