Using ...
in expressions is now an error
This commit is contained in:
parent
4bd6be9dc6
commit
3c41c28f48
3 changed files with 21 additions and 16 deletions
|
@ -2784,10 +2784,11 @@ impl<'a> Parser<'a> {
|
||||||
if op.precedence() < min_prec {
|
if op.precedence() < min_prec {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Warn about deprecated ... syntax (until SNAP)
|
// Check for deprecated `...` syntax
|
||||||
if self.token == token::DotDotDot {
|
if self.token == token::DotDotDot && op == AssocOp::DotDotEq {
|
||||||
self.warn_dotdoteq(self.span);
|
self.err_dotdotdot_syntax(self.span);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.bump();
|
self.bump();
|
||||||
if op.is_comparison() {
|
if op.is_comparison() {
|
||||||
self.check_no_chained_comparison(&lhs, &op);
|
self.check_no_chained_comparison(&lhs, &op);
|
||||||
|
@ -2820,7 +2821,6 @@ impl<'a> Parser<'a> {
|
||||||
//
|
//
|
||||||
// We have 2 alternatives here: `x..y`/`x..=y` and `x..`/`x..=` The other
|
// We have 2 alternatives here: `x..y`/`x..=y` and `x..`/`x..=` The other
|
||||||
// two variants are handled with `parse_prefix_range_expr` call above.
|
// two variants are handled with `parse_prefix_range_expr` call above.
|
||||||
// (and `x...y`/`x...` until SNAP)
|
|
||||||
let rhs = if self.is_at_start_of_range_notation_rhs() {
|
let rhs = if self.is_at_start_of_range_notation_rhs() {
|
||||||
Some(self.parse_assoc_expr_with(op.precedence() + 1,
|
Some(self.parse_assoc_expr_with(op.precedence() + 1,
|
||||||
LhsExpr::NotYetParsed)?)
|
LhsExpr::NotYetParsed)?)
|
||||||
|
@ -3008,22 +3008,22 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse prefix-forms of range notation: `..expr`, `..`, `..=expr` (and `...expr` until SNAP)
|
/// Parse prefix-forms of range notation: `..expr`, `..`, `..=expr`
|
||||||
fn parse_prefix_range_expr(&mut self,
|
fn parse_prefix_range_expr(&mut self,
|
||||||
already_parsed_attrs: Option<ThinVec<Attribute>>)
|
already_parsed_attrs: Option<ThinVec<Attribute>>)
|
||||||
-> PResult<'a, P<Expr>> {
|
-> PResult<'a, P<Expr>> {
|
||||||
// SNAP remove DotDotDot
|
// Check for deprecated `...` syntax
|
||||||
|
if self.token == token::DotDotDot {
|
||||||
|
self.err_dotdotdot_syntax(self.span);
|
||||||
|
}
|
||||||
|
|
||||||
debug_assert!([token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token),
|
debug_assert!([token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token),
|
||||||
"parse_prefix_range_expr: token {:?} is not DotDot/DotDotDot/DotDotEq",
|
"parse_prefix_range_expr: token {:?} is not DotDot/DotDotEq",
|
||||||
self.token);
|
self.token);
|
||||||
let tok = self.token.clone();
|
let tok = self.token.clone();
|
||||||
let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?;
|
let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?;
|
||||||
let lo = self.span;
|
let lo = self.span;
|
||||||
let mut hi = self.span;
|
let mut hi = self.span;
|
||||||
// Warn about deprecated ... syntax (until SNAP)
|
|
||||||
if tok == token::DotDotDot {
|
|
||||||
self.warn_dotdoteq(self.span);
|
|
||||||
}
|
|
||||||
self.bump();
|
self.bump();
|
||||||
let opt_end = if self.is_at_start_of_range_notation_rhs() {
|
let opt_end = if self.is_at_start_of_range_notation_rhs() {
|
||||||
// RHS must be parsed with more associativity than the dots.
|
// RHS must be parsed with more associativity than the dots.
|
||||||
|
@ -4271,9 +4271,13 @@ impl<'a> Parser<'a> {
|
||||||
}).emit();
|
}).emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn warn_dotdoteq(&self, span: Span) {
|
fn err_dotdotdot_syntax(&self, span: Span) {
|
||||||
self.diagnostic().struct_span_warn(span, {
|
self.diagnostic().struct_span_err(span, {
|
||||||
"`...` is being replaced by `..=`"
|
"`...` syntax cannot be used in expressions"
|
||||||
|
}).help({
|
||||||
|
"Use `..` if you need an exclusive range (a < b)"
|
||||||
|
}).help({
|
||||||
|
"or `..=` if you need an inclusive range (a <= b)"
|
||||||
}).emit();
|
}).emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,8 +222,8 @@ impl Token {
|
||||||
BinOp(Or) | OrOr | // closure
|
BinOp(Or) | OrOr | // closure
|
||||||
BinOp(And) | // reference
|
BinOp(And) | // reference
|
||||||
AndAnd | // double reference
|
AndAnd | // double reference
|
||||||
|
// DotDotDot is no longer supported, but we need some way to display the error
|
||||||
DotDot | DotDotDot | DotDotEq | // range notation
|
DotDot | DotDotDot | DotDotEq | // range notation
|
||||||
// SNAP remove DotDotDot
|
|
||||||
Lt | BinOp(Shl) | // associated path
|
Lt | BinOp(Shl) | // associated path
|
||||||
ModSep | // global path
|
ModSep | // global path
|
||||||
Pound => true, // expression attributes
|
Pound => true, // expression attributes
|
||||||
|
|
|
@ -106,7 +106,8 @@ impl AssocOp {
|
||||||
Token::OrOr => Some(LOr),
|
Token::OrOr => Some(LOr),
|
||||||
Token::DotDot => Some(DotDot),
|
Token::DotDot => Some(DotDot),
|
||||||
Token::DotDotEq => Some(DotDotEq),
|
Token::DotDotEq => Some(DotDotEq),
|
||||||
Token::DotDotDot => Some(DotDotEq), // remove this after SNAP
|
// DotDotDot is no longer supported, but we need some way to display the error
|
||||||
|
Token::DotDotDot => Some(DotDotEq),
|
||||||
Token::Colon => Some(Colon),
|
Token::Colon => Some(Colon),
|
||||||
_ if t.is_keyword(keywords::As) => Some(As),
|
_ if t.is_keyword(keywords::As) => Some(As),
|
||||||
_ => None
|
_ => None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue