Repository navigation
Borrowed temporary dropped on nightly but works on stable #148427
Copy link
Copy link
Closed as not planned
Labels
A-fmtArea: `core::fmt`Area: `core::fmt`A-temporary-lifetime-extensionArea: temporary lifetime extensionArea: temporary lifetime extensionC-bugCategory: This is a bug.Category: This is a bug.F-super_letit's super, let's go!it's super, let's go!I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Description
I tried this code:
writeln!(
cfg.process.stdout().lock(),
"{} ({})",
toolchain.name(),
match source {
ActiveSource::Default => &"default" as &dyn fmt::Display,
_ => &source.to_reason(),
}
)?;This compiles on stable (1.91). However, current nightly fails:
error[E0716]: temporary value dropped while borrowed
--> src/cli/rustup_mode.rs:1225:31
|
1223 | / match source {
1224 | | ActiveSource::Default => &"default" as &dyn fmt::Display,
1225 | | _ => &source.to_reason(),
| | ^^^^^^^^^^^^^^^^^-
| | | |
| | | temporary value is freed at the end of this statement
| | creates a temporary value which is freed while still in use
1226 | | }
| |_____________________- borrow later used here
|
= note: consider using a `let` binding to create a longer lived valueI tried to make a minimal reproduction but this playground fails on stable, too.
Meta
nightly:
rustc 1.93.0-nightly (b15a874aa 2025-11-02)
binary: rustc
commit-hash: b15a874aafe7eab9ea3ac2c1d59c7b03e1425027
commit-date: 2025-11-02
host: aarch64-apple-darwin
release: 1.93.0-nightly
LLVM version: 21.1.3
rustc --version --verbose:
rustc 1.91.0 (f8297e351 2025-10-28)
binary: rustc
commit-hash: f8297e351a40c1439a467bbbb6879088047f50b3
commit-date: 2025-10-28
host: aarch64-apple-darwin
release: 1.91.0
LLVM version: 21.1.2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-fmtArea: `core::fmt`Area: `core::fmt`A-temporary-lifetime-extensionArea: temporary lifetime extensionArea: temporary lifetime extensionC-bugCategory: This is a bug.Category: This is a bug.F-super_letit's super, let's go!it's super, let's go!I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Activity
Noratrieb commentedon Nov 3, 2025
@dianne
theemathas commentedon Nov 3, 2025
Minimal reproduction: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=47622718fd479b14b67f431c8515f951
There has to be at least two things being formatted in the macro for this weirdness to happen, and they must not be one of the things that get optimized by the compiler into part of the format string.
This code is supposed to produce this warning in stable, but for some reason the warning didn't fire. The warning was added in #147056.
The code currently compiles in stable due to a bug, that is intended to be fixed in version 1.92, making the code not compile.
djc commentedon Nov 3, 2025
@theemathas thanks for taking the time. Fixing rustup in
dianne commentedon Nov 3, 2025
Oops, it looks like I missed temporary scopes from
matcharms when writing the future-compatibility warning. The lint fires if you change thematchto anifexpression. Unfortunately, unless the fix for #145784 is pushed back to 1.93, I'm not sure much can be done, since it is indeed intentional breakage.theemathas commentedon Nov 3, 2025
Lang-nominating to reconfirm whether to continue with this intended breakage in 1.92, given that the FCW for it in 1.91 was incomplete.
traviscross commentedon Nov 5, 2025
Thanks for raising this for lang attention.
In this case, we accepted the breakage to happen directly. We weren't even expecting there to be an FCW. My own procedural analysis here is that this consequently does not need further confirmation.
(If someone on lang wants to raise it for reconsideration, of course feel free to do so.)
cc @rust-lang/lang
theemathas commentedon Nov 5, 2025
It seems like there's going to be a 1.91.1 release. Is it feasible / reasonable / beneficial to get a fix to the lint in that release? @dianne
dianne commentedon Nov 5, 2025
I can't speak to the release logistics, but it should be easy to implement at least.
theemathas commentedon Nov 6, 2025
Seems like T-compiler thinks it's not worth fixing the lint. See Zulip.
Closing this issue, as there's nothing to be done.