Add a space before range if lhs ends with dot

This commit is contained in:
topecongiro 2017-07-04 20:21:49 +09:00
parent 2400f39f98
commit 183e3482e5
3 changed files with 24 additions and 0 deletions

View File

@ -268,10 +268,26 @@ pub fn format_expr(
ast::RangeLimits::Closed => "...", 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)) { match (lhs.as_ref().map(|x| &**x), rhs.as_ref().map(|x| &**x)) {
(Some(ref lhs), Some(ref rhs)) => { (Some(ref lhs), Some(ref rhs)) => {
let sp_delim = if context.config.spaces_around_ranges() { let sp_delim = if context.config.spaces_around_ranges() {
format!(" {} ", delim) format!(" {} ", delim)
} else if needs_space_before_range(context, lhs) {
format!(" {}", delim)
} else { } else {
delim.into() delim.into()
}; };

View File

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

View File

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