Skip to content

Commit 8eafd2d

Browse files
committed
Add a HIR pretty-printing test focused on lifetimes.
HIR printing currently gets very little testing. This increases coverage a bit, with a focus on lifetimes. There are some FIXME comments for cases that are printed in a dubious fashion. This PR won't address those; the point of adding this test is to ensure that the subsequent commits don't hurt pretty-printing.
1 parent 43f0014 commit 8eafd2d

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

tests/pretty/hir-lifetimes.pp

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//@ pretty-compare-only
2+
//@ pretty-mode:hir
3+
//@ pp-exact:hir-lifetimes.pp
4+
5+
// This tests the pretty-printing of lifetimes in lots of ways.
6+
7+
#![allow(unused)]
8+
#[prelude_import]
9+
use ::std::prelude::rust_2015::*;
10+
#[macro_use]
11+
extern crate std;
12+
13+
struct Foo<'a> {
14+
x: &'a u32,
15+
}
16+
17+
impl <'a> Foo<'a> {
18+
fn f<'b>(x: &'b u32) { }
19+
}
20+
21+
impl Foo<'_> {
22+
// FIXME(?): `'_` is inserted before `u32`
23+
fn a(x: &'_ u32) { }
24+
25+
fn b(x: &'_ u32) { }
26+
27+
fn c(x: &'_ u32, y: &'static u32) { }
28+
29+
// FIXME: `'a` before `self` is omitted
30+
fn d<'a>(&self, x: &'a u32) { }
31+
32+
fn iter1<'a>(&self)
33+
-> /*impl Trait*/ { #[lang = "Range"]{ start: 0, end: 1,} }
34+
35+
fn iter2(&self)
36+
-> /*impl Trait*/ { #[lang = "Range"]{ start: 0, end: 1,} }
37+
}
38+
39+
fn a(x: Foo<'_>) { }
40+
41+
fn b<'a>(x: Foo<'a>) { }
42+
43+
struct Bar<'a, 'b, 'c, T> {
44+
x: &'a u32,
45+
y: &'b &'c u32,
46+
z: T,
47+
}
48+
49+
fn f1<'a, 'b, T>(x: Bar<'a, 'b, '_, T>) { }
50+
51+
fn f2(x: Bar<'_, '_, '_, u32>) { }
52+
53+
trait MyTrait<'a, 'b> {
54+
fn f(&self, x: Foo<'a>, y: Foo<'b>);
55+
}
56+
57+
impl <'a, 'b, 'c, T> MyTrait<'a, 'b> for Bar<'a, 'b, 'c, T> {
58+
fn f(&self, x: Foo<'a>, y: Foo<'b>) { }
59+
}
60+
61+
// FIXME(?): `'_` is inserted before `dyn`
62+
fn g(x: &'_ dyn for<'a, 'b> MyTrait<'a, 'b>) { }
63+
64+
trait Blah { }
65+
66+
type T<'a> = dyn Blah + 'a;
67+
68+
type Q<'a> = dyn MyTrait<'a, 'a> + 'a;
69+
70+
fn h<'b, F>(f: F, y: Foo<'b>) where F: for<'d> MyTrait<'d, 'b> { }
71+
72+
fn main() { }

tests/pretty/hir-lifetimes.rs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//@ pretty-compare-only
2+
//@ pretty-mode:hir
3+
//@ pp-exact:hir-lifetimes.pp
4+
5+
// This tests the pretty-printing of lifetimes in lots of ways.
6+
7+
#![allow(unused)]
8+
9+
struct Foo<'a> {
10+
x: &'a u32,
11+
}
12+
13+
impl<'a> Foo<'a> {
14+
fn f<'b>(x: &'b u32) {}
15+
}
16+
17+
impl Foo<'_> {
18+
// FIXME(?): `'_` is inserted before `u32`
19+
fn a(x: &u32) {}
20+
21+
fn b(x: &'_ u32) {}
22+
23+
fn c(x: &'_ u32, y: &'static u32) {}
24+
25+
// FIXME: `'a` before `self` is omitted
26+
fn d<'a>(&'a self, x: &'a u32) {}
27+
28+
fn iter1<'a>(&self) -> impl Iterator<Item = u32> + 'a { 0..1 }
29+
30+
fn iter2(&self) -> impl Iterator<Item = u32> + '_ { 0..1 }
31+
}
32+
33+
fn a(x: Foo<'_>) {}
34+
35+
fn b<'a>(x: Foo<'a>) {}
36+
37+
struct Bar<'a, 'b, 'c, T> {
38+
x: &'a u32,
39+
y: &'b &'c u32,
40+
z: T,
41+
}
42+
43+
fn f1<'a, 'b, T>(x: Bar<'a, 'b, '_, T>) {}
44+
45+
fn f2(x: Bar<'_, '_, '_, u32>) {}
46+
47+
trait MyTrait<'a, 'b> {
48+
fn f(&self, x: Foo<'a>, y: Foo<'b>);
49+
}
50+
51+
impl<'a, 'b, 'c, T> MyTrait<'a, 'b> for Bar<'a, 'b, 'c, T> {
52+
fn f(&self, x: Foo<'a>, y: Foo<'b>) {}
53+
}
54+
55+
// FIXME(?): `'_` is inserted before `dyn`
56+
fn g(x: &dyn for<'a, 'b> MyTrait<'a, 'b>) {}
57+
58+
trait Blah {}
59+
60+
type T<'a> = dyn Blah + 'a;
61+
62+
type Q<'a> = dyn MyTrait<'a, 'a> + 'a;
63+
64+
fn h<'b, F>(f: F, y: Foo<'b>) where F: for<'d> MyTrait<'d, 'b> {}
65+
66+
fn main() {}

0 commit comments

Comments
 (0)