Skip to content

Commit d645c28

Browse files
committed
---
yaml --- r: 273718 b: refs/heads/beta c: 9f899a6 h: refs/heads/master
1 parent 73d5ca3 commit d645c28

File tree

3 files changed

+42
-31
lines changed

3 files changed

+42
-31
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 9799cacba3042420cc7b49d555289241cf0456e1
26+
refs/heads/beta: 9f899a66591c1a4bc68b51fc6d1f207d2d49a087
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/libsyntax/parse/parser.rs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,8 +2072,15 @@ impl<'a> Parser<'a> {
20722072
start: Option<P<Expr>>,
20732073
end: Option<P<Expr>>,
20742074
limits: RangeLimits)
2075-
-> ast::ExprKind {
2076-
ExprKind::Range(start, end, limits)
2075+
-> PResult<'a, ast::ExprKind> {
2076+
if end.is_none() && limits == RangeLimits::Closed {
2077+
Err(self.span_fatal_help(self.span,
2078+
"inclusive range with no end",
2079+
"currently, inclusive ranges must be bounded at the end \
2080+
(`...b` or `a...b`) -- see tracking issue #28237"))
2081+
} else {
2082+
Ok(ExprKind::Range(start, end, limits))
2083+
}
20772084
}
20782085

20792086
pub fn mk_field(&mut self, expr: P<Expr>, ident: ast::SpannedIdent) -> ast::ExprKind {
@@ -2961,12 +2968,12 @@ impl<'a> Parser<'a> {
29612968
lhs = self.mk_expr(lhs_span.lo, rhs.span.hi,
29622969
ExprKind::Type(lhs, rhs), None);
29632970
continue
2964-
} else if op == AssocOp::DotDot {
2965-
// If we didn’t have to handle `x..`, it would be pretty easy to generalise
2966-
// it to the Fixity::None code.
2971+
} else if op == AssocOp::DotDot || op == AssocOp::DotDotDot {
2972+
// If we didn’t have to handle `x..`/`x...`, it would be pretty easy to
2973+
// generalise it to the Fixity::None code.
29672974
//
2968-
// We have 2 alternatives here: `x..y` and `x..` The other two variants are
2969-
// handled with `parse_prefix_range_expr` call above.
2975+
// We have 2 alternatives here: `x..y`/`x...y` and `x..`/`x...` The other
2976+
// two variants are handled with `parse_prefix_range_expr` call above.
29702977
let rhs = if self.is_at_start_of_range_notation_rhs() {
29712978
let rhs = self.parse_assoc_expr_with(op.precedence() + 1,
29722979
LhsExpr::NotYetParsed);
@@ -2985,7 +2992,13 @@ impl<'a> Parser<'a> {
29852992
} else {
29862993
cur_op_span
29872994
});
2988-
let r = self.mk_range(Some(lhs), rhs, RangeLimits::HalfOpen);
2995+
let limits = if op == AssocOp::DotDot {
2996+
RangeLimits::HalfOpen
2997+
} else {
2998+
RangeLimits::Closed
2999+
};
3000+
3001+
let r = try!(self.mk_range(Some(lhs), rhs, limits));
29893002
lhs = self.mk_expr(lhs_span.lo, rhs_span.hi, r, None);
29903003
break
29913004
}
@@ -3003,8 +3016,7 @@ impl<'a> Parser<'a> {
30033016
this.parse_assoc_expr_with(op.precedence() + 1,
30043017
LhsExpr::NotYetParsed)
30053018
}),
3006-
// the only operator handled here is `...` (the other non-associative operators are
3007-
// special-cased above)
3019+
// no operators are currently handled here
30083020
Fixity::None => self.with_res(
30093021
restrictions - Restrictions::RESTRICTION_STMT_EXPR,
30103022
|this| {
@@ -3045,13 +3057,8 @@ impl<'a> Parser<'a> {
30453057
let aopexpr = self.mk_assign_op(codemap::respan(cur_op_span, aop), lhs, rhs);
30463058
self.mk_expr(lhs_span.lo, rhs_span.hi, aopexpr, None)
30473059
}
3048-
AssocOp::DotDotDot => {
3049-
let (lhs_span, rhs_span) = (lhs.span, rhs.span);
3050-
let r = self.mk_range(Some(lhs), Some(rhs), RangeLimits::Closed);
3051-
self.mk_expr(lhs_span.lo, rhs_span.hi, r, None)
3052-
}
3053-
AssocOp::As | AssocOp::Colon | AssocOp::DotDot => {
3054-
self.bug("As, Colon or DotDot branch reached")
3060+
AssocOp::As | AssocOp::Colon | AssocOp::DotDot | AssocOp::DotDotDot => {
3061+
self.bug("As, Colon, DotDot or DotDotDot branch reached")
30553062
}
30563063
};
30573064

@@ -3095,21 +3102,23 @@ impl<'a> Parser<'a> {
30953102
// RHS must be parsed with more associativity than the dots.
30963103
let next_prec = AssocOp::from_token(&tok).unwrap().precedence() + 1;
30973104
Some(self.parse_assoc_expr_with(next_prec,
3098-
LhsExpr::NotYetParsed)
3099-
.map(|x|{
3100-
hi = x.span.hi;
3101-
x
3102-
})?)
3105+
LhsExpr::NotYetParsed)
3106+
.map(|x|{
3107+
hi = x.span.hi;
3108+
x
3109+
})?)
31033110
} else {
31043111
None
31053112
};
3106-
let r = self.mk_range(None,
3107-
opt_end,
3108-
if tok == token::DotDot {
3109-
RangeLimits::HalfOpen
3110-
} else {
3111-
RangeLimits::Closed
3112-
});
3113+
let limits = if tok == token::DotDot {
3114+
RangeLimits::HalfOpen
3115+
} else {
3116+
RangeLimits::Closed
3117+
};
3118+
3119+
let r = try!(self.mk_range(None,
3120+
opt_end,
3121+
limits));
31133122
Ok(self.mk_expr(lo, hi, r, attrs))
31143123
}
31153124

branches/beta/src/test/compile-fail/impossible_range.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub fn main() {
1919
0..1;
2020

2121
...; //~ERROR inclusive range with no end
22-
0...; //~ERROR unexpected token
22+
//~^HELP 28237
23+
0...; //~ERROR inclusive range with no end
24+
//~^HELP 28237
2325
...1;
2426
0...1;
2527
}

0 commit comments

Comments
 (0)