error during parsing for malformed inclusive range
Now it is impossible for `...` or `a...` to reach HIR lowering without a rogue syntax extension in play.
This commit is contained in:
parent
9799cacba3
commit
9f899a6659
2 changed files with 41 additions and 30 deletions
|
@ -2072,8 +2072,15 @@ impl<'a> Parser<'a> {
|
||||||
start: Option<P<Expr>>,
|
start: Option<P<Expr>>,
|
||||||
end: Option<P<Expr>>,
|
end: Option<P<Expr>>,
|
||||||
limits: RangeLimits)
|
limits: RangeLimits)
|
||||||
-> ast::ExprKind {
|
-> PResult<'a, ast::ExprKind> {
|
||||||
ExprKind::Range(start, end, limits)
|
if end.is_none() && limits == RangeLimits::Closed {
|
||||||
|
Err(self.span_fatal_help(self.span,
|
||||||
|
"inclusive range with no end",
|
||||||
|
"currently, inclusive ranges must be bounded at the end \
|
||||||
|
(`...b` or `a...b`) -- see tracking issue #28237"))
|
||||||
|
} else {
|
||||||
|
Ok(ExprKind::Range(start, end, limits))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_field(&mut self, expr: P<Expr>, ident: ast::SpannedIdent) -> ast::ExprKind {
|
pub fn mk_field(&mut self, expr: P<Expr>, ident: ast::SpannedIdent) -> ast::ExprKind {
|
||||||
|
@ -2961,12 +2968,12 @@ impl<'a> Parser<'a> {
|
||||||
lhs = self.mk_expr(lhs_span.lo, rhs.span.hi,
|
lhs = self.mk_expr(lhs_span.lo, rhs.span.hi,
|
||||||
ExprKind::Type(lhs, rhs), None);
|
ExprKind::Type(lhs, rhs), None);
|
||||||
continue
|
continue
|
||||||
} else if op == AssocOp::DotDot {
|
} else if op == AssocOp::DotDot || op == AssocOp::DotDotDot {
|
||||||
// If we didn’t have to handle `x..`, it would be pretty easy to generalise
|
// If we didn’t have to handle `x..`/`x...`, it would be pretty easy to
|
||||||
// it to the Fixity::None code.
|
// generalise it to the Fixity::None code.
|
||||||
//
|
//
|
||||||
// We have 2 alternatives here: `x..y` and `x..` The other two variants are
|
// We have 2 alternatives here: `x..y`/`x...y` and `x..`/`x...` The other
|
||||||
// handled with `parse_prefix_range_expr` call above.
|
// two variants are handled with `parse_prefix_range_expr` call above.
|
||||||
let rhs = if self.is_at_start_of_range_notation_rhs() {
|
let rhs = if self.is_at_start_of_range_notation_rhs() {
|
||||||
let rhs = self.parse_assoc_expr_with(op.precedence() + 1,
|
let rhs = self.parse_assoc_expr_with(op.precedence() + 1,
|
||||||
LhsExpr::NotYetParsed);
|
LhsExpr::NotYetParsed);
|
||||||
|
@ -2985,7 +2992,13 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
cur_op_span
|
cur_op_span
|
||||||
});
|
});
|
||||||
let r = self.mk_range(Some(lhs), rhs, RangeLimits::HalfOpen);
|
let limits = if op == AssocOp::DotDot {
|
||||||
|
RangeLimits::HalfOpen
|
||||||
|
} else {
|
||||||
|
RangeLimits::Closed
|
||||||
|
};
|
||||||
|
|
||||||
|
let r = try!(self.mk_range(Some(lhs), rhs, limits));
|
||||||
lhs = self.mk_expr(lhs_span.lo, rhs_span.hi, r, None);
|
lhs = self.mk_expr(lhs_span.lo, rhs_span.hi, r, None);
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -3003,8 +3016,7 @@ impl<'a> Parser<'a> {
|
||||||
this.parse_assoc_expr_with(op.precedence() + 1,
|
this.parse_assoc_expr_with(op.precedence() + 1,
|
||||||
LhsExpr::NotYetParsed)
|
LhsExpr::NotYetParsed)
|
||||||
}),
|
}),
|
||||||
// the only operator handled here is `...` (the other non-associative operators are
|
// no operators are currently handled here
|
||||||
// special-cased above)
|
|
||||||
Fixity::None => self.with_res(
|
Fixity::None => self.with_res(
|
||||||
restrictions - Restrictions::RESTRICTION_STMT_EXPR,
|
restrictions - Restrictions::RESTRICTION_STMT_EXPR,
|
||||||
|this| {
|
|this| {
|
||||||
|
@ -3045,13 +3057,8 @@ impl<'a> Parser<'a> {
|
||||||
let aopexpr = self.mk_assign_op(codemap::respan(cur_op_span, aop), lhs, rhs);
|
let aopexpr = self.mk_assign_op(codemap::respan(cur_op_span, aop), lhs, rhs);
|
||||||
self.mk_expr(lhs_span.lo, rhs_span.hi, aopexpr, None)
|
self.mk_expr(lhs_span.lo, rhs_span.hi, aopexpr, None)
|
||||||
}
|
}
|
||||||
AssocOp::DotDotDot => {
|
AssocOp::As | AssocOp::Colon | AssocOp::DotDot | AssocOp::DotDotDot => {
|
||||||
let (lhs_span, rhs_span) = (lhs.span, rhs.span);
|
self.bug("As, Colon, DotDot or DotDotDot branch reached")
|
||||||
let r = self.mk_range(Some(lhs), Some(rhs), RangeLimits::Closed);
|
|
||||||
self.mk_expr(lhs_span.lo, rhs_span.hi, r, None)
|
|
||||||
}
|
|
||||||
AssocOp::As | AssocOp::Colon | AssocOp::DotDot => {
|
|
||||||
self.bug("As, Colon or DotDot branch reached")
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3103,13 +3110,15 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let r = self.mk_range(None,
|
let limits = if tok == token::DotDot {
|
||||||
opt_end,
|
|
||||||
if tok == token::DotDot {
|
|
||||||
RangeLimits::HalfOpen
|
RangeLimits::HalfOpen
|
||||||
} else {
|
} else {
|
||||||
RangeLimits::Closed
|
RangeLimits::Closed
|
||||||
});
|
};
|
||||||
|
|
||||||
|
let r = try!(self.mk_range(None,
|
||||||
|
opt_end,
|
||||||
|
limits));
|
||||||
Ok(self.mk_expr(lo, hi, r, attrs))
|
Ok(self.mk_expr(lo, hi, r, attrs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,9 @@ pub fn main() {
|
||||||
0..1;
|
0..1;
|
||||||
|
|
||||||
...; //~ERROR inclusive range with no end
|
...; //~ERROR inclusive range with no end
|
||||||
0...; //~ERROR unexpected token
|
//~^HELP 28237
|
||||||
|
0...; //~ERROR inclusive range with no end
|
||||||
|
//~^HELP 28237
|
||||||
...1;
|
...1;
|
||||||
0...1;
|
0...1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue