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

Fix parsing of ranges after unary operators #134900

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Dec 29, 2024

Fixes #134899.

This PR aligns the parsing for unary ! and - and * with how unary & is already parsed here.

--- stderr -------------------------------
error: expected expression, found `..`
  --> tests/ui/parser/ranges-precedence.rs:75:12
   |
LL |         ($e:expr) => {};
   |          ------- while parsing argument for this `expr` macro fragment
LL |     }
LL |     expr!(!..0);
   |            ^^ expected expression

error: expected expression, found `..`
  --> tests/ui/parser/ranges-precedence.rs:76:12
   |
LL |         ($e:expr) => {};
   |          ------- while parsing argument for this `expr` macro fragment
...
LL |     expr!(-..0);
   |            ^^ expected expression

error: expected expression, found `..`
  --> tests/ui/parser/ranges-precedence.rs:77:12
   |
LL |         ($e:expr) => {};
   |          ------- while parsing argument for this `expr` macro fragment
...
LL |     expr!(*..0);
   |            ^^ expected expression

error: aborting due to 3 previous errors
------------------------------------------
@rustbot
Copy link
Collaborator

rustbot commented Dec 29, 2024

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 29, 2024
@dtolnay dtolnay added the A-parser Area: The parsing of Rust source code to an AST label Dec 29, 2024
@jieyouxu
Copy link
Member

r? parser (this is likely accepting new code or re-accepting code that regressed a while ago)

@rustbot rustbot assigned davidtwco and unassigned lcnr Dec 30, 2024
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks fine and this does align with the approach that the & operator takes. Funny enough that was implemented in #105701, and it never went through an FCP even though it was tagged as such, and obviously changes the set of parsed expressions in a way that makes new guarantees to the grammar (at least effectively? not certain if the grammar in the reference suggests that should be parsed, and I don't really want to look).

I think this is both clearly a T-lang signoff but also trivial and desirable to make, so r=me after that is approved. They also should perhaps retroactively be aware that we began to allow &.. too in 1.68.

@compiler-errors compiler-errors added T-lang Relevant to the language team, which will review and decide on the PR/issue. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST I-lang-easy-decision Issue: The decision needed by the team is conjectured to be easy; this does not imply nomination I-lang-nominated Nominated for discussion during a lang team meeting. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unary operator applied to range fails to parse
6 participants