]> git.lizzy.rs Git - rust.git/commitdiff
Add a space before range if lhs ends with dot
authortopecongiro <seuchida@gmail.com>
Tue, 4 Jul 2017 11:21:49 +0000 (20:21 +0900)
committertopecongiro <seuchida@gmail.com>
Tue, 4 Jul 2017 11:23:57 +0000 (20:23 +0900)
src/expr.rs
tests/source/expr.rs
tests/target/expr.rs

index c5f7ccb857b0b99bb7a442a8cf84c53de546f9f6..2b15ff53787bc9c1ee33c325d8838464cd37dace 100644 (file)
@@ -268,10 +268,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()
                     };
index 3d54e68c4093beac1bbc75a0207fc4e76cd27a20..96e00174af88604a429193f20f23142dcde4b2e4 100644 (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...
index 3b275d30f4ced3b7ec6e2a2562ba41ab56549f50..de4391d405608a75494b29d816e73485ff4ce45e 100644 (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...