From 4cfb7add771367757ee2dd26da4e29d333c93cb6 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 21 Oct 2021 09:01:16 -0500 Subject: [PATCH] Fix a format_args span to be expansion --- compiler/rustc_builtin_macros/src/format.rs | 5 ++++- src/test/ui/borrowck/borrowck-and-init.stderr | 2 ++ src/test/ui/borrowck/borrowck-break-uninit-2.stderr | 2 ++ src/test/ui/borrowck/borrowck-break-uninit.stderr | 2 ++ src/test/ui/borrowck/borrowck-or-init.stderr | 2 ++ src/test/ui/borrowck/borrowck-while-break.stderr | 2 ++ src/test/ui/borrowck/issue-24267-flow-exit.stderr | 4 ++++ .../closures/2229_closure_analysis/diagnostics/arrays.stderr | 2 ++ .../ui/closures/2229_closure_analysis/diagnostics/box.stderr | 2 ++ .../2229_closure_analysis/diagnostics/repr_packed.stderr | 1 + .../diagnostics/simple-struct-min-capture.stderr | 2 ++ src/test/ui/codemap_tests/tab_3.stderr | 1 + .../ui/consts/const-eval/conditional_array_execution.stderr | 1 + src/test/ui/consts/const-eval/issue-43197.stderr | 2 ++ src/test/ui/generator/yield-while-ref-reborrowed.stderr | 2 ++ src/test/ui/issues/issue-42796.stderr | 2 ++ src/test/ui/issues/issue-47646.stderr | 2 ++ src/test/ui/limits/issue-55878.stderr | 1 + src/test/ui/liveness/liveness-move-in-while.stderr | 2 ++ src/test/ui/liveness/liveness-use-after-move.stderr | 2 ++ src/test/ui/liveness/liveness-use-after-send.stderr | 2 ++ src/test/ui/loops/loop-proper-liveness.stderr | 2 ++ .../ui/moves/moves-based-on-type-capture-clause-bad.stderr | 2 ++ src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr | 2 ++ src/test/ui/use/use-after-move-based-on-type.stderr | 2 ++ src/test/ui/walk-struct-literal-with.stderr | 1 + 26 files changed, 51 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index f0056cb79766a..3f9ea371583be 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -793,7 +793,10 @@ impl<'a, 'b> Context<'a, 'b> { for arg_ty in self.arg_unique_types[i].iter() { locals.push(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty, name)); } - heads.push(self.ecx.expr_addr_of(e.span, e)); + // use the arg span for `&arg` so that borrowck errors + // point to the specific expression passed to the macro + // (the span is otherwise unavailable in MIR) + heads.push(self.ecx.expr_addr_of(e.span.with_ctxt(self.macsp.ctxt()), e)); } for pos in self.count_args { let index = match pos { diff --git a/src/test/ui/borrowck/borrowck-and-init.stderr b/src/test/ui/borrowck/borrowck-and-init.stderr index c7e357d4604f7..d2c7473c036b8 100644 --- a/src/test/ui/borrowck/borrowck-and-init.stderr +++ b/src/test/ui/borrowck/borrowck-and-init.stderr @@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `i` | LL | println!("{}", i); | ^ use of possibly-uninitialized `i` + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-break-uninit-2.stderr b/src/test/ui/borrowck/borrowck-break-uninit-2.stderr index bc9b25c0221fc..b134f5cc2d8e3 100644 --- a/src/test/ui/borrowck/borrowck-break-uninit-2.stderr +++ b/src/test/ui/borrowck/borrowck-break-uninit-2.stderr @@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `x` | LL | println!("{}", x); | ^ use of possibly-uninitialized `x` + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-break-uninit.stderr b/src/test/ui/borrowck/borrowck-break-uninit.stderr index 766d5cfd6348c..652d7d3076fbd 100644 --- a/src/test/ui/borrowck/borrowck-break-uninit.stderr +++ b/src/test/ui/borrowck/borrowck-break-uninit.stderr @@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `x` | LL | println!("{}", x); | ^ use of possibly-uninitialized `x` + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-or-init.stderr b/src/test/ui/borrowck/borrowck-or-init.stderr index 3fe8d9eededc5..6c757759f7134 100644 --- a/src/test/ui/borrowck/borrowck-or-init.stderr +++ b/src/test/ui/borrowck/borrowck-or-init.stderr @@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `i` | LL | println!("{}", i); | ^ use of possibly-uninitialized `i` + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-while-break.stderr b/src/test/ui/borrowck/borrowck-while-break.stderr index 3eaaf8d7df08d..fc144a066bb27 100644 --- a/src/test/ui/borrowck/borrowck-while-break.stderr +++ b/src/test/ui/borrowck/borrowck-while-break.stderr @@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `v` | LL | println!("{}", v); | ^ use of possibly-uninitialized `v` + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/borrowck/issue-24267-flow-exit.stderr b/src/test/ui/borrowck/issue-24267-flow-exit.stderr index 4eb41ca24ddfe..e29cf7a1a7519 100644 --- a/src/test/ui/borrowck/issue-24267-flow-exit.stderr +++ b/src/test/ui/borrowck/issue-24267-flow-exit.stderr @@ -3,12 +3,16 @@ error[E0381]: borrow of possibly-uninitialized variable: `x` | LL | println!("{}", x); | ^ use of possibly-uninitialized `x` + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0381]: borrow of possibly-uninitialized variable: `x` --> $DIR/issue-24267-flow-exit.rs:18:20 | LL | println!("{}", x); | ^ use of possibly-uninitialized `x` + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.stderr index a3f2f25e447e1..f6c2190183211 100644 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.stderr +++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/arrays.stderr @@ -81,6 +81,8 @@ LL | println!("{}", arr[3]); ... LL | c(); | - mutable borrow later used here + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0502]: cannot borrow `arr` as immutable because it is also borrowed as mutable --> $DIR/arrays.rs:73:24 diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/box.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/box.stderr index 2badf0514187e..29228d85324ef 100644 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/box.stderr +++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/box.stderr @@ -25,6 +25,8 @@ LL | println!("{}", e.0.0.m.x); LL | LL | c(); | - mutable borrow later used here + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0506]: cannot assign to `e.0.0.m.x` because it is borrowed --> $DIR/box.rs:55:5 diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr index d2466681a0877..5acf3797ab53f 100644 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr +++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr @@ -8,6 +8,7 @@ LL | println!("{}", foo.x); = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #82523 = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) + = note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) warning: 1 warning emitted diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.stderr index 32705af3d0166..4f9fdbd368a88 100644 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.stderr +++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/simple-struct-min-capture.stderr @@ -13,6 +13,8 @@ LL | println!("{:?}", p); LL | LL | c(); | - mutable borrow later used here + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/codemap_tests/tab_3.stderr b/src/test/ui/codemap_tests/tab_3.stderr index e067dbbf85bdd..ceb91142ac826 100644 --- a/src/test/ui/codemap_tests/tab_3.stderr +++ b/src/test/ui/codemap_tests/tab_3.stderr @@ -14,6 +14,7 @@ note: this function takes ownership of the receiver `self`, which moves `some_ve | LL | fn into_iter(self) -> Self::IntoIter; | ^^^^ + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/consts/const-eval/conditional_array_execution.stderr b/src/test/ui/consts/const-eval/conditional_array_execution.stderr index 356a7f58d8562..9dc40030a6ff8 100644 --- a/src/test/ui/consts/const-eval/conditional_array_execution.stderr +++ b/src/test/ui/consts/const-eval/conditional_array_execution.stderr @@ -28,6 +28,7 @@ LL | println!("{}", FOO); | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 + = note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error; 2 warnings emitted diff --git a/src/test/ui/consts/const-eval/issue-43197.stderr b/src/test/ui/consts/const-eval/issue-43197.stderr index d4d8cbc669a7b..32ab7c74b891f 100644 --- a/src/test/ui/consts/const-eval/issue-43197.stderr +++ b/src/test/ui/consts/const-eval/issue-43197.stderr @@ -39,6 +39,7 @@ LL | println!("{} {}", X, Y); | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 + = note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0080]: evaluation of constant value failed --> $DIR/issue-43197.rs:16:26 @@ -54,6 +55,7 @@ LL | println!("{} {}", X, Y); | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 + = note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors; 4 warnings emitted diff --git a/src/test/ui/generator/yield-while-ref-reborrowed.stderr b/src/test/ui/generator/yield-while-ref-reborrowed.stderr index 68d785efcfe5d..67cd1f64d94aa 100644 --- a/src/test/ui/generator/yield-while-ref-reborrowed.stderr +++ b/src/test/ui/generator/yield-while-ref-reborrowed.stderr @@ -10,6 +10,8 @@ LL | println!("{}", x); | ^ second borrow occurs here LL | Pin::new(&mut b).resume(()); | ------ first borrow later used here + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/issues/issue-42796.stderr b/src/test/ui/issues/issue-42796.stderr index 61cf3f25d0d07..4a1debf37a079 100644 --- a/src/test/ui/issues/issue-42796.stderr +++ b/src/test/ui/issues/issue-42796.stderr @@ -8,6 +8,8 @@ LL | let mut s_copy = s; ... LL | println!("{}", s); | ^ value borrowed here after move + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/issues/issue-47646.stderr b/src/test/ui/issues/issue-47646.stderr index eff1de3e01752..32e8588b3c074 100644 --- a/src/test/ui/issues/issue-47646.stderr +++ b/src/test/ui/issues/issue-47646.stderr @@ -12,6 +12,8 @@ LL | println!("{:?}", heap); ... LL | }; | - ... and the mutable borrow might be used here, when that temporary is dropped and runs the destructor for type `(Option>, ())` + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/limits/issue-55878.stderr b/src/test/ui/limits/issue-55878.stderr index a7e382479021a..90411353f0825 100644 --- a/src/test/ui/limits/issue-55878.stderr +++ b/src/test/ui/limits/issue-55878.stderr @@ -18,6 +18,7 @@ LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>()); = note: `#[deny(const_err)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/src/test/ui/liveness/liveness-move-in-while.stderr b/src/test/ui/liveness/liveness-move-in-while.stderr index 6a8f239bd09a8..ff6c02f2110f6 100644 --- a/src/test/ui/liveness/liveness-move-in-while.stderr +++ b/src/test/ui/liveness/liveness-move-in-while.stderr @@ -28,6 +28,8 @@ LL | println!("{}", y); | ^ value borrowed here after move LL | while true { while true { while true { x = y; x.clone(); } } } | - value moved here, in previous iteration of loop + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error; 3 warnings emitted diff --git a/src/test/ui/liveness/liveness-use-after-move.stderr b/src/test/ui/liveness/liveness-use-after-move.stderr index 292ce013dcc76..df54af9f0f2ce 100644 --- a/src/test/ui/liveness/liveness-use-after-move.stderr +++ b/src/test/ui/liveness/liveness-use-after-move.stderr @@ -8,6 +8,8 @@ LL | let y = x; LL | LL | println!("{}", *x); | ^^ value borrowed here after move + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/liveness/liveness-use-after-send.stderr b/src/test/ui/liveness/liveness-use-after-send.stderr index 50ae98ca9bedc..becede1ceb6b3 100644 --- a/src/test/ui/liveness/liveness-use-after-send.stderr +++ b/src/test/ui/liveness/liveness-use-after-send.stderr @@ -7,6 +7,8 @@ LL | send(ch, message); | ------- value moved here LL | println!("{}", message); | ^^^^^^^ value borrowed here after move + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/loops/loop-proper-liveness.stderr b/src/test/ui/loops/loop-proper-liveness.stderr index d55f9ff31e3ee..20d5c66a3f205 100644 --- a/src/test/ui/loops/loop-proper-liveness.stderr +++ b/src/test/ui/loops/loop-proper-liveness.stderr @@ -3,6 +3,8 @@ error[E0381]: borrow of possibly-uninitialized variable: `x` | LL | println!("{:?}", x); | ^ use of possibly-uninitialized `x` + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/moves/moves-based-on-type-capture-clause-bad.stderr b/src/test/ui/moves/moves-based-on-type-capture-clause-bad.stderr index acb0932f6d6b9..ac921c18e07d5 100644 --- a/src/test/ui/moves/moves-based-on-type-capture-clause-bad.stderr +++ b/src/test/ui/moves/moves-based-on-type-capture-clause-bad.stderr @@ -10,6 +10,8 @@ LL | println!("{}", x); LL | }); LL | println!("{}", x); | ^ value borrowed here after move + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr b/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr index c092aa26946f6..d6822d94ca8c9 100644 --- a/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr +++ b/src/test/ui/try-block/try-block-maybe-bad-lifetime.stderr @@ -21,6 +21,8 @@ LL | ::std::mem::drop(x); LL | }; LL | println!("{}", x); | ^ value borrowed here after move + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0506]: cannot assign to `i` because it is borrowed --> $DIR/try-block-maybe-bad-lifetime.rs:40:9 diff --git a/src/test/ui/use/use-after-move-based-on-type.stderr b/src/test/ui/use/use-after-move-based-on-type.stderr index 11ce005bb457c..361a6e2d8c278 100644 --- a/src/test/ui/use/use-after-move-based-on-type.stderr +++ b/src/test/ui/use/use-after-move-based-on-type.stderr @@ -7,6 +7,8 @@ LL | let _y = x; | - value moved here LL | println!("{}", x); | ^ value borrowed here after move + | + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/walk-struct-literal-with.stderr b/src/test/ui/walk-struct-literal-with.stderr index cda08b0f4e09c..377a807445891 100644 --- a/src/test/ui/walk-struct-literal-with.stderr +++ b/src/test/ui/walk-struct-literal-with.stderr @@ -13,6 +13,7 @@ note: this function takes ownership of the receiver `self`, which moves `start` | LL | fn make_string_bar(mut self) -> Mine{ | ^^^^ + = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error