Skip to content

fix: false positive E0109 for shift operators - #21119

Closed
Aditya-PS-05 wants to merge 3 commits into
rust-lang:masterfrom
Aditya-PS-05:fix/shift-operator-after-type
Closed

Aditya-PS-05 wants to merge 3 commits into
rust-lang:masterfrom
Aditya-PS-05:fix/shift-operator-after-type

Conversation

@Aditya-PS-05

@Aditya-PS-05 Aditya-PS-05 commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

closes #20958
also fixes #3861

Earlier when a type parameter in a macro is followed by the << shift operator, rust-analyzer incorrectly treats it as the start of generic arguments, triggering a false positive E0109 error.

Cause

In opt_path_type_args(), the parser checks if < starts a generic argument list but it incorrectly parses shift operators as generic args and also incorrectly treats nested generics.

Fix

Added a look ahead check to examine the token after <<:

  • A type/path start token (ident, Self, super, crate, self) → it treats them as nested generics
  • Otherwise (e.g., literals, expressions) → it treat them as shift operator

I fixed the broken test_issue_3861 and added a new test also.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 24, 2025
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

No no no. The error is not in the parser, and the fix need not be in the parser, definitely not such workaround.

The error is in macro expansion, where we handle transparent groups incorrectly.

@Aditya-PS-05

Aditya-PS-05 commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

No no no. The error is not in the parser, and the fix need not be in the parser, definitely not such workaround.

The error is in macro expansion, where we handle transparent groups incorrectly.

Sir, I think this issue is not in the macro expansion, as in both rustc and rust-analyzer, macro expands to 1 as u8 << 2 from 1 as $t << 2 and then parser thinks << is generic args and works differently.

Can I get more inputs and exact location where you think the Macro expansion error is happening?

@Aditya-PS-05

Copy link
Copy Markdown
Contributor Author

@ChayimFriedman2 please review it.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

I don't think ty fragments are unique in the way they capture, and we definitely shouldn't have a very hacky special delimiters for them.

This is not an issue that can be just solved. It is a fundamental problem with our macro expander (rustc works a bit differently), and will require design work before trying to solve it. The likely solution will be to rewrite the entirety of our expander to match rustc.

@rustbot

rustbot commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #21804) made this pull request unmergeable. Please resolve the merge conflicts.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Closing since this is not fixing the real problem, as I explained above.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 22, 2026
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

Successfully merging this pull request may close these issues.

False positive E0109 due to incorrect operator precedence in macro expansion "The parser seems stuck" on recent versions of ra

3 participants