rust-analyzer: False positive ``unnecessary 'unsafe' block`` warning?
I’m not sure if this is a part of GenericDetour::call being generated by a macro, I thought this was fixed with expanding macros though. Removing the unsafe block just causes a missing-unsafe error
use detour::GenericDetour;
type Add5 = extern "Rust" fn(i32) -> i32;
extern "Rust" fn add_5(n: i32) -> i32 { n + 5 }
extern "Rust" fn hookfn(n: i32) -> i32 { n + 50 }
fn main() -> Result<(), detour::Error> {
let hook = unsafe { GenericDetour::<Add5>::new(add_5, hookfn)? };
// This unsafe is needed (afaik) yet causes a ``unnecessary `unsafe` block`` diagnostic?
let _res = unsafe { hook.call(50) };
Ok(())
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 15 (8 by maintainers)
@rossmacarthur try enabling
rust-analyzer.experimental.procAttrMacros.I’m still getting this error, even with the nightly rust-analyzer (with stable rust and 2021 profile) nevermind this might be an error with my vim config. VScode seems to work fine.
@nbars see #10022
It appears that using the nightly channel via
"rust-analyzer.updates.channel": "nightly"solves the problem.Encountered this when using
wasm-bindgenmy_functionis safe here but ra thinks it is unsafe.