aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2024-05-10 18:32:51 -0700
committerDavid Tolnay <dtolnay@gmail.com>2024-05-10 19:37:47 -0700
commita79428844f350cee8097d7057151af51a2ee45cc (patch)
tree6dd48952f3d8f7bf594a6fb1c1fb4186541a5bad
parent46bc5aa10399b5f7e86bbc24d18e8f6335bce40f (diff)
downloadsyn-a79428844f350cee8097d7057151af51a2ee45cc.tar.gz
Disallow range with upper bound in lhs of binop
-rw-r--r--src/expr.rs6
-rw-r--r--tests/test_expr.rs29
2 files changed, 10 insertions, 25 deletions
diff --git a/src/expr.rs b/src/expr.rs
index ca16fdee..4183ced2 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1391,7 +1391,11 @@ pub(crate) mod parsing {
) -> Result<Expr> {
loop {
let ahead = input.fork();
- if let Ok(op) = ahead.parse::<BinOp>() {
+ if let Expr::Range(ExprRange { end: Some(_), .. }) = lhs {
+ // A range with an upper bound cannot be the left-hand side of
+ // another binary operator.
+ break;
+ } else if let Ok(op) = ahead.parse::<BinOp>() {
let precedence = Precedence::of(&op);
if precedence < base {
break;
diff --git a/tests/test_expr.rs b/tests/test_expr.rs
index 8a7c3a27..13c37b6b 100644
--- a/tests/test_expr.rs
+++ b/tests/test_expr.rs
@@ -379,30 +379,11 @@ fn test_range_precedence() {
}
"###);
- // FIXME: should fail to parse. A range with a lower bound cannot be the
- // upper bound of another range.
- snapshot!(".. () .." as Expr, @r###"
- Expr::Range {
- limits: RangeLimits::HalfOpen,
- end: Some(Expr::Range {
- start: Some(Expr::Tuple),
- limits: RangeLimits::HalfOpen,
- }),
- }
- "###);
-
- // FIXME: should fail to parse. A range with an upper bound cannot be the
- // lower bound of another range.
- snapshot!("() .. () .." as Expr, @r###"
- Expr::Range {
- start: Some(Expr::Range {
- start: Some(Expr::Tuple),
- limits: RangeLimits::HalfOpen,
- end: Some(Expr::Tuple),
- }),
- limits: RangeLimits::HalfOpen,
- }
- "###);
+ // 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.
+ syn::parse_str::<Expr>(".. x ..").unwrap_err();
+ syn::parse_str::<Expr>("x .. x ..").unwrap_err();
}
#[test]