Closed
Description
The following example triggers the unsafe_op_in_unsafe_fn
lint twice in the same position:
#![warn(unsafe_op_in_unsafe_fn)]
macro_rules! foo {
($x:ident) => {
pub unsafe fn $x() {
let _ = String::new().as_mut_vec();
}
};
}
foo!(a);
foo!(b);
This causes cargo fix
to apply both suggestions which ends up with:
// ...snip
pub unsafe fn $x() { unsafe { unsafe {
let _ = String::new().as_mut_vec();
}}}
// ...snip
which triggers the unused_unsafe
lint.
Would it be possible to avoid duplicate suggestions when used in a macro?
cc @asquared31415
I suspect this may be encountered frequently with the 2024 edition migration (crater run is pending in #122960). Although it isn't too much of a problem to repair, a frequently used macro could have many unsafe blocks, which could be confusing.
rustc 1.79.0-nightly (8df7e723e 2024-03-30)
binary: rustc
commit-hash: 8df7e723ea729a7f917501cc2d91d640b7021373
commit-date: 2024-03-30
host: aarch64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2