Skip to content

Fix pretty-printing of lifetime bound #34547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ impl<'a> State<'a> {
if comma {
try!(self.word_space(","))
}
try!(self.print_lifetime_def(lifetime_def));
try!(self.print_lifetime_bounds(&lifetime_def.lifetime, &lifetime_def.bounds));
comma = true;
}
try!(word(&mut self.s, ">"));
Expand Down Expand Up @@ -2749,16 +2749,20 @@ impl<'a> State<'a> {
self.print_name(lifetime.name)
}

pub fn print_lifetime_def(&mut self,
lifetime: &ast::LifetimeDef)
-> io::Result<()>
pub fn print_lifetime_bounds(&mut self,
lifetime: &ast::Lifetime,
bounds: &[ast::Lifetime])
-> io::Result<()>
{
try!(self.print_lifetime(&lifetime.lifetime));
let mut sep = ":";
for v in &lifetime.bounds {
try!(word(&mut self.s, sep));
try!(self.print_lifetime(v));
sep = "+";
try!(self.print_lifetime(lifetime));
if !bounds.is_empty() {
try!(word(&mut self.s, ": "));
for (i, bound) in bounds.iter().enumerate() {
if i != 0 {
try!(word(&mut self.s, " + "));
}
try!(self.print_lifetime(bound));
}
}
Ok(())
}
Expand All @@ -2781,8 +2785,8 @@ impl<'a> State<'a> {

try!(self.commasep(Inconsistent, &ints[..], |s, &idx| {
if idx < generics.lifetimes.len() {
let lifetime = &generics.lifetimes[idx];
s.print_lifetime_def(lifetime)
let lifetime_def = &generics.lifetimes[idx];
s.print_lifetime_bounds(&lifetime_def.lifetime, &lifetime_def.bounds)
} else {
let idx = idx - generics.lifetimes.len();
let param = &generics.ty_params[idx];
Expand Down Expand Up @@ -2833,16 +2837,7 @@ impl<'a> State<'a> {
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime,
ref bounds,
..}) => {
try!(self.print_lifetime(lifetime));
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, ":"));
}
}
try!(self.print_lifetime_bounds(lifetime, bounds));
}
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => {
try!(self.print_path(path, false, 0));
Expand Down
15 changes: 15 additions & 0 deletions src/test/pretty/lifetime.rs
Original file line number Diff line number Diff line change
@@ -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 { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(now that I look at it, I wonder if the right convention would be to print 'c: 'a+'b instead of 'c: 'a + 'b. But I'm not going to let that question hold up this PR.)


fn main() { }
2 changes: 1 addition & 1 deletion src/test/pretty/where-clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

// 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() { }