1
Fork 0

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
This commit is contained in:
kennytm 2017-12-20 21:22:02 +08:00 committed by GitHub
commit 0c29c7b1e4
6 changed files with 45 additions and 42 deletions

View file

@ -408,15 +408,16 @@ impl<'a> State<'a> {
hir::TyTraitObject(ref bounds, ref lifetime) => {
let mut first = true;
for bound in bounds {
self.nbsp()?;
if first {
first = false;
} else {
self.nbsp()?;
self.word_space("+")?;
}
self.print_poly_trait_ref(bound)?;
}
if !lifetime.is_elided() {
self.nbsp()?;
self.word_space("+")?;
self.print_lifetime(lifetime)?;
}
@ -764,6 +765,7 @@ impl<'a> State<'a> {
real_bounds.push(b.clone());
}
}
self.nbsp()?;
self.print_bounds("=", &real_bounds[..])?;
self.print_where_clause(&generics.where_clause)?;
self.s.word(";")?;
@ -788,6 +790,7 @@ impl<'a> State<'a> {
comma = true;
}
self.s.word(">")?;
self.nbsp()?;
}
Ok(())
}
@ -2016,30 +2019,29 @@ impl<'a> State<'a> {
self.s.word(prefix)?;
let mut first = true;
for bound in bounds {
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) => {
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)
self.print_poly_trait_ref(tref)?;
}
RegionTyParamBound(lt) => {
self.print_lifetime(lt)?;
}
}
}
}?
}
Ok(())
} else {
Ok(())
}
}
pub fn print_lifetime(&mut self, lifetime: &hir::Lifetime) -> io::Result<()> {

View file

@ -1398,6 +1398,7 @@ impl<'a> State<'a> {
real_bounds.push(b.clone());
}
}
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 {
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) => {
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)
self.print_poly_trait_ref(tref)?;
}
RegionTyParamBound(lt) => {
self.print_lifetime(lt)?;
}
}
}
})?
}
Ok(())
} else {
Ok(())
}
}
pub fn print_lifetime(&mut self,