Skip to content

Commit 94848f7

Browse files
committed
Print variadic argument pattern in HIR pretty printer
1 parent 151256b commit 94848f7

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

compiler/rustc_hir_pretty/src/lib.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -502,13 +502,13 @@ impl<'a> State<'a> {
502502
self.word(";");
503503
self.end(); // end the outer cbox
504504
}
505-
hir::ItemKind::Fn(ref sig, param_names, body) => {
505+
hir::ItemKind::Fn(ref sig, generics, body) => {
506506
self.head("");
507507
self.print_fn(
508508
sig.decl,
509509
sig.header,
510510
Some(item.ident.name),
511-
param_names,
511+
generics,
512512
&[],
513513
Some(body),
514514
);
@@ -1948,11 +1948,10 @@ impl<'a> State<'a> {
19481948
self.print_generic_params(generics.params);
19491949

19501950
self.popen();
1951-
let mut i = 0;
19521951
// Make sure we aren't supplied *both* `arg_names` and `body_id`.
19531952
assert!(arg_names.is_empty() || body_id.is_none());
1954-
self.commasep(Inconsistent, decl.inputs, |s, ty| {
1955-
s.ibox(INDENT_UNIT);
1953+
let mut i = 0;
1954+
let mut print_arg = |s: &mut Self| {
19561955
if let Some(arg_name) = arg_names.get(i) {
19571956
s.word(arg_name.to_string());
19581957
s.word(":");
@@ -1963,11 +1962,17 @@ impl<'a> State<'a> {
19631962
s.space();
19641963
}
19651964
i += 1;
1965+
};
1966+
self.commasep(Inconsistent, decl.inputs, |s, ty| {
1967+
s.ibox(INDENT_UNIT);
1968+
print_arg(s);
19661969
s.print_type(ty);
1967-
s.end()
1970+
s.end();
19681971
});
19691972
if decl.c_variadic {
1970-
self.word(", ...");
1973+
self.word(", ");
1974+
print_arg(self);
1975+
self.word("...");
19711976
}
19721977
self.pclose();
19731978

tests/pretty/hir-fn-variadic.pp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// pretty-compare-only
2+
// pretty-mode:hir
3+
// pp-exact:hir-fn-variadic.pp
4+
5+
#![feature(c_variadic)]
6+
#[prelude_import]
7+
use ::std::prelude::rust_2015::*;
8+
#[macro_use]
9+
extern crate std;
10+
11+
extern "C" {
12+
fn foo(x: i32, ...);
13+
}
14+
15+
unsafe extern "C" fn bar(_: i32, mut va2: ...) -> usize { va2.arg::<usize>() }

tests/pretty/hir-fn-variadic.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// pretty-compare-only
2+
// pretty-mode:hir
3+
// pp-exact:hir-fn-variadic.pp
4+
5+
#![feature(c_variadic)]
6+
7+
extern "C" {
8+
pub fn foo(x: i32, va1: ...);
9+
}
10+
11+
pub unsafe extern "C" fn bar(_: i32, mut va2: ...) -> usize {
12+
va2.arg::<usize>()
13+
}

0 commit comments

Comments
 (0)