Skip to content

Borrowed temporary dropped on nightly but works on stable #148427

Closed as not planned

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

Activity

  1. added
    C-bugCategory: This is a bug.
    on Nov 3, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 3, 2025
  3. Noratrieb commented on Nov 3, 2025

    @Noratrieb
    Member
  4. theemathas commented on Nov 3, 2025

    @theemathas
    Contributor

    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.

  5. added
    A-fmtArea: `core::fmt`
    T-langRelevant to the language team
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 3, 2025
  6. djc commented on Nov 3, 2025

    @djc
    ContributorAuthor

    @theemathas thanks for taking the time. Fixing rustup in

  7. dianne commented on Nov 3, 2025

    @dianne
    Member

    Oops, it looks like I missed temporary scopes from match arms when writing the future-compatibility warning. The lint fires if you change the match to an if expression. 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.

  8. theemathas commented on Nov 3, 2025

    @theemathas
    Contributor

    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.

  9. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 3, 2025
  10. traviscross commented on Nov 5, 2025

    @traviscross
    Contributor

    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

  11. added
    I-lang-radarItems that are on lang's radar and will need eventual work or consideration.
    and removed
    I-lang-nominatedNominated for discussion during a lang team meeting.
    on Nov 5, 2025
  12. theemathas commented on Nov 5, 2025

    @theemathas
    Contributor

    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

  13. dianne commented on Nov 5, 2025

    @dianne
    Member

    I can't speak to the release logistics, but it should be easy to implement at least.

  14. theemathas commented on Nov 6, 2025

    @theemathas
    Contributor

    Seems like T-compiler thinks it's not worth fixing the lint. See Zulip.

    Closing this issue, as there's nothing to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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