diff options
| author | bors <bors@rust-lang.org> | 2013-09-03 09:50:58 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-09-03 09:50:58 -0700 |
| commit | dee9d7f97f2e679eecd21dfcbc7628c7caf5bd7e (patch) | |
| tree | 52fc5f068e2c7152938cd9b678f1c60f95d8022d /src | |
| parent | c14daba3b2f3218438a6928ed0676986c6339d48 (diff) | |
| parent | 7e7024718a8f9668c3ae6f885ba77d2957362d46 (diff) | |
| download | rust-dee9d7f97f2e679eecd21dfcbc7628c7caf5bd7e.tar.gz rust-dee9d7f97f2e679eecd21dfcbc7628c7caf5bd7e.zip | |
auto merge of #8945 : alexcrichton/rust/ifmt-dont-move, r=thestinger
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax/ext/ifmt.rs | 8 | ||||
| -rw-r--r-- | src/test/run-pass/ifmt.rs | 5 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/libsyntax/ext/ifmt.rs b/src/libsyntax/ext/ifmt.rs index ddddd44c7f1..213aeee66c7 100644 --- a/src/libsyntax/ext/ifmt.rs +++ b/src/libsyntax/ext/ifmt.rs @@ -588,11 +588,14 @@ impl Context { // foo(bar(&1)) // the lifetime of `1` doesn't outlast the call to `bar`, so it's not // vald for the call to `foo`. To work around this all arguments to the - // fmt! string are shoved into locals. + // fmt! string are shoved into locals. Furthermore, we shove the address + // of each variable because we don't want to move out of the arguments + // passed to this function. for (i, &e) in self.args.iter().enumerate() { if self.arg_types[i].is_none() { loop } // error already generated let name = self.ecx.ident_of(fmt!("__arg%u", i)); + let e = self.ecx.expr_addr_of(e.span, e); lets.push(self.ecx.stmt_let(e.span, false, name, e)); locals.push(self.format_arg(e.span, Left(i), name)); } @@ -600,6 +603,7 @@ impl Context { if !self.name_types.contains_key(&name) { loop } let lname = self.ecx.ident_of(fmt!("__arg%s", name)); + let e = self.ecx.expr_addr_of(e.span, e); lets.push(self.ecx.stmt_let(e.span, false, lname, e)); names[*self.name_positions.get(&name)] = Some(self.format_arg(e.span, Right(name), lname)); @@ -643,7 +647,7 @@ impl Context { Right(s) => *self.name_types.get(&s) }; - let argptr = self.ecx.expr_addr_of(sp, self.ecx.expr_ident(sp, ident)); + let argptr = self.ecx.expr_ident(sp, ident); let fmt_trait = match ty { Unknown => "Default", Known(tyname) => { diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 44d4386e0c5..236fa44939a 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -215,6 +215,11 @@ pub fn main() { test_write(); test_print(); + + // make sure that format! doesn't move out of local variables + let a = ~3; + format!("{:?}", a); + format!("{:?}", a); } // Basic test to make sure that we can invoke the `write!` macro with an |
