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.
This commit is contained in:
@@ -695,7 +695,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
|||||||
// Now create a vector containing all the arguments
|
// Now create a vector containing all the arguments
|
||||||
let args = locals.into_iter().chain(counts.into_iter());
|
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:
|
// 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
|
// But the nested match expression is proved to perform not as well
|
||||||
// as series of let's; the first approach does.
|
// as series of let's; the first approach does.
|
||||||
let pat = self.ecx.pat_tuple(self.fmtsp, pats);
|
let pat = self.ecx.pat_tuple(self.macsp, pats);
|
||||||
let arm = self.ecx.arm(self.fmtsp, pat, args_array);
|
let arm = self.ecx.arm(self.macsp, pat, args_array);
|
||||||
let head = self.ecx.expr(self.fmtsp, ast::ExprKind::Tup(heads));
|
let head = self.ecx.expr(self.macsp, ast::ExprKind::Tup(heads));
|
||||||
let result = self.ecx.expr_match(self.fmtsp, head, vec![arm]);
|
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.
|
// Now create the fmt::Arguments struct with all our locals we created.
|
||||||
let (fn_name, fn_args) = if self.all_pieces_simple {
|
let (fn_name, fn_args) = if self.all_pieces_simple {
|
||||||
|
|||||||
@@ -15,5 +15,5 @@ impl ::std::fmt::Write for Stream {
|
|||||||
fn main() {
|
fn main() {
|
||||||
write(|| format_args!("{}", String::from("Hello world")));
|
write(|| format_args!("{}", String::from("Hello world")));
|
||||||
//~^ ERROR cannot return value referencing temporary value
|
//~^ ERROR cannot return value referencing temporary value
|
||||||
//~| ERROR cannot return value referencing temporary value
|
//~| ERROR cannot return reference to temporary value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,11 @@ LL | write(|| format_args!("{}", String::from("Hello world")));
|
|||||||
| | temporary value created here
|
| | temporary value created here
|
||||||
| returns a value referencing data owned by the current function
|
| 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
|
--> $DIR/issue-27592.rs:16:14
|
||||||
|
|
|
|
||||||
LL | write(|| format_args!("{}", String::from("Hello world")));
|
LL | write(|| format_args!("{}", String::from("Hello world")));
|
||||||
| ^^^^^^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returns a reference to data owned by the current function
|
||||||
| | |
|
|
||||||
| | temporary value created here
|
|
||||||
| returns a value referencing data owned by the current function
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user