]> git.lizzy.rs Git - rust.git/commitdiff
rustfmt part of libcore/fmt
authorMichael Pankov <work@michaelpankov.com>
Wed, 7 Oct 2015 22:01:02 +0000 (01:01 +0300)
committerMichael Pankov <work@michaelpankov.com>
Wed, 7 Oct 2015 22:02:45 +0000 (01:02 +0300)
Rest is blocked by https://github.com/nrc/rustfmt/issues/413

src/libcore/fmt/builders.rs
src/libcore/fmt/num.rs
src/libcore/fmt/rt/v1.rs

index 764d12dd9033435b0ddf9619731be5e73bff01a8..0d4c0bb6480086c34a71e37ed13c45458cf26e1e 100644 (file)
@@ -61,7 +61,8 @@ pub struct DebugStruct<'a, 'b: 'a> {
     has_fields: bool,
 }
 
-pub fn debug_struct_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>, name: &str)
+pub fn debug_struct_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>,
+                                name: &str)
                                 -> DebugStruct<'a, 'b> {
     let result = fmt.write_str(name);
     DebugStruct {
@@ -84,7 +85,8 @@ pub fn field(&mut self, name: &str, value: &fmt::Debug) -> &mut DebugStruct<'a,
 
             if self.is_pretty() {
                 let mut writer = PadAdapter::new(self.fmt);
-                fmt::write(&mut writer, format_args!("{}\n{}: {:#?}", prefix, name, value))
+                fmt::write(&mut writer,
+                           format_args!("{}\n{}: {:#?}", prefix, name, value))
             } else {
                 write!(self.fmt, "{} {}: {:?}", prefix, name, value)
             }
@@ -195,10 +197,18 @@ fn entry(&mut self, entry: &fmt::Debug) {
         self.result = self.result.and_then(|_| {
             if self.is_pretty() {
                 let mut writer = PadAdapter::new(self.fmt);
-                let prefix = if self.has_fields { "," } else { "" };
+                let prefix = if self.has_fields {
+                    ","
+                } else {
+                    ""
+                };
                 fmt::write(&mut writer, format_args!("{}\n{:#?}", prefix, entry))
             } else {
-                let prefix = if self.has_fields { ", " } else { "" };
+                let prefix = if self.has_fields {
+                    ", "
+                } else {
+                    ""
+                };
                 write!(self.fmt, "{}{:?}", prefix, entry)
             }
         });
@@ -207,7 +217,11 @@ fn entry(&mut self, entry: &fmt::Debug) {
     }
 
     pub fn finish(&mut self) {
-        let prefix = if self.is_pretty() && self.has_fields { "\n" } else { "" };
+        let prefix = if self.is_pretty() && self.has_fields {
+            "\n"
+        } else {
+            ""
+        };
         self.result = self.result.and_then(|_| self.fmt.write_str(prefix));
     }
 
@@ -232,7 +246,7 @@ pub fn debug_set_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugSet<'a, 'b
             fmt: fmt,
             result: result,
             has_fields: false,
-        }
+        },
     }
 }
 
@@ -247,7 +261,9 @@ pub fn entry(&mut self, entry: &fmt::Debug) -> &mut DebugSet<'a, 'b> {
     /// Adds the contents of an iterator of entries to the set output.
     #[stable(feature = "debug_builders", since = "1.2.0")]
     pub fn entries<D, I>(&mut self, entries: I) -> &mut DebugSet<'a, 'b>
-            where D: fmt::Debug, I: IntoIterator<Item=D> {
+        where D: fmt::Debug,
+              I: IntoIterator<Item = D>
+    {
         for entry in entries {
             self.entry(&entry);
         }
@@ -278,7 +294,7 @@ pub fn debug_list_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugList<'a,
             fmt: fmt,
             result: result,
             has_fields: false,
-        }
+        },
     }
 }
 
@@ -293,7 +309,9 @@ pub fn entry(&mut self, entry: &fmt::Debug) -> &mut DebugList<'a, 'b> {
     /// Adds the contents of an iterator of entries to the list output.
     #[stable(feature = "debug_builders", since = "1.2.0")]
     pub fn entries<D, I>(&mut self, entries: I) -> &mut DebugList<'a, 'b>
-            where D: fmt::Debug, I: IntoIterator<Item=D> {
+        where D: fmt::Debug,
+              I: IntoIterator<Item = D>
+    {
         for entry in entries {
             self.entry(&entry);
         }
@@ -335,10 +353,19 @@ pub fn entry(&mut self, key: &fmt::Debug, value: &fmt::Debug) -> &mut DebugMap<'
         self.result = self.result.and_then(|_| {
             if self.is_pretty() {
                 let mut writer = PadAdapter::new(self.fmt);
-                let prefix = if self.has_fields { "," } else { "" };
-                fmt::write(&mut writer, format_args!("{}\n{:#?}: {:#?}", prefix, key, value))
+                let prefix = if self.has_fields {
+                    ","
+                } else {
+                    ""
+                };
+                fmt::write(&mut writer,
+                           format_args!("{}\n{:#?}: {:#?}", prefix, key, value))
             } else {
-                let prefix = if self.has_fields { ", " } else { "" };
+                let prefix = if self.has_fields {
+                    ", "
+                } else {
+                    ""
+                };
                 write!(self.fmt, "{}{:?}: {:?}", prefix, key, value)
             }
         });
@@ -350,7 +377,10 @@ pub fn entry(&mut self, key: &fmt::Debug, value: &fmt::Debug) -> &mut DebugMap<'
     /// Adds the contents of an iterator of entries to the map output.
     #[stable(feature = "debug_builders", since = "1.2.0")]
     pub fn entries<K, V, I>(&mut self, entries: I) -> &mut DebugMap<'a, 'b>
-            where K: fmt::Debug, V: fmt::Debug, I: IntoIterator<Item=(K, V)> {
+        where K: fmt::Debug,
+              V: fmt::Debug,
+              I: IntoIterator<Item = (K, V)>
+    {
         for (k, v) in entries {
             self.entry(&k, &v);
         }
@@ -360,7 +390,11 @@ pub fn entries<K, V, I>(&mut self, entries: I) -> &mut DebugMap<'a, 'b>
     /// Finishes output and returns any error encountered.
     #[stable(feature = "debug_builders", since = "1.2.0")]
     pub fn finish(&mut self) -> fmt::Result {
-        let prefix = if self.is_pretty() && self.has_fields { "\n" } else { "" };
+        let prefix = if self.is_pretty() && self.has_fields {
+            "\n"
+        } else {
+            ""
+        };
         self.result.and_then(|_| write!(self.fmt, "{}}}", prefix))
     }
 
index 022fe6711bdb3c7379585cf3356eca0a20222d64..5d8f58580788d2cee6ebee917812a61c5a62ecc1 100644 (file)
@@ -48,7 +48,9 @@ trait GenericRadix {
     fn base(&self) -> u8;
 
     /// A radix-specific prefix string.
-    fn prefix(&self) -> &'static str { "" }
+    fn prefix(&self) -> &'static str {
+        ""
+    }
 
     /// Converts an integer to corresponding radix digit.
     fn digit(&self, x: u8) -> u8;
@@ -70,7 +72,10 @@ fn fmt_int<T: Int>(&self, mut x: T, f: &mut fmt::Formatter) -> fmt::Result {
                 x = x / base;                  // Deaccumulate the number.
                 *byte = self.digit(n.to_u8()); // Store the digit in the buffer.
                 curr -= 1;
-                if x == zero { break };        // No more digits left to accumulate.
+                if x == zero {
+                    // No more digits left to accumulate.
+                    break
+                };
             }
         } else {
             // Do the same as above, but accounting for two's complement.
@@ -79,7 +84,9 @@ fn fmt_int<T: Int>(&self, mut x: T, f: &mut fmt::Formatter) -> fmt::Result {
                 x = x / base;                  // Deaccumulate the number.
                 *byte = self.digit(n.to_u8()); // Store the digit in the buffer.
                 curr -= 1;
-                if x == zero { break };        // No more digits left to accumulate.
+                if x == zero {
+                    break
+                };        // No more digits left to accumulate.
             }
         }
         let buf = unsafe { str::from_utf8_unchecked(&buf[curr..]) };
@@ -141,13 +148,17 @@ pub struct Radix {
 
 impl Radix {
     fn new(base: u8) -> Radix {
-        assert!(2 <= base && base <= 36, "the base must be in the range of 2..36: {}", base);
+        assert!(2 <= base && base <= 36,
+                "the base must be in the range of 2..36: {}",
+                base);
         Radix { base: base }
     }
 }
 
 impl GenericRadix for Radix {
-    fn base(&self) -> u8 { self.base }
+    fn base(&self) -> u8 {
+        self.base
+    }
     fn digit(&self, x: u8) -> u8 {
         match x {
             x @  0 ... 9 => b'0' + x,
index 033834dd5aaaa59dc7941eb5a82f06271782a599..f889045a3f59568b14eeca4689a0bf21c11975d1 100644 (file)
@@ -53,5 +53,5 @@ pub enum Count {
 #[derive(Copy, Clone)]
 pub enum Position {
     Next,
-    At(usize)
+    At(usize),
 }