Skip to content
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

What are the 'rust-analyzer diagnostics'? #6214

Closed
lokegustafsson opened this issue Oct 13, 2020 · 10 comments
Closed

What are the 'rust-analyzer diagnostics'? #6214

lokegustafsson opened this issue Oct 13, 2020 · 10 comments

Comments

@lokegustafsson
Copy link

From the readme:

rust-analyzer.diagnostics.disabled: List of rust-analyzer diagnostics to disable, default: []

I would like to disable the "This operation is unsafe and requires an unsafe block" error diagnostic, since it gives false positives with wasm-bindgen. But I have no idea what to write in that array...

@bjorn3
Copy link
Member

bjorn3 commented Oct 13, 2020

In this case it is missing-unsafe.

@bjorn3
Copy link
Member

bjorn3 commented Oct 13, 2020

What are the false positives by the way? What code gives them?

@lokegustafsson
Copy link
Author

Oh, i managed to post this to the wrong repo. I though i sent it posted it to https://github.com/fannheyward/coc-rust-analyzer ops. It is their readme that i refer to.

@flodiebold
Copy link
Member

We should document our diagnostics (we could probably auto-generate this like we do for assists).

@bjorn3
Copy link
Member

bjorn3 commented Oct 13, 2020

This is the right repo for this kind of configuration questions. It is rust-analyzer that implements them. coc-rust-analyzer just forwards them. You need to put

{
    "rust-analyzer.diagnostics.disabled": ["missing-unsafe"]
}

in $HOME/.config/nvim/coc-settings.json to disable the diagnostic for coc-rust-analyzer.

@flodiebold
Copy link
Member

There's already a bug for the false positives, #5412.

@lokegustafsson
Copy link
Author

lokegustafsson commented Oct 13, 2020

missing-unsafe solves my problem, thank you. Regarding the false positive: wasm-bindgen is all about making declarations along the line of

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(js_namespace = Console)]
    pub fn log(msg: &str);
}

This would make log unsafe as it is an external function, but some wasm-bindgen magic makes them safe. I don't know any details, but the code compiles and can use the function normally. However, rust-analyzer considers the function unsafe.

@lokegustafsson
Copy link
Author

Yes, this is the same false positive. And yes, there should be a list of these diagnostics somewhere

@jplatte
Copy link
Contributor

jplatte commented Oct 23, 2020

Found this: https://github.com/rust-analyzer/rust-analyzer/blob/c483212f274e9a5e348451cd4bbd0487e172458b/docs/user/generated_diagnostic.adoc

Is this also available somewhere on the website? Haven't found an obvious entry in the user manual TOC.

@flodiebold
Copy link
Member

It should be included in the manual with the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants