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

bug: Incorrect parsing of attributes #244

Open
2 tasks done
wetneb opened this issue Nov 14, 2024 · 0 comments · May be fixed by #245
Open
2 tasks done

bug: Incorrect parsing of attributes #244

wetneb opened this issue Nov 14, 2024 · 0 comments · May be fixed by #245
Labels

Comments

@wetneb
Copy link

wetneb commented Nov 14, 2024

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-rust

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

This grammar successfully parses the following code:

mod tests {
    pub fn execute() {}
    #[cfg(feature = "tracing")]
}

This code is incorrect because #[cfg(feature = "tracing")] is an outer attribute, which needs to be followed by the element it is applied to. This is indeed rejected by rustc:

error: expected item after attributes
 --> test.rs:3:5
  |
3 |     #[cfg(feature = "tracing")]
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

A correct version would be:

mod tests {
    #[cfg(feature = "tracing")]
    pub fn execute() {}
}

In this example, we expect the attribute and function declaration to be bundled together, and not treated as two independent children of the module, as is currently the case.

Steps To Reproduce/Bad Parse Tree

See above.

Expected Behavior/Parse Tree

Correctly bundling outer attributes with the syntactic element they apply to.

Repro

mod tests {
    pub fn execute() {}
    #[cfg(feature = "tracing")]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant