dtolnay / syn

Parser for Rust source code
Apache License 2.0
2.81k stars 308 forks source link

Disallow range with upper bound in lhs of binop #1642

Closed dtolnay closed 4 months ago

dtolnay commented 4 months ago

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