1
Fork 0

Fix pretty-printing of lifetime bound

This commit is contained in:
Seo Sanghyeon 2016-06-29 21:53:01 +09:00
parent 366de839ae
commit 3c29fc5f6c
3 changed files with 33 additions and 23 deletions

View file

@ -1338,7 +1338,7 @@ impl<'a> State<'a> {
if comma { if comma {
try!(self.word_space(",")) try!(self.word_space(","))
} }
try!(self.print_lifetime_def(lifetime_def)); try!(self.print_lifetime_bounds(&lifetime_def.lifetime, &lifetime_def.bounds));
comma = true; comma = true;
} }
try!(word(&mut self.s, ">")); try!(word(&mut self.s, ">"));
@ -2749,16 +2749,20 @@ impl<'a> State<'a> {
self.print_name(lifetime.name) self.print_name(lifetime.name)
} }
pub fn print_lifetime_def(&mut self, pub fn print_lifetime_bounds(&mut self,
lifetime: &ast::LifetimeDef) lifetime: &ast::Lifetime,
-> io::Result<()> bounds: &[ast::Lifetime])
-> io::Result<()>
{ {
try!(self.print_lifetime(&lifetime.lifetime)); try!(self.print_lifetime(lifetime));
let mut sep = ":"; if !bounds.is_empty() {
for v in &lifetime.bounds { try!(word(&mut self.s, ": "));
try!(word(&mut self.s, sep)); for (i, bound) in bounds.iter().enumerate() {
try!(self.print_lifetime(v)); if i != 0 {
sep = "+"; try!(word(&mut self.s, " + "));
}
try!(self.print_lifetime(bound));
}
} }
Ok(()) Ok(())
} }
@ -2781,8 +2785,8 @@ impl<'a> State<'a> {
try!(self.commasep(Inconsistent, &ints[..], |s, &idx| { try!(self.commasep(Inconsistent, &ints[..], |s, &idx| {
if idx < generics.lifetimes.len() { if idx < generics.lifetimes.len() {
let lifetime = &generics.lifetimes[idx]; let lifetime_def = &generics.lifetimes[idx];
s.print_lifetime_def(lifetime) s.print_lifetime_bounds(&lifetime_def.lifetime, &lifetime_def.bounds)
} else { } else {
let idx = idx - generics.lifetimes.len(); let idx = idx - generics.lifetimes.len();
let param = &generics.ty_params[idx]; let param = &generics.ty_params[idx];
@ -2833,16 +2837,7 @@ impl<'a> State<'a> {
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime, ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime,
ref bounds, ref bounds,
..}) => { ..}) => {
try!(self.print_lifetime(lifetime)); try!(self.print_lifetime_bounds(lifetime, bounds));
try!(word(&mut self.s, ":"));
for (i, bound) in bounds.iter().enumerate() {
try!(self.print_lifetime(bound));
if i != 0 {
try!(word(&mut self.s, ":"));
}
}
} }
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => { ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => {
try!(self.print_path(path, false, 0)); try!(self.print_path(path, false, 0));

View file

@ -0,0 +1,15 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// pp-exact
fn f1<'a, 'b, 'c>(_x: &'a u32, _y: &'b u32, _z: &'c u32) where 'c: 'a + 'b { }
fn main() { }

View file

@ -10,6 +10,6 @@
// pp-exact // pp-exact
fn f<'a, 'b, T>(t: T) -> isize where T: 'a, 'a:'b, T: Eq { 0 } fn f<'a, 'b, T>(t: T) -> isize where T: 'a, 'a: 'b, T: Eq { 0 }
fn main() { } fn main() { }