Skip to content

Commit

Permalink
Support ..= syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Badel2 committed Sep 27, 2017
1 parent 2f81933 commit 2886000
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/expr.rs
Expand Up @@ -232,7 +232,7 @@ pub fn format_expr(
ast::ExprKind::Range(ref lhs, ref rhs, limits) => {
let delim = match limits {
ast::RangeLimits::HalfOpen => "..",
ast::RangeLimits::Closed => "...",
ast::RangeLimits::Closed => "..=",
};

fn needs_space_before_range(context: &RewriteContext, lhs: &ast::Expr) -> bool {
Expand Down
30 changes: 11 additions & 19 deletions src/patterns.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd};
use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSyntax};
use syntax::codemap::{self, BytePos, Span};
use syntax::ptr;

Expand Down Expand Up @@ -58,31 +58,23 @@ impl Rewrite for Pat {
} else {
None
},
PatKind::Range(ref lhs, ref rhs, ref end_kind) => match *end_kind {
RangeEnd::Excluded => rewrite_pair(
&**lhs,
&**rhs,
"",
"..",
"",
context,
shape,
SeparatorPlace::Front,
),
// FIXME: Change _ to RangeEnd::Included(RangeSyntax::DotDotDot)
// and add RangeEnd::Included(RangeSyntax::DotDotEq)
// once rust PR #44709 gets merged
_ => rewrite_pair(
PatKind::Range(ref lhs, ref rhs, ref end_kind) => {
let infix = match *end_kind {
RangeEnd::Included(RangeSyntax::DotDotDot) => "...",
RangeEnd::Included(RangeSyntax::DotDotEq) => "..=",
RangeEnd::Excluded => "..",
};
rewrite_pair(
&**lhs,
&**rhs,
"",
"...",
infix,
"",
context,
shape,
SeparatorPlace::Front,
),
},
)
}
PatKind::Ref(ref pat, mutability) => {
let prefix = format!("&{}", format_mutability(mutability));
rewrite_unary_prefix(context, &prefix, &**pat, shape)
Expand Down

0 comments on commit 2886000

Please sign in to comment.