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

r-a fails to parse as u8<< expression within macro #19076

Open
dzamlo opened this issue Jan 31, 2025 · 1 comment
Open

r-a fails to parse as u8<< expression within macro #19076

dzamlo opened this issue Jan 31, 2025 · 1 comment
Labels
C-bug Category: bug

Comments

@dzamlo
Copy link

dzamlo commented Jan 31, 2025

rust-analyzer version:
rust-analyzer version: 0.3.2237-standalone and rust-analyzer 0.3.2284-standalone

rustc version:
rustc 1.85.0-nightly (7f75bfa1a 2024-12-30)

editor or extension:
Both VSCode and Neovim

repository link (if public, optional):
https://github.com/dzamlo/rust-bitfield/

When calling my macro bitfield, as shown in the code snippet below, I get a "generic arguments are not allowed on builtin types" error from rust-analyzer.

But the code compile without any error or warnings.

If I copy the generated code as outputted by cargo expand in my editor, I don't get the error.

code snippet to reproduce:

use bitfield::bitfield;
bitfield! {
    struct Foo([u8]);
}

If the type in parentheses is a simple type, like u8 and not a slice like type, there is no error. A slice like type in parentheses is handled differently by the macro

You can also check the examples in the "examples" folder of the repo.

@dzamlo dzamlo added the C-bug Category: bug label Jan 31, 2025
@ChayimFriedman2
Copy link
Contributor

ChayimFriedman2 commented Jan 31, 2025

From first look, I believe this is #18211. Note there is another syntax error.

Edit: To clarify, the parse error is the problem. rust-analyzer mis-parses the expression (value&1)as u8<<(i%bit_len) (which is indeed unparseable) as a generic argument to u8. I suspect the reason for this parsing error is that we don't handle none groups correctly.

@ChayimFriedman2 ChayimFriedman2 changed the title "generic arguments are not allowed on builtin types" error where there should be no error r-a fails to parse as u8<< expression within macri Jan 31, 2025
@ChayimFriedman2 ChayimFriedman2 changed the title r-a fails to parse as u8<< expression within macri r-a fails to parse as u8<< expression within macro Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants