Skip to content

Commit e885122

Browse files
committed
Add a pretty printing test for fn params.
Note that multiple parts of the output are incorrect. The following commits will fix this.
1 parent 249cb84 commit e885122

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

tests/pretty/hir-fn-params.pp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#[prelude_import]
2+
use ::std::prelude::rust_2015::*;
3+
#[macro_use]
4+
extern crate std;
5+
//@ pretty-compare-only
6+
//@ pretty-mode:hir
7+
//@ pp-exact:hir-fn-params.pp
8+
9+
// This tests the pretty-printing of various kinds of function parameters.
10+
11+
//---------------------------------------------------------------------------
12+
// Normal functions and methods.
13+
14+
fn normal_fn(_: u32, a: u32) { }
15+
16+
struct S;
17+
impl S {
18+
fn method(_: u32, a: u32) { }
19+
}
20+
21+
//---------------------------------------------------------------------------
22+
// More exotic forms, which get a different pretty-printing path. In the past,
23+
// anonymous params and `_` params printed incorrectly, e.g. `fn(u32, _: u32)`
24+
// was printed as `fn(: u32, : u32)`.
25+
//
26+
// Ideally we would also test invalid patterns, e.g. `fn(1: u32, &a: u32)`,
27+
// because they had similar problems. But the pretty-printing tests currently
28+
// can't contain compile errors.
29+
30+
fn bare_fn(x: fn(: u32, : u32, a: u32)) { }
31+
32+
extern "C" {
33+
unsafe fn foreign_fn(: u32, a: u32);
34+
}
35+
36+
trait T {
37+
fn trait_fn(: u32, : u32, a: u32);
38+
}

tests/pretty/hir-fn-params.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@ pretty-compare-only
2+
//@ pretty-mode:hir
3+
//@ pp-exact:hir-fn-params.pp
4+
5+
// This tests the pretty-printing of various kinds of function parameters.
6+
7+
//---------------------------------------------------------------------------
8+
// Normal functions and methods.
9+
10+
fn normal_fn(_: u32, a: u32) {}
11+
12+
struct S;
13+
impl S {
14+
fn method(_: u32, a: u32) {}
15+
}
16+
17+
//---------------------------------------------------------------------------
18+
// More exotic forms, which get a different pretty-printing path. In the past,
19+
// anonymous params and `_` params printed incorrectly, e.g. `fn(u32, _: u32)`
20+
// was printed as `fn(: u32, : u32)`.
21+
//
22+
// Ideally we would also test invalid patterns, e.g. `fn(1: u32, &a: u32)`,
23+
// because they had similar problems. But the pretty-printing tests currently
24+
// can't contain compile errors.
25+
26+
fn bare_fn(x: fn(u32, _: u32, a: u32)) {}
27+
28+
extern "C" {
29+
fn foreign_fn(_: u32, a: u32);
30+
}
31+
32+
trait T {
33+
fn trait_fn(u32, _: u32, a: u32);
34+
}

0 commit comments

Comments
 (0)