Skip to content

Commit 3c41c28

Browse files
committed
Using ... in expressions is now an error
1 parent 4bd6be9 commit 3c41c28

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

src/libsyntax/parse/parser.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -2784,10 +2784,11 @@ impl<'a> Parser<'a> {
27842784
if op.precedence() < min_prec {
27852785
break;
27862786
}
2787-
// Warn about deprecated ... syntax (until SNAP)
2788-
if self.token == token::DotDotDot {
2789-
self.warn_dotdoteq(self.span);
2787+
// Check for deprecated `...` syntax
2788+
if self.token == token::DotDotDot && op == AssocOp::DotDotEq {
2789+
self.err_dotdotdot_syntax(self.span);
27902790
}
2791+
27912792
self.bump();
27922793
if op.is_comparison() {
27932794
self.check_no_chained_comparison(&lhs, &op);
@@ -2820,7 +2821,6 @@ impl<'a> Parser<'a> {
28202821
//
28212822
// We have 2 alternatives here: `x..y`/`x..=y` and `x..`/`x..=` The other
28222823
// two variants are handled with `parse_prefix_range_expr` call above.
2823-
// (and `x...y`/`x...` until SNAP)
28242824
let rhs = if self.is_at_start_of_range_notation_rhs() {
28252825
Some(self.parse_assoc_expr_with(op.precedence() + 1,
28262826
LhsExpr::NotYetParsed)?)
@@ -3008,22 +3008,22 @@ impl<'a> Parser<'a> {
30083008
}
30093009
}
30103010

3011-
/// Parse prefix-forms of range notation: `..expr`, `..`, `..=expr` (and `...expr` until SNAP)
3011+
/// Parse prefix-forms of range notation: `..expr`, `..`, `..=expr`
30123012
fn parse_prefix_range_expr(&mut self,
30133013
already_parsed_attrs: Option<ThinVec<Attribute>>)
30143014
-> PResult<'a, P<Expr>> {
3015-
// SNAP remove DotDotDot
3015+
// Check for deprecated `...` syntax
3016+
if self.token == token::DotDotDot {
3017+
self.err_dotdotdot_syntax(self.span);
3018+
}
3019+
30163020
debug_assert!([token::DotDot, token::DotDotDot, token::DotDotEq].contains(&self.token),
3017-
"parse_prefix_range_expr: token {:?} is not DotDot/DotDotDot/DotDotEq",
3021+
"parse_prefix_range_expr: token {:?} is not DotDot/DotDotEq",
30183022
self.token);
30193023
let tok = self.token.clone();
30203024
let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?;
30213025
let lo = self.span;
30223026
let mut hi = self.span;
3023-
// Warn about deprecated ... syntax (until SNAP)
3024-
if tok == token::DotDotDot {
3025-
self.warn_dotdoteq(self.span);
3026-
}
30273027
self.bump();
30283028
let opt_end = if self.is_at_start_of_range_notation_rhs() {
30293029
// RHS must be parsed with more associativity than the dots.
@@ -4271,9 +4271,13 @@ impl<'a> Parser<'a> {
42714271
}).emit();
42724272
}
42734273

4274-
fn warn_dotdoteq(&self, span: Span) {
4275-
self.diagnostic().struct_span_warn(span, {
4276-
"`...` is being replaced by `..=`"
4274+
fn err_dotdotdot_syntax(&self, span: Span) {
4275+
self.diagnostic().struct_span_err(span, {
4276+
"`...` syntax cannot be used in expressions"
4277+
}).help({
4278+
"Use `..` if you need an exclusive range (a < b)"
4279+
}).help({
4280+
"or `..=` if you need an inclusive range (a <= b)"
42774281
}).emit();
42784282
}
42794283

src/libsyntax/parse/token.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ impl Token {
222222
BinOp(Or) | OrOr | // closure
223223
BinOp(And) | // reference
224224
AndAnd | // double reference
225+
// DotDotDot is no longer supported, but we need some way to display the error
225226
DotDot | DotDotDot | DotDotEq | // range notation
226-
// SNAP remove DotDotDot
227227
Lt | BinOp(Shl) | // associated path
228228
ModSep | // global path
229229
Pound => true, // expression attributes

src/libsyntax/util/parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ impl AssocOp {
106106
Token::OrOr => Some(LOr),
107107
Token::DotDot => Some(DotDot),
108108
Token::DotDotEq => Some(DotDotEq),
109-
Token::DotDotDot => Some(DotDotEq), // remove this after SNAP
109+
// DotDotDot is no longer supported, but we need some way to display the error
110+
Token::DotDotDot => Some(DotDotEq),
110111
Token::Colon => Some(Colon),
111112
_ if t.is_keyword(keywords::As) => Some(As),
112113
_ => None

0 commit comments

Comments
 (0)