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:
commit
6546aaf5ec
3 changed files with 24 additions and 0 deletions
16
src/expr.rs
16
src/expr.rs
|
@ -269,10 +269,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()
|
||||||
};
|
};
|
||||||
|
|
|
@ -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...
|
||||||
|
|
|
@ -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...
|
||||||
|
|
Loading…
Reference in a new issue