Skip to content

Commit 3c29fc5

Browse files
committed
Fix pretty-printing of lifetime bound
1 parent 366de83 commit 3c29fc5

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

src/libsyntax/print/pprust.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ impl<'a> State<'a> {
13381338
if comma {
13391339
try!(self.word_space(","))
13401340
}
1341-
try!(self.print_lifetime_def(lifetime_def));
1341+
try!(self.print_lifetime_bounds(&lifetime_def.lifetime, &lifetime_def.bounds));
13421342
comma = true;
13431343
}
13441344
try!(word(&mut self.s, ">"));
@@ -2749,16 +2749,20 @@ impl<'a> State<'a> {
27492749
self.print_name(lifetime.name)
27502750
}
27512751

2752-
pub fn print_lifetime_def(&mut self,
2753-
lifetime: &ast::LifetimeDef)
2754-
-> io::Result<()>
2752+
pub fn print_lifetime_bounds(&mut self,
2753+
lifetime: &ast::Lifetime,
2754+
bounds: &[ast::Lifetime])
2755+
-> io::Result<()>
27552756
{
2756-
try!(self.print_lifetime(&lifetime.lifetime));
2757-
let mut sep = ":";
2758-
for v in &lifetime.bounds {
2759-
try!(word(&mut self.s, sep));
2760-
try!(self.print_lifetime(v));
2761-
sep = "+";
2757+
try!(self.print_lifetime(lifetime));
2758+
if !bounds.is_empty() {
2759+
try!(word(&mut self.s, ": "));
2760+
for (i, bound) in bounds.iter().enumerate() {
2761+
if i != 0 {
2762+
try!(word(&mut self.s, " + "));
2763+
}
2764+
try!(self.print_lifetime(bound));
2765+
}
27622766
}
27632767
Ok(())
27642768
}
@@ -2781,8 +2785,8 @@ impl<'a> State<'a> {
27812785

27822786
try!(self.commasep(Inconsistent, &ints[..], |s, &idx| {
27832787
if idx < generics.lifetimes.len() {
2784-
let lifetime = &generics.lifetimes[idx];
2785-
s.print_lifetime_def(lifetime)
2788+
let lifetime_def = &generics.lifetimes[idx];
2789+
s.print_lifetime_bounds(&lifetime_def.lifetime, &lifetime_def.bounds)
27862790
} else {
27872791
let idx = idx - generics.lifetimes.len();
27882792
let param = &generics.ty_params[idx];
@@ -2833,16 +2837,7 @@ impl<'a> State<'a> {
28332837
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime,
28342838
ref bounds,
28352839
..}) => {
2836-
try!(self.print_lifetime(lifetime));
2837-
try!(word(&mut self.s, ":"));
2838-
2839-
for (i, bound) in bounds.iter().enumerate() {
2840-
try!(self.print_lifetime(bound));
2841-
2842-
if i != 0 {
2843-
try!(word(&mut self.s, ":"));
2844-
}
2845-
}
2840+
try!(self.print_lifetime_bounds(lifetime, bounds));
28462841
}
28472842
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => {
28482843
try!(self.print_path(path, false, 0));

src/test/pretty/lifetime.rs

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

src/test/pretty/where-clauses.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
// pp-exact
1212

13-
fn f<'a, 'b, T>(t: T) -> isize where T: 'a, 'a:'b, T: Eq { 0 }
13+
fn f<'a, 'b, T>(t: T) -> isize where T: 'a, 'a: 'b, T: Eq { 0 }
1414

1515
fn main() { }

0 commit comments

Comments
 (0)