about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-12-20 21:22:02 +0800
committerGitHub <noreply@github.com>2017-12-20 21:22:02 +0800
commit0c29c7b1e48136c3fac6bb7fe9235672ae56a9c6 (patch)
tree00c700afe754ad48b23aff2c6b82dfce5ee365dc /src/libsyntax
parent99fdca077c9e4b629dbb44453804ca0e449f0e56 (diff)
parent7a95e716c731d1e358eeb8bf9741852f1278b4f3 (diff)
downloadrust-0c29c7b1e48136c3fac6bb7fe9235672ae56a9c6.tar.gz
rust-0c29c7b1e48136c3fac6bb7fe9235672ae56a9c6.zip
Rollup merge of #46851 - petrochenkov:tospace, r=estebank
Fix whitespacing issues in pretty-printing of bounds

cc https://github.com/rust-lang/rust/pull/46827#discussion_r157603277
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/print/pprust.rs35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index e9386e5187f..da4d5f5f676 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1066,11 +1066,11 @@ impl<'a> State<'a> {
                 self.print_qpath(path, qself, false)?
             }
             ast::TyKind::TraitObject(ref bounds, syntax) => {
-                let prefix = if syntax == ast::TraitObjectSyntax::Dyn { "dyn " } else { "" };
+                let prefix = if syntax == ast::TraitObjectSyntax::Dyn { "dyn" } else { "" };
                 self.print_bounds(prefix, &bounds[..])?;
             }
             ast::TyKind::ImplTrait(ref bounds) => {
-                self.print_bounds("impl ", &bounds[..])?;
+                self.print_bounds("impl", &bounds[..])?;
             }
             ast::TyKind::Array(ref ty, ref v) => {
                 self.s.word("[")?;
@@ -1398,7 +1398,8 @@ impl<'a> State<'a> {
                         real_bounds.push(b.clone());
                     }
                 }
-                self.print_bounds(" = ", &real_bounds[..])?;
+                self.nbsp()?;
+                self.print_bounds("=", &real_bounds[..])?;
                 self.print_where_clause(&generics.where_clause)?;
                 self.s.word(";")?;
             }
@@ -1444,6 +1445,7 @@ impl<'a> State<'a> {
                 comma = true;
             }
             self.s.word(">")?;
+            self.nbsp()?;
         }
         Ok(())
     }
@@ -2818,30 +2820,29 @@ impl<'a> State<'a> {
             self.s.word(prefix)?;
             let mut first = true;
             for bound in bounds {
-                self.nbsp()?;
+                if !(first && prefix.is_empty()) {
+                    self.nbsp()?;
+                }
                 if first {
                     first = false;
                 } else {
                     self.word_space("+")?;
                 }
 
-                (match *bound {
-                    TraitTyParamBound(ref tref, TraitBoundModifier::None) => {
-                        self.print_poly_trait_ref(tref)
-                    }
-                    TraitTyParamBound(ref tref, TraitBoundModifier::Maybe) => {
-                        self.s.word("?")?;
-                        self.print_poly_trait_ref(tref)
+                match bound {
+                    TraitTyParamBound(tref, modifier) => {
+                        if modifier == &TraitBoundModifier::Maybe {
+                            self.s.word("?")?;
+                        }
+                        self.print_poly_trait_ref(tref)?;
                     }
-                    RegionTyParamBound(ref lt) => {
-                        self.print_lifetime(lt)
+                    RegionTyParamBound(lt) => {
+                        self.print_lifetime(lt)?;
                     }
-                })?
+                }
             }
-            Ok(())
-        } else {
-            Ok(())
         }
+        Ok(())
     }
 
     pub fn print_lifetime(&mut self,