Skip to content

Commit 2886000

Browse files
committed
Support ..= syntax
1 parent 2f81933 commit 2886000

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub fn format_expr(
232232
ast::ExprKind::Range(ref lhs, ref rhs, limits) => {
233233
let delim = match limits {
234234
ast::RangeLimits::HalfOpen => "..",
235-
ast::RangeLimits::Closed => "...",
235+
ast::RangeLimits::Closed => "..=",
236236
};
237237

238238
fn needs_space_before_range(context: &RewriteContext, lhs: &ast::Expr) -> bool {

src/patterns.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd};
11+
use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSyntax};
1212
use syntax::codemap::{self, BytePos, Span};
1313
use syntax::ptr;
1414

@@ -58,31 +58,23 @@ impl Rewrite for Pat {
5858
} else {
5959
None
6060
},
61-
PatKind::Range(ref lhs, ref rhs, ref end_kind) => match *end_kind {
62-
RangeEnd::Excluded => rewrite_pair(
63-
&**lhs,
64-
&**rhs,
65-
"",
66-
"..",
67-
"",
68-
context,
69-
shape,
70-
SeparatorPlace::Front,
71-
),
72-
// FIXME: Change _ to RangeEnd::Included(RangeSyntax::DotDotDot)
73-
// and add RangeEnd::Included(RangeSyntax::DotDotEq)
74-
// once rust PR #44709 gets merged
75-
_ => rewrite_pair(
61+
PatKind::Range(ref lhs, ref rhs, ref end_kind) => {
62+
let infix = match *end_kind {
63+
RangeEnd::Included(RangeSyntax::DotDotDot) => "...",
64+
RangeEnd::Included(RangeSyntax::DotDotEq) => "..=",
65+
RangeEnd::Excluded => "..",
66+
};
67+
rewrite_pair(
7668
&**lhs,
7769
&**rhs,
7870
"",
79-
"...",
71+
infix,
8072
"",
8173
context,
8274
shape,
8375
SeparatorPlace::Front,
84-
),
85-
},
76+
)
77+
}
8678
PatKind::Ref(ref pat, mutability) => {
8779
let prefix = format!("&{}", format_mutability(mutability));
8880
rewrite_unary_prefix(context, &prefix, &**pat, shape)

0 commit comments

Comments
 (0)