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

Disallow range with upper bound in lhs of binop #1642

Merged
merged 2 commits into from May 11, 2024
Merged

Conversation

dtolnay
Copy link
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
29 checks passed
@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.

None yet

1 participant