Skip to content

Commit 001f6fb

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 001f6fb

File tree

2 files changed

+187
-0
lines changed

2 files changed

+187
-0
lines changed

tests/pretty/hir-lifetimes.pp

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
fn a(x: &'_ u32) { }
23+
24+
fn b(x: &'_ u32) { }
25+
26+
fn c(x: &'_ u32, y: &'static u32) { }
27+
28+
// FIXME: `'a` before `self` is omitted
29+
fn d<'a>(&self, x: &'a u32) { }
30+
31+
// FIXME: impl Traits printed as just `/*impl Trait*/`, ugh
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+
fn g(x: &'_ dyn for<'a, 'b> MyTrait<'a, 'b>) { }
62+
63+
trait Blah { }
64+
65+
type T<'a> = dyn Blah + 'a;
66+
67+
type Q<'a> = dyn MyTrait<'a, 'a> + 'a;
68+
69+
fn h<'b, F>(f: F, y: Foo<'b>) where F: for<'d> MyTrait<'d, 'b> { }
70+
71+
// FIXME(?): attr printing is weird
72+
#[attr = Repr([ReprC])]
73+
struct S<'a>(&'a u32);
74+
75+
extern "C" {
76+
unsafe fn g1(s: S<>);
77+
unsafe fn g2(s: S<'_>);
78+
unsafe fn g3<'a>(s: S<'a>);
79+
}
80+
81+
struct St<'a> {
82+
x: &'a u32,
83+
}
84+
85+
fn f() { { let _ = St{ x: &0,}; }; { let _ = St{ x: &0,}; }; }
86+
87+
struct Name<'a>(&'a str);
88+
89+
const A: Name<> = Name("a");
90+
const B: &'_ str = "";
91+
static C: &'_ str = "";
92+
static D: &'static str = "";
93+
94+
fn tr(_: Box<dyn Blah>) { }
95+
96+
fn main() { }

tests/pretty/hir-lifetimes.rs

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
fn a(x: &u32) {}
19+
20+
fn b(x: &'_ u32) {}
21+
22+
fn c(x: &'_ u32, y: &'static u32) {}
23+
24+
// FIXME: `'a` before `self` is omitted
25+
fn d<'a>(&'a self, x: &'a u32) {}
26+
27+
// FIXME: impl Traits printed as just `/*impl Trait*/`, ugh
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+
fn g(x: &dyn for<'a, 'b> MyTrait<'a, 'b>) {}
56+
57+
trait Blah {}
58+
59+
type T<'a> = dyn Blah + 'a;
60+
61+
type Q<'a> = dyn MyTrait<'a, 'a> + 'a;
62+
63+
fn h<'b, F>(f: F, y: Foo<'b>) where F: for<'d> MyTrait<'d, 'b> {}
64+
65+
// FIXME(?): attr printing is weird
66+
#[repr(C)]
67+
struct S<'a>(&'a u32);
68+
69+
extern "C" {
70+
fn g1(s: S);
71+
fn g2(s: S<'_>);
72+
fn g3<'a>(s: S<'a>);
73+
}
74+
75+
struct St<'a> { x: &'a u32 }
76+
77+
fn f() {
78+
_ = St { x: &0 };
79+
_ = St::<'_> { x: &0 };
80+
}
81+
82+
struct Name<'a>(&'a str);
83+
84+
const A: Name = Name("a");
85+
const B: &str = "";
86+
static C: &'_ str = "";
87+
static D: &'static str = "";
88+
89+
fn tr(_: Box<dyn Blah>) {}
90+
91+
fn main() {}

0 commit comments

Comments
 (0)