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

bilge generates false positive errors in rust_analyzer #92

Open
denniskempin opened this issue Jul 5, 2024 · 4 comments
Open

bilge generates false positive errors in rust_analyzer #92

denniskempin opened this issue Jul 5, 2024 · 4 comments

Comments

@denniskempin
Copy link

In a dead simple example:

use bilge::prelude::*;

#[bitsize(8)]
#[derive(FromBits)]
struct Test {
    a: u4,
    b: u4,
}

The latest version (0.3.2020) of rust_analyzer reports:

❯ rust-analyzer diagnostics .
processing crate: foo, module: /Users/denniskempin/workspace/test/foo/src/main.rs
Diagnostic { code: Ra("macro-error", Error), message: "add #[bitsize] attribute above your derive attribute", range: FileRange { file_id: FileId(11), range: 24..37 }, severity: Error, unused: false, experimental: false, fixes: None, main_node: None }

i.e.

add #[bitsize] attribute above your derive attribute from this piece of code

Oddly enough, the same error does not appear with cargo check.

@hecatia-elegua
Copy link
Owner

They might have done something to the ordering of macro execution.
I thought there is a silent agreement about that, but if not... well... it still works on the normal compiler.
Is it always happening? If yes, I would have to ask the ra devs somewhere

@showier-drastic
Copy link

Just met the same problem. Reproducible with very simple projects.

@showier-drastic
Copy link

FYI RA devs replied.

@alexkl-rugged-controls
Copy link

alexkl-rugged-controls commented Nov 22, 2024

It looks like rust-analyzer re-evaluates derive macros once for every macro defined below it, and after the non-derive macro is evaluated, it is removed. More info here: rust-lang/rust-analyzer#17873 (comment)

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