Skip to content

Borrowed temporary dropped on nightly but works on stable #148427

@djc

Description

@djc

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 value

I 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-fmtArea: `core::fmt`A-temporary-lifetime-extensionArea: temporary lifetime extensionC-bugCategory: This is a bug.F-super_letit's super, let's go!I-lang-radarItems 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.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions