-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ambiguous "unsafe" Error WASM JS alert #5412
Comments
That's just because we don't expand procedural macros yet. Presumably it does some magic to make these operations safe. |
Would you rather recommend to get the "unsafe" error or the "unused unsafe" warning? Or in other words is my temporary 'fix' the right thing to do or should I just ignore it? |
I'd suggest listening to the rustc warning, not rust-analyzer. If the wrong diagnostics from rust-analyzer annoys you, you can also turn it off in the settings (but this currently turns all of them off). |
5682: Add an option to disable diagnostics r=matklad a=popzxc As far as I know, currently it's not possible to disable a selected type of diagnostics provided by `rust-analyzer`. This causes an inconvenient situation with a false-positive warnings: you either have to disable all the diagnostics, or you have to ignore these warnings. There are some open issues related to this problem, e.g.: #5412, #5502 This PR attempts to make it possible to selectively disable some diagnostics on per-project basis. Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
I just hit this today myself. Is there a timeline on rust-analyzer being able to run proc-macros? |
Derive proc macros already work when you enable them. The other kinds are not yet supported. I don't know of any timeline for imolementing this. |
The latest release has preliminary support for function-like procedural macros like Attribute macros are harder to implement and require pretty hairy name resolution changes. |
For those looking to disable the
credit to @popzxc for landing #5682, which makes the above possible |
Is it possible to disable these diagnostics locally, using an attribute like with clippy lints? |
Not yet, no |
I just ran into this issue with cxx, which uses macros to generate safe C++ FFIs. |
You can enable proc-macro support using {
"rust-analyzer.cargo.loadOutDirsFromCheck": true,
"rust-analyzer.procMacro.enable": true,
} |
Thanks @bjorn3, but unfortunately, that didn't get rid of the erroneous warning. I think I'll stick with disabling |
@OliverEvans96 |
You can get rid of this error / warning locally by putting an unsafe block and then surpressing the warning, but it is not a great way to handle that: #[wasm_bindgen]
pub fn greet(name: &str) {
#[allow(unused_unsafe)]
unsafe {
alert(&format!("Hello, {}!", name));
}
} |
9128: feat: expand procedural attribute macros r=jonas-schievink a=jonas-schievink This adds experimental support for attribute macros. They can be enabled by setting `rust-analyzer.experimental.procAttrMacros` to `true`. Known issues: * Tokens aren't remapped, presumably because we edit the input syntax tree (this causes IDE features to not work inside items with attribute macros on them) * Macro errors aren't reported correctly Closes #8971 Fixes #8964 / la10736/rstest#120 Fixes #2984 Fixes #5412 Fixes #6029 Fixes #6687 #6740 is still not fixed – we now expand `#[proc_macro_hack]`, but fail to expand the resulting `proc_macro_call!()` macro. Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Just in case anyone doesn't think to check the merged PR and runs into this, I can confirm that I was able to set this in VS Code and got the warning to go away:
|
For folks using Doom Emacs, this seems to do the trick: (after! lsp-rust
(setq lsp-rust-analyzer-proc-macro-enable t
lsp-rust-analyzer-experimental-proc-attr-macros t)) |
Recent |
Should be fixed or no longer applies - rust-lang/rust-analyzer#5412
I'm in the process of following the Game of Life Rust-WASM tutorial here:
https://rustwasm.github.io/docs/book/game-of-life/hello-world.html
My level of expertise in Rust: Beginner
OS: macOS Catalina 10.15.5
Editor: VSCode 1.47
rust-analyzer: v0.2.240
(rust-analyzer updated just a few minutes ago)
I'm getting this error message when looking at src/lib.rs:
In this code block the second
alert(...)
is highlighted:However the code compiles regardless.
When changing to:
Then I'm getting this warning:
The text was updated successfully, but these errors were encountered: