Merge pull request #1767 from topecongiro/range-with-floating-literal

Add a space before range if lhs ends with dot
This commit is contained in:
Nick Cameron 2017-07-05 15:46:43 +12:00 committed by GitHub
commit 6546aaf5ec
3 changed files with 24 additions and 0 deletions

View file

@ -269,10 +269,26 @@ pub fn format_expr(
ast::RangeLimits::Closed => "...",
};
fn needs_space_before_range(context: &RewriteContext, lhs: &ast::Expr) -> bool {
match lhs.node {
ast::ExprKind::Lit(ref lit) => {
match lit.node {
ast::LitKind::FloatUnsuffixed(..) => {
context.snippet(lit.span).ends_with('.')
}
_ => false,
}
}
_ => false,
}
}
match (lhs.as_ref().map(|x| &**x), rhs.as_ref().map(|x| &**x)) {
(Some(ref lhs), Some(ref rhs)) => {
let sp_delim = if context.config.spaces_around_ranges() {
format!(" {} ", delim)
} else if needs_space_before_range(context, lhs) {
format!(" {}", delim)
} else {
delim.into()
};

View file

@ -251,6 +251,10 @@ fn ranges() {
let y = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ... bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
let z = ... x ;
// #1766
let x = [0. ..10.0];
let x = [0. ...10.0];
a ... b
// the expr below won't compile for some reason...

View file

@ -315,6 +315,10 @@ fn ranges() {
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
let z = ...x;
// #1766
let x = [0. ..10.0];
let x = [0. ...10.0];
a...b
// the expr below won't compile for some reason...