Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1871,10 +1871,11 @@ impl<'a> State<'a> {
fn print_pat(&mut self, pat: &hir::Pat<'_>) {
self.maybe_print_comment(pat.span.lo());
self.ann.pre(self, AnnNode::Pat(pat));
// Pat isn't normalized, but the beauty of it
// is that it doesn't matter
// Pat isn't normalized, but the beauty of it is that it doesn't matter.
match pat.kind {
PatKind::Missing => unreachable!(),
// Printing `_` isn't ideal for a missing pattern, but it's easy and good enough.
// E.g. `fn(u32)` gets printed as `fn(_: u32)`.
PatKind::Missing => self.word("_"),
PatKind::Wild => self.word("_"),
PatKind::Never => self.word("!"),
PatKind::Binding(BindingMode(by_ref, mutbl), _, ident, sub) => {
Expand Down Expand Up @@ -2164,7 +2165,9 @@ impl<'a> State<'a> {
s.end();
});
if decl.c_variadic {
self.word(", ");
if !decl.inputs.is_empty() {
self.word(", ");
}
print_arg(self, None);
self.word("...");
}
Expand Down
36 changes: 36 additions & 0 deletions tests/pretty/hir-fn-variadic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,39 @@
}

unsafe extern "C" fn bar(_: i32, mut va2: ...) -> usize { va2.arg::<usize>() }

fn main() {
fn g1(_: extern "C" fn(_: u8, va: ...)) { }
fn g2(_: extern "C" fn(_: u8, ...)) { }
fn g3(_: extern "C" fn(u8, va: ...)) { }
fn g4(_: extern "C" fn(u8, ...)) { }

fn g5(_: extern "C" fn(va: ...)) { }
fn g6(_: extern "C" fn(...)) { }

{
let _ =
{
unsafe extern "C" fn f1(_: u8, va: ...) { }
};
};
{
let _ =
{
unsafe extern "C" fn f2(_: u8, _: ...) { }
};
};

{
let _ =
{
unsafe extern "C" fn f5(va: ...) { }
};
};
{
let _ =
{
unsafe extern "C" fn f6(_: ...) { }
};
};
}
16 changes: 16 additions & 0 deletions tests/pretty/hir-fn-variadic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ extern "C" {
pub unsafe extern "C" fn bar(_: i32, mut va2: ...) -> usize {
va2.arg::<usize>()
}

fn main() {
fn g1(_: extern "C" fn(_: u8, va: ...)) {}
fn g2(_: extern "C" fn(_: u8, ...)) {}
fn g3(_: extern "C" fn(u8, va: ...)) {}
fn g4(_: extern "C" fn(u8, ...)) {}

fn g5(_: extern "C" fn(va: ...)) {}
fn g6(_: extern "C" fn(...)) {}

_ = { unsafe extern "C" fn f1(_: u8, va: ...) {} };
_ = { unsafe extern "C" fn f2(_: u8, ...) {} };

_ = { unsafe extern "C" fn f5(va: ...) {} };
_ = { unsafe extern "C" fn f6(...) {} };
}
Loading