From 6ab240d3299b4b6953dc8140f1f40d62beee7fab Mon Sep 17 00:00:00 2001 From: Theemathas Chirananthavat Date: Mon, 27 Oct 2025 21:49:39 +0700 Subject: [PATCH] [beta-1.91] Add more context to the temporary lifetime extension FCW Mention in the FCW that the lifetime extension behavior was wrong since 1.88/1.89. --- compiler/rustc_borrowck/src/diagnostics/mod.rs | 1 + .../extended-super-let-bindings.stderr | 1 + .../macro-extended-temporary-scopes.e2021.stderr | 7 +++++++ .../macro-extended-temporary-scopes.e2024.stderr | 15 +++++++++++++++ .../user-defined-macros.stderr | 4 ++++ 5 files changed, 28 insertions(+) diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index e85945d633b6..3827c7268c22 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -1607,6 +1607,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { tcx.node_span_lint(MACRO_EXTENDED_TEMPORARY_SCOPES, lint_root, labels, |diag| { diag.primary_message("temporary lifetime will be shortened in Rust 1.92"); diag.note("consider using a `let` binding to create a longer lived value"); + diag.note("some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()`"); }); } } diff --git a/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/extended-super-let-bindings.stderr b/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/extended-super-let-bindings.stderr index 4dee6f4fc321..038839eb9240 100644 --- a/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/extended-super-let-bindings.stderr +++ b/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/extended-super-let-bindings.stderr @@ -9,6 +9,7 @@ LL | println!("{:?}{}", (), { format_args!("{:?}", ()) }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` = note: `#[warn(macro_extended_temporary_scopes)]` (part of `#[warn(future_incompatible)]`) on by default warning: 1 warning emitted diff --git a/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/macro-extended-temporary-scopes.e2021.stderr b/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/macro-extended-temporary-scopes.e2021.stderr index c7a7e1b3238e..1c890daeaa52 100644 --- a/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/macro-extended-temporary-scopes.e2021.stderr +++ b/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/macro-extended-temporary-scopes.e2021.stderr @@ -9,6 +9,7 @@ LL | println!("{:?}{:?}", (), if cond() { &format!("") } else { "" }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` = note: `#[warn(macro_extended_temporary_scopes)]` (part of `#[warn(future_incompatible)]`) on by default = note: this warning originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -23,6 +24,7 @@ LL | println!("{:?}{:?}", (), if cond() { &"".to_string() } else { "" }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:39:43 @@ -35,6 +37,7 @@ LL | println!("{:?}{:?}", (), if cond() { &("string".to_owned() + "string") = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:58:17 @@ -48,6 +51,7 @@ LL | } = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:54:14 @@ -61,6 +65,7 @@ LL | } else { = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:50:14 @@ -74,6 +79,7 @@ LL | } else if cond() { = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:46:14 @@ -87,6 +93,7 @@ LL | } else if cond() { = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: 7 warnings emitted diff --git a/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/macro-extended-temporary-scopes.e2024.stderr b/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/macro-extended-temporary-scopes.e2024.stderr index 0c61fd8d1b0e..bd086e08956f 100644 --- a/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/macro-extended-temporary-scopes.e2024.stderr +++ b/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/macro-extended-temporary-scopes.e2024.stderr @@ -9,6 +9,7 @@ LL | println!("{:?}{:?}", { &temp() }, ()); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` = note: `#[warn(macro_extended_temporary_scopes)]` (part of `#[warn(future_incompatible)]`) on by default warning: temporary lifetime will be shortened in Rust 1.92 @@ -22,6 +23,7 @@ LL | println!("{:?}{:?}", (), if cond() { &format!("") } else { "" }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` = note: this warning originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info) warning: temporary lifetime will be shortened in Rust 1.92 @@ -35,6 +37,7 @@ LL | println!("{:?}{:?}", (), if cond() { &"".to_string() } else { "" }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:39:43 @@ -47,6 +50,7 @@ LL | println!("{:?}{:?}", (), if cond() { &("string".to_owned() + "string") = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:58:17 @@ -60,6 +64,7 @@ LL | } = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:54:14 @@ -73,6 +78,7 @@ LL | } else { = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:50:14 @@ -86,6 +92,7 @@ LL | } else if cond() { = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:46:14 @@ -99,6 +106,7 @@ LL | } else if cond() { = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:65:18 @@ -111,6 +119,7 @@ LL | pin!(pin!({ &temp() })); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:96:13 @@ -123,6 +132,7 @@ LL | pin!({ &(1 / 0) }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:99:17 @@ -135,6 +145,7 @@ LL | pin!({ &mut [()] }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:102:13 @@ -147,6 +158,7 @@ LL | pin!({ &Some(String::new()) }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:105:13 @@ -159,6 +171,7 @@ LL | pin!({ &(|| ())() }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:108:13 @@ -171,6 +184,7 @@ LL | pin!({ &|| &local }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/macro-extended-temporary-scopes.rs:111:13 @@ -183,6 +197,7 @@ LL | pin!({ &CONST_STRING }); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: 15 warnings emitted diff --git a/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/user-defined-macros.stderr b/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/user-defined-macros.stderr index b4996952f4f1..313f7a663815 100644 --- a/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/user-defined-macros.stderr +++ b/tests/ui/lifetimes/lint-macro-extended-temporary-scopes/user-defined-macros.stderr @@ -10,6 +10,7 @@ LL | wrap!(String::new()) = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` = note: `#[warn(macro_extended_temporary_scopes)]` (part of `#[warn(future_incompatible)]`) on by default warning: temporary lifetime will be shortened in Rust 1.92 @@ -27,6 +28,7 @@ LL | print_with_internal_wrap!(); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` = note: this warning originates in the macro `print_with_internal_wrap` (in Nightly builds, run with -Z macro-backtrace for more info) warning: temporary lifetime will be shortened in Rust 1.92 @@ -41,6 +43,7 @@ LL | external_macros::wrap!(String::new()) = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` warning: temporary lifetime will be shortened in Rust 1.92 --> $DIR/user-defined-macros.rs:52:5 @@ -54,6 +57,7 @@ LL | external_macros::print_with_internal_wrap!(); = 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 = note: consider using a `let` binding to create a longer lived value + = note: some temporaries were previously incorrectly lifetime-extended since Rust 1.89 in formatting macros, and since Rust 1.88 in `pin!()` = note: this warning originates in the macro `external_macros::print_with_internal_wrap` (in Nightly builds, run with -Z macro-backtrace for more info) warning: 4 warnings emitted