Skip to content

Commit 7aabf57

Browse files
committed
Add information about the syntax used in ranges
... or ..=
1 parent 4737c5a commit 7aabf57

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ impl<'a> LoweringContext<'a> {
18691869

18701870
fn lower_range_end(&mut self, e: &RangeEnd) -> hir::RangeEnd {
18711871
match *e {
1872-
RangeEnd::Included => hir::RangeEnd::Included,
1872+
RangeEnd::Included(_) => hir::RangeEnd::Included,
18731873
RangeEnd::Excluded => hir::RangeEnd::Excluded,
18741874
}
18751875
}

src/libsyntax/ast.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,16 @@ pub enum BindingMode {
538538

539539
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
540540
pub enum RangeEnd {
541-
Included,
541+
Included(RangeSyntax),
542542
Excluded,
543543
}
544544

545+
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
546+
pub enum RangeSyntax {
547+
DotDotDot,
548+
DotDotEq,
549+
}
550+
545551
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
546552
pub enum PatKind {
547553
/// Represents a wildcard pattern (`_`)
@@ -578,7 +584,7 @@ pub enum PatKind {
578584
Ref(P<Pat>, Mutability),
579585
/// A literal
580586
Lit(P<Expr>),
581-
/// A range pattern, e.g. `1...2` or `1..2`
587+
/// A range pattern, e.g. `1...2`, `1..=2` or `1..2`
582588
Range(P<Expr>, P<Expr>, RangeEnd),
583589
/// `[a, b, ..i, y, z]` is represented as:
584590
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`

src/libsyntax/parse/parser.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds};
3838
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
3939
use ast::{Visibility, WhereClause};
4040
use ast::{BinOpKind, UnOp};
41-
use ast::RangeEnd;
41+
use ast::{RangeEnd, RangeSyntax};
4242
use {ast, attr};
4343
use codemap::{self, CodeMap, Spanned, respan};
4444
use syntax_pos::{self, Span, BytePos};
@@ -3557,7 +3557,8 @@ impl<'a> Parser<'a> {
35573557
token::DotDotDot | token::DotDotEq | token::DotDot => {
35583558
let end_kind = match self.token {
35593559
token::DotDot => RangeEnd::Excluded,
3560-
token::DotDotDot | token::DotDotEq => RangeEnd::Included,
3560+
token::DotDotDot => RangeEnd::Included(RangeSyntax::DotDotDot),
3561+
token::DotDotEq => RangeEnd::Included(RangeSyntax::DotDotEq),
35613562
_ => panic!("can only parse `..`/`...`/`..=` for ranges \
35623563
(checked above)"),
35633564
};
@@ -3600,10 +3601,12 @@ impl<'a> Parser<'a> {
36003601
Ok(begin) => {
36013602
if self.eat(&token::DotDotDot) {
36023603
let end = self.parse_pat_range_end()?;
3603-
pat = PatKind::Range(begin, end, RangeEnd::Included);
3604+
pat = PatKind::Range(begin, end,
3605+
RangeEnd::Included(RangeSyntax::DotDotDot));
36043606
} else if self.eat(&token::DotDotEq) {
36053607
let end = self.parse_pat_range_end()?;
3606-
pat = PatKind::Range(begin, end, RangeEnd::Included);
3608+
pat = PatKind::Range(begin, end,
3609+
RangeEnd::Included(RangeSyntax::DotDotEq));
36073610
} else if self.eat(&token::DotDot) {
36083611
let end = self.parse_pat_range_end()?;
36093612
pat = PatKind::Range(begin, end, RangeEnd::Excluded);

src/libsyntax/print/pprust.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
pub use self::AnnNode::*;
1212

1313
use abi::{self, Abi};
14-
use ast::{self, BlockCheckMode, PatKind, RangeEnd};
14+
use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
1515
use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
1616
use ast::Attribute;
1717
use util::parser::{self, AssocOp, Fixity};
@@ -2590,7 +2590,8 @@ impl<'a> State<'a> {
25902590
self.print_expr(begin)?;
25912591
self.s.space()?;
25922592
match *end_kind {
2593-
RangeEnd::Included => self.s.word("...")?,
2593+
RangeEnd::Included(RangeSyntax::DotDotDot) => self.s.word("...")?,
2594+
RangeEnd::Included(RangeSyntax::DotDotEq) => self.s.word("..=")?,
25942595
RangeEnd::Excluded => self.s.word("..")?,
25952596
}
25962597
self.print_expr(end)?;

0 commit comments

Comments
 (0)