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

+4-1
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

+2
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

+2
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

+2
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

+2
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

+2
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

+4
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

+2
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

+2
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

+1
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

src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ LL | println!("{:?}", p);
1313
LL |
1414
LL | c();
1515
| - mutable borrow later used here
16+
|
17+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1618

1719
error: aborting due to previous error
1820

src/test/ui/codemap_tests/tab_3.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ note: this function takes ownership of the receiver `self`, which moves `some_ve
1414
|
1515
LL | fn into_iter(self) -> Self::IntoIter;
1616
| ^^^^
17+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1718

1819
error: aborting due to previous error
1920

src/test/ui/consts/const-eval/conditional_array_execution.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ LL | println!("{}", FOO);
2828
|
2929
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3030
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
31+
= note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
3132

3233
error: aborting due to previous error; 2 warnings emitted
3334

src/test/ui/consts/const-eval/issue-43197.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ LL | println!("{} {}", X, Y);
3939
|
4040
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4141
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
42+
= note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
4243

4344
error[E0080]: evaluation of constant value failed
4445
--> $DIR/issue-43197.rs:16:26
@@ -54,6 +55,7 @@ LL | println!("{} {}", X, Y);
5455
|
5556
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5657
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
58+
= note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
5759

5860
error: aborting due to 2 previous errors; 4 warnings emitted
5961

src/test/ui/generator/yield-while-ref-reborrowed.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ LL | println!("{}", x);
1010
| ^ second borrow occurs here
1111
LL | Pin::new(&mut b).resume(());
1212
| ------ first borrow later used here
13+
|
14+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1315

1416
error: aborting due to previous error
1517

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

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ LL | let mut s_copy = s;
88
...
99
LL | println!("{}", s);
1010
| ^ value borrowed here after move
11+
|
12+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1113

1214
error: aborting due to previous error
1315

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

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ LL | println!("{:?}", heap);
1212
...
1313
LL | };
1414
| - ... and the mutable borrow might be used here, when that temporary is dropped and runs the destructor for type `(Option<PeekMut<'_, i32>>, ())`
15+
|
16+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1517

1618
error: aborting due to previous error
1719

src/test/ui/limits/issue-55878.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
1818
= note: `#[deny(const_err)]` on by default
1919
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2020
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
21+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
2122

2223
error: aborting due to 2 previous errors
2324

src/test/ui/liveness/liveness-move-in-while.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ LL | println!("{}", y);
2828
| ^ value borrowed here after move
2929
LL | while true { while true { while true { x = y; x.clone(); } } }
3030
| - value moved here, in previous iteration of loop
31+
|
32+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
3133

3234
error: aborting due to previous error; 3 warnings emitted
3335

src/test/ui/liveness/liveness-use-after-move.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ LL | let y = x;
88
LL |
99
LL | println!("{}", *x);
1010
| ^^ value borrowed here after move
11+
|
12+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1113

1214
error: aborting due to previous error
1315

src/test/ui/liveness/liveness-use-after-send.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ LL | send(ch, message);
77
| ------- value moved here
88
LL | println!("{}", message);
99
| ^^^^^^^ value borrowed here after move
10+
|
11+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1012

1113
error: aborting due to previous error
1214

src/test/ui/loops/loop-proper-liveness.stderr

+2
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/moves/moves-based-on-type-capture-clause-bad.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ LL | println!("{}", x);
1010
LL | });
1111
LL | println!("{}", x);
1212
| ^ value borrowed here after move
13+
|
14+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1315

1416
error: aborting due to previous error
1517

src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ LL | ::std::mem::drop(x);
2121
LL | };
2222
LL | println!("{}", x);
2323
| ^ value borrowed here after move
24+
|
25+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
2426

2527
error[E0506]: cannot assign to `i` because it is borrowed
2628
--> $DIR/try-block-maybe-bad-lifetime.rs:40:9

src/test/ui/use/use-after-move-based-on-type.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ LL | let _y = x;
77
| - value moved here
88
LL | println!("{}", x);
99
| ^ value borrowed here after move
10+
|
11+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1012

1113
error: aborting due to previous error
1214

src/test/ui/walk-struct-literal-with.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ note: this function takes ownership of the receiver `self`, which moves `start`
1313
|
1414
LL | fn make_string_bar(mut self) -> Mine{
1515
| ^^^^
16+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
1617

1718
error: aborting due to previous error
1819

0 commit comments

Comments
 (0)