Skip to content

env::split_paths regression in nightly-2025-08-31 #146045

@dtolnay

Description

@dtolnay

This code used to compile in previous stable releases and nightlies prior to nightly-2025-08-31. After #145242, it no longer compiles, which seems unintended.

pub fn repro() -> Option<std::path::PathBuf> {
    let unparsed = std::ffi::OsString::new();
    std::env::split_paths(&unparsed).next()
}

rustc --crate-type=lib --edition=2021 --target=x86_64-unknown-linux-gnu repro.rs

error[E0597]: `unparsed` does not live long enough
 --> repro.rs:3:27
  |
2 |     let unparsed = std::ffi::OsString::new();
  |         -------- binding `unparsed` declared here
3 |     std::env::split_paths(&unparsed).next()
  |     ----------------------^^^^^^^^^-
  |     |                     |
  |     |                     borrowed value does not live long enough
  |     a temporary with access to the borrow is created here ...
4 | }
  | -
  | |
  | `unparsed` dropped here while still borrowed
  | ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `SplitPaths<'_>`
  |
  = note: the temporary is part of an expression at the end of a block;
          consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
  |
3 |     let x = std::env::split_paths(&unparsed).next(); x
  |     +++++++                                        +++

The regression only occurs if building for both a unix target platforms and an edition older than 2024. It does not reproduce in non-unix platforms (--target=x86_64-pc-windows-mscv) nor 2024 edition (--edition=2024).

@joboet

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-unixOperating system: Unix-likeS-has-bisectionStatus: A bisection has been found for this issueT-libsRelevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions