[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.
This commit is contained in:
Theemathas Chirananthavat
2025-10-27 21:49:39 +07:00
parent f2f881bb99
commit 6ab240d329
5 changed files with 28 additions and 0 deletions

View File

@@ -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!()`");
});
}
}

View File

@@ -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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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

View File

@@ -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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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

View File

@@ -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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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

View File

@@ -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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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 <https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#macro-extended-temporary-scopes>
= 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