Skip to content

Commit

Permalink
Rollup merge of rust-lang#103080 - ohno418:fix-hir-pretty-print-lifet…
Browse files Browse the repository at this point in the history
…imes, r=cjgillot

pretty: fix to print some lifetimes on HIR pretty-print

HIR pretty-printer doesn't seem to print some lifetimes in types. This PR fixes that.

Closes rust-lang#85089
  • Loading branch information
matthiaskrgr committed Oct 15, 2022
2 parents ac26c0e + 7334526 commit 0aaf7b2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,11 @@ impl<'a> State<'a> {

let mut nonelided_generic_args: bool = false;
let elide_lifetimes = generic_args.args.iter().all(|arg| match arg {
GenericArg::Lifetime(lt) => lt.is_elided(),
GenericArg::Lifetime(lt) if lt.is_elided() => true,
GenericArg::Lifetime(_) => {
nonelided_generic_args = true;
false
}
_ => {
nonelided_generic_args = true;
true
Expand Down
20 changes: 20 additions & 0 deletions src/test/pretty/issue-85089.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
// Test to print lifetimes on HIR pretty-printing.

// pretty-compare-only
// pretty-mode:hir
// pp-exact:issue-85089.pp

trait A<'x> { }
trait B<'x> { }

struct Foo<'b> {
bar: &'b dyn for<'a> A<'a>,
}

impl <'a> B<'a> for dyn for<'b> A<'b> { }

impl <'a> A<'a> for Foo<'a> { }
16 changes: 16 additions & 0 deletions src/test/pretty/issue-85089.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Test to print lifetimes on HIR pretty-printing.

// pretty-compare-only
// pretty-mode:hir
// pp-exact:issue-85089.pp

trait A<'x> {}
trait B<'x> {}

struct Foo<'b> {
pub bar: &'b dyn for<'a> A<'a>,
}

impl<'a> B<'a> for dyn for<'b> A<'b> {}

impl<'a> A<'a> for Foo<'a> {}

0 comments on commit 0aaf7b2

Please sign in to comment.