mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 03:03:40 +00:00
Add a space before range if lhs ends with dot
This commit is contained in:
parent
2400f39f98
commit
183e3482e5
16
src/expr.rs
16
src/expr.rs
@ -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()
|
||||||
};
|
};
|
||||||
|
@ -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 New Issue
Block a user