Rollup merge of #134900 - dtolnay:unoprange, r=compiler-errors,davidtwco

Fix parsing of ranges after unary operators

Fixes https://github.com/rust-lang/rust/issues/134899.

This PR aligns the parsing for unary `!` and `-` and `*` with how unary `&` is already parsed [here](5c0a6e68cf/compiler/rustc_parse/src/parser/expr.rs (L848-L854)).
This commit is contained in:
Matthias Krüger 2025-03-03 10:40:57 +01:00 committed by GitHub
commit 9aff9c070a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 2 deletions

View file

@ -567,7 +567,11 @@ impl<'a> Parser<'a> {
fn parse_expr_prefix_common(&mut self, lo: Span) -> PResult<'a, (Span, P<Expr>)> {
self.bump();
let attrs = self.parse_outer_attributes()?;
let expr = self.parse_expr_prefix(attrs)?;
let expr = if self.token.is_range_separator() {
self.parse_expr_prefix_range(attrs)
} else {
self.parse_expr_prefix(attrs)
}?;
let span = self.interpolated_or_expr_span(&expr);
Ok((lo.to(span), expr))
}