Skip to content

Disallow range with upper bound in lhs of binop#1642

Merged
dtolnay merged 2 commits intomasterfrom
rangeprecedence
May 11, 2024
Merged

Disallow range with upper bound in lhs of binop#1642
dtolnay merged 2 commits intomasterfrom
rangeprecedence

Conversation

@dtolnay
Copy link
Copy Markdown
Owner

@dtolnay dtolnay commented May 11, 2024

Previously, syn incorrectly accepted .. $e .. as:

Expr::Range {
    limits: RangeLimits::HalfOpen,
    end: Some(Expr::Range {
        start: Some($e),
        limits: RangeLimits::HalfOpen,
    }),
}

and $e .. $e .. as:

Expr::Range {
    start: Some(Expr::Range {
        start: Some($e),
        limits: RangeLimits::HalfOpen,
        end: Some($e),
    }),
    limits: RangeLimits::HalfOpen,
}

but these are not legal expressions in Rust. A range with a lower bound cannot be the upper bound of another range, and a range with an upper bound cannot be the lower bound of another range.

error: expected one of `.`, `;`, `?`, `else`, or an operator, found `..`
 --> src/main.rs:2:19
  |
2 |     let _ = .. () ..;
  |                   ^^ expected one of `.`, `;`, `?`, `else`, or an operator

error: expected one of `.`, `;`, `?`, `else`, or an operator, found `..`
 --> src/main.rs:3:22
  |
3 |     let _ = () .. () ..;
  |                      ^^ expected one of `.`, `;`, `?`, `else`, or an operator

@dtolnay dtolnay merged commit b1a12f4 into master May 11, 2024
@dtolnay dtolnay deleted the rangeprecedence branch May 11, 2024 02:48
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.

1 participant