Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4d5284a

Browse files
Rollup merge of #139833 - nnethercote:fix-139633, r=oli-obk
Fix some HIR pretty-printing problems r? `@oli-obk`
2 parents 45b644b + 16670e1 commit 4d5284a

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

‎compiler/rustc_hir_pretty/src/lib.rs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,10 +1871,11 @@ impl<'a> State<'a> {
18711871
fn print_pat(&mut self, pat: &hir::Pat<'_>) {
18721872
self.maybe_print_comment(pat.span.lo());
18731873
self.ann.pre(self, AnnNode::Pat(pat));
1874-
// Pat isn't normalized, but the beauty of it
1875-
// is that it doesn't matter
1874+
// Pat isn't normalized, but the beauty of it is that it doesn't matter.
18761875
match pat.kind {
1877-
PatKind::Missing => unreachable!(),
1876+
// Printing `_` isn't ideal for a missing pattern, but it's easy and good enough.
1877+
// E.g. `fn(u32)` gets printed as `fn(_: u32)`.
1878+
PatKind::Missing => self.word("_"),
18781879
PatKind::Wild => self.word("_"),
18791880
PatKind::Never => self.word("!"),
18801881
PatKind::Binding(BindingMode(by_ref, mutbl), _, ident, sub) => {
@@ -2164,7 +2165,9 @@ impl<'a> State<'a> {
21642165
s.end();
21652166
});
21662167
if decl.c_variadic {
2167-
self.word(", ");
2168+
if !decl.inputs.is_empty() {
2169+
self.word(", ");
2170+
}
21682171
print_arg(self, None);
21692172
self.word("...");
21702173
}

‎tests/pretty/hir-fn-variadic.pp‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,39 @@
1313
}
1414

1515
unsafe extern "C" fn bar(_: i32, mut va2: ...) -> usize { va2.arg::<usize>() }
16+
17+
fn main() {
18+
fn g1(_: extern "C" fn(_: u8, va: ...)) { }
19+
fn g2(_: extern "C" fn(_: u8, ...)) { }
20+
fn g3(_: extern "C" fn(u8, va: ...)) { }
21+
fn g4(_: extern "C" fn(u8, ...)) { }
22+
23+
fn g5(_: extern "C" fn(va: ...)) { }
24+
fn g6(_: extern "C" fn(...)) { }
25+
26+
{
27+
let _ =
28+
{
29+
unsafe extern "C" fn f1(_: u8, va: ...) { }
30+
};
31+
};
32+
{
33+
let _ =
34+
{
35+
unsafe extern "C" fn f2(_: u8, _: ...) { }
36+
};
37+
};
38+
39+
{
40+
let _ =
41+
{
42+
unsafe extern "C" fn f5(va: ...) { }
43+
};
44+
};
45+
{
46+
let _ =
47+
{
48+
unsafe extern "C" fn f6(_: ...) { }
49+
};
50+
};
51+
}

‎tests/pretty/hir-fn-variadic.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,19 @@ extern "C" {
1111
pub unsafe extern "C" fn bar(_: i32, mut va2: ...) -> usize {
1212
va2.arg::<usize>()
1313
}
14+
15+
fn main() {
16+
fn g1(_: extern "C" fn(_: u8, va: ...)) {}
17+
fn g2(_: extern "C" fn(_: u8, ...)) {}
18+
fn g3(_: extern "C" fn(u8, va: ...)) {}
19+
fn g4(_: extern "C" fn(u8, ...)) {}
20+
21+
fn g5(_: extern "C" fn(va: ...)) {}
22+
fn g6(_: extern "C" fn(...)) {}
23+
24+
_ = { unsafe extern "C" fn f1(_: u8, va: ...) {} };
25+
_ = { unsafe extern "C" fn f2(_: u8, ...) {} };
26+
27+
_ = { unsafe extern "C" fn f5(va: ...) {} };
28+
_ = { unsafe extern "C" fn f6(...) {} };
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /