Skip to content

Commit 9715724

Browse files
authored
Rollup merge of #90131 - camsteffen:fmt-args-span-fix, r=cjgillot
Fix a format_args span to be expansion I found this while exploring solutions for rust-lang/rust-clippy#7843. r? `@m-ou-se`
2 parents db9d361 + 4cfb7ad commit 9715724

26 files changed

+51
-1
lines changed

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,10 @@ impl<'a, 'b> Context<'a, 'b> {
769769
for arg_ty in self.arg_unique_types[i].iter() {
770770
args.push(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty, i));
771771
}
772-
heads.push(self.ecx.expr_addr_of(e.span, e));
772+
// use the arg span for `&arg` so that borrowck errors
773+
// point to the specific expression passed to the macro
774+
// (the span is otherwise unavailable in MIR)
775+
heads.push(self.ecx.expr_addr_of(e.span.with_ctxt(self.macsp.ctxt()), e));
773776
}
774777
for pos in self.count_args {
775778
let index = match pos {

src/test/ui/borrowck/borrowck-and-init.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `i`
33
|
44
LL | println!("{}", i);
55
| ^ use of possibly-uninitialized `i`
6+
|
7+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
68

79
error: aborting due to previous error
810

src/test/ui/borrowck/borrowck-break-uninit-2.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `x`
33
|
44
LL | println!("{}", x);
55
| ^ use of possibly-uninitialized `x`
6+
|
7+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
68

79
error: aborting due to previous error
810

src/test/ui/borrowck/borrowck-break-uninit.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `x`
33
|
44
LL | println!("{}", x);
55
| ^ use of possibly-uninitialized `x`
6+
|
7+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
68

79
error: aborting due to previous error
810

src/test/ui/borrowck/borrowck-or-init.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `i`
33
|
44
LL | println!("{}", i);
55
| ^ use of possibly-uninitialized `i`
6+
|
7+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
68

79
error: aborting due to previous error
810

src/test/ui/borrowck/borrowck-while-break.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `v`
33
|
44
LL | println!("{}", v);
55
| ^ use of possibly-uninitialized `v`
6+
|
7+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
68

79
error: aborting due to previous error
810

src/test/ui/borrowck/issue-24267-flow-exit.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error[E0381]: borrow of possibly-uninitialized variable: `x`
33
|
44
LL | println!("{}", x);
55
| ^ use of possibly-uninitialized `x`
6+
|
7+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
68

79
error[E0381]: borrow of possibly-uninitialized variable: `x`
810
--> $DIR/issue-24267-flow-exit.rs:18:20
911
|
1012
LL | println!("{}", x);
1113
| ^ use of possibly-uninitialized `x`
14+
|
15+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1216

1317
error: aborting due to 2 previous errors
1418

src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ LL | println!("{}", arr[3]);
8181
...
8282
LL | c();
8383
| - mutable borrow later used here
84+
|
85+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
8486

8587
error[E0502]: cannot borrow `arr` as immutable because it is also borrowed as mutable
8688
--> $DIR/arrays.rs:73:24

src/test/ui/closures/2229_closure_analysis/diagnostics/box.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ LL | println!("{}", e.0.0.m.x);
2525
LL |
2626
LL | c();
2727
| - mutable borrow later used here
28+
|
29+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
2830

2931
error[E0506]: cannot assign to `e.0.0.m.x` because it is borrowed
3032
--> $DIR/box.rs:55:5

src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ LL | println!("{}", foo.x);
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
1010
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
11+
= note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1112

1213
warning: 1 warning emitted
1314

0 commit comments

Comments
 (0)