Gensym arguments for format macro

This commit is contained in:
James Sanderson
2018-04-24 21:30:13 +01:00
parent d80797b85e
commit 27b0f1e193

View File

@@ -543,6 +543,10 @@ impl<'a, 'b> Context<'a, 'b> {
let mut pats = Vec::new();
let mut heads = Vec::new();
let names_pos: Vec<_> = (0..self.args.len()).map(|i| {
self.ecx.ident_of(&format!("arg{}", i)).gensym()
}).collect();
// First, build up the static array which will become our precompiled
// format "string"
let pieces = self.ecx.expr_vec_slice(self.fmtsp, self.str_pieces);
@@ -560,7 +564,7 @@ impl<'a, 'b> Context<'a, 'b> {
// of each variable because we don't want to move out of the arguments
// passed to this function.
for (i, e) in self.args.into_iter().enumerate() {
let name = self.ecx.ident_of(&format!("__arg{}", i));
let name = names_pos[i];
let span =
DUMMY_SP.with_ctxt(e.span.ctxt().apply_mark(self.ecx.current_expansion.mark));
pats.push(self.ecx.pat_ident(span, name));
@@ -570,14 +574,12 @@ impl<'a, 'b> Context<'a, 'b> {
heads.push(self.ecx.expr_addr_of(e.span, e));
}
for pos in self.count_args {
let name = self.ecx.ident_of(&match pos {
Exact(i) => format!("__arg{}", i),
_ => panic!("should never happen"),
});
let span = match pos {
Exact(i) => spans_pos[i],
let index = match pos {
Exact(i) => i,
_ => panic!("should never happen"),
};
let name = names_pos[index];
let span = spans_pos[index];
counts.push(Context::format_arg(self.ecx, self.macsp, span, &Count, name));
}