Skip to content

Commit aa6fcd6

Browse files
authored
Rollup merge of #64793 - immunant:format_spans, r=matthewjasper
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 with an expansion context, rather than the span of the format string which does not.
2 parents 0df6386 + 0ec4513 commit aa6fcd6

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/libsyntax_ext/format.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl<'a, 'b> Context<'a, 'b> {
695695
// Now create a vector containing all the arguments
696696
let args = locals.into_iter().chain(counts.into_iter());
697697

698-
let args_array = self.ecx.expr_vec(self.fmtsp, args.collect());
698+
let args_array = self.ecx.expr_vec(self.macsp, args.collect());
699699

700700
// Constructs an AST equivalent to:
701701
//
@@ -724,12 +724,12 @@ impl<'a, 'b> Context<'a, 'b> {
724724
//
725725
// But the nested match expression is proved to perform not as well
726726
// as series of let's; the first approach does.
727-
let pat = self.ecx.pat_tuple(self.fmtsp, pats);
728-
let arm = self.ecx.arm(self.fmtsp, pat, args_array);
729-
let head = self.ecx.expr(self.fmtsp, ast::ExprKind::Tup(heads));
730-
let result = self.ecx.expr_match(self.fmtsp, head, vec![arm]);
727+
let pat = self.ecx.pat_tuple(self.macsp, pats);
728+
let arm = self.ecx.arm(self.macsp, pat, args_array);
729+
let head = self.ecx.expr(self.macsp, ast::ExprKind::Tup(heads));
730+
let result = self.ecx.expr_match(self.macsp, head, vec![arm]);
731731

732-
let args_slice = self.ecx.expr_addr_of(self.fmtsp, result);
732+
let args_slice = self.ecx.expr_addr_of(self.macsp, result);
733733

734734
// Now create the fmt::Arguments struct with all our locals we created.
735735
let (fn_name, fn_args) = if self.all_pieces_simple {

src/test/ui/issues/issue-27592.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ impl ::std::fmt::Write for Stream {
1515
fn main() {
1616
write(|| format_args!("{}", String::from("Hello world")));
1717
//~^ ERROR cannot return value referencing temporary value
18-
//~| ERROR cannot return value referencing temporary value
18+
//~| ERROR cannot return reference to temporary value
1919
}

src/test/ui/issues/issue-27592.stderr

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ LL | write(|| format_args!("{}", String::from("Hello world")));
77
| | temporary value created here
88
| returns a value referencing data owned by the current function
99

10-
error[E0515]: cannot return value referencing temporary value
10+
error[E0515]: cannot return reference to temporary value
1111
--> $DIR/issue-27592.rs:16:14
1212
|
1313
LL | write(|| format_args!("{}", String::from("Hello world")));
14-
| ^^^^^^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15-
| | |
16-
| | temporary value created here
17-
| returns a value referencing data owned by the current function
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returns a reference to data owned by the current function
1815

1916
error: aborting due to 2 previous errors
2017

0 commit comments

Comments
 (0)