about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorStephen Crane <sjc@immunant.com>2019-09-25 11:45:38 -0700
committerStephen Crane <sjc@immunant.com>2019-09-25 17:45:15 -0700
commit0ec4513d5fe23fabe353e4773682ddb341c9d20f (patch)
treeeadfee784797a1ef47e4db0f3397260355d4a368 /src
parent6c2c29c43206d6e2f1091fa278d2792ea10e3659 (diff)
downloadrust-0ec4513d5fe23fabe353e4773682ddb341c9d20f.tar.gz
rust-0ec4513d5fe23fabe353e4773682ddb341c9d20f.zip
Fix format macro expansions spans to be macro-generated
New Exprs generated as part of the format macro expansion should get the macro
expansion span which has an expansion context, not the span of the format string
which does not.
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax_ext/format.rs12
-rw-r--r--src/test/ui/issues/issue-27592.rs2
-rw-r--r--src/test/ui/issues/issue-27592.stderr7
3 files changed, 9 insertions, 12 deletions
diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs
index 2765346b333..8fc64021b51 100644
--- a/src/libsyntax_ext/format.rs
+++ b/src/libsyntax_ext/format.rs
@@ -695,7 +695,7 @@ impl<'a, 'b> Context<'a, 'b> {
         // Now create a vector containing all the arguments
         let args = locals.into_iter().chain(counts.into_iter());
 
-        let args_array = self.ecx.expr_vec(self.fmtsp, args.collect());
+        let args_array = self.ecx.expr_vec(self.macsp, args.collect());
 
         // Constructs an AST equivalent to:
         //
@@ -724,12 +724,12 @@ impl<'a, 'b> Context<'a, 'b> {
         //
         // But the nested match expression is proved to perform not as well
         // as series of let's; the first approach does.
-        let pat = self.ecx.pat_tuple(self.fmtsp, pats);
-        let arm = self.ecx.arm(self.fmtsp, pat, args_array);
-        let head = self.ecx.expr(self.fmtsp, ast::ExprKind::Tup(heads));
-        let result = self.ecx.expr_match(self.fmtsp, head, vec![arm]);
+        let pat = self.ecx.pat_tuple(self.macsp, pats);
+        let arm = self.ecx.arm(self.macsp, pat, args_array);
+        let head = self.ecx.expr(self.macsp, ast::ExprKind::Tup(heads));
+        let result = self.ecx.expr_match(self.macsp, head, vec![arm]);
 
-        let args_slice = self.ecx.expr_addr_of(self.fmtsp, result);
+        let args_slice = self.ecx.expr_addr_of(self.macsp, result);
 
         // Now create the fmt::Arguments struct with all our locals we created.
         let (fn_name, fn_args) = if self.all_pieces_simple {
diff --git a/src/test/ui/issues/issue-27592.rs b/src/test/ui/issues/issue-27592.rs
index b023ea18ac9..88f70f58402 100644
--- a/src/test/ui/issues/issue-27592.rs
+++ b/src/test/ui/issues/issue-27592.rs
@@ -15,5 +15,5 @@ impl ::std::fmt::Write for Stream {
 fn main() {
     write(|| format_args!("{}", String::from("Hello world")));
     //~^ ERROR cannot return value referencing temporary value
-    //~| ERROR cannot return value referencing temporary value
+    //~| ERROR cannot return reference to temporary value
 }
diff --git a/src/test/ui/issues/issue-27592.stderr b/src/test/ui/issues/issue-27592.stderr
index 9d3eaa9705d..c8649d82d74 100644
--- a/src/test/ui/issues/issue-27592.stderr
+++ b/src/test/ui/issues/issue-27592.stderr
@@ -7,14 +7,11 @@ LL |     write(|| format_args!("{}", String::from("Hello world")));
    |              |                  temporary value created here
    |              returns a value referencing data owned by the current function
 
-error[E0515]: cannot return value referencing temporary value
+error[E0515]: cannot return reference to temporary value
   --> $DIR/issue-27592.rs:16:14
    |
 LL |     write(|| format_args!("{}", String::from("Hello world")));
-   |              ^^^^^^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |              |            |
-   |              |            temporary value created here
-   |              returns a value referencing data owned by the current function
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returns a reference to data owned by the current function
 
 error: aborting due to 2 previous errors