Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f73bcd5

Browse files
committed
Auto merge of #146053 - joboet:split-paths-regression, r=Mark-Simulacrum
std: fix `SplitPaths` regression Fixes #146045 by defining the TAIT more precisely, ensuring that `'a` does not need to be live on drop.
2 parents 564ee21 + 6d8d952 commit f73bcd5

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

‎library/std/src/sys/pal/unix/os.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,24 @@ pub fn chdir(p: &path::Path) -> io::Result<()> {
186186
if result == 0 { Ok(()) } else { Err(io::Error::last_os_error()) }
187187
}
188188

189-
pub type SplitPaths<'a> = impl Iterator<Item = PathBuf>;
189+
// This can't just be `impl Iterator` because that requires `'a` to be live on
190+
// drop (see #146045).
191+
pub type SplitPaths<'a> = iter::Map<
192+
slice::Split<'a, u8, impl FnMut(&u8) -> bool + 'static>,
193+
impl FnMut(&[u8]) -> PathBuf + 'static,
194+
>;
190195

191196
#[define_opaque(SplitPaths)]
192197
pub fn split_paths(unparsed: &OsStr) -> SplitPaths<'_> {
193-
unparsed
194-
.as_bytes()
195-
.split(|&b| b == PATH_SEPARATOR)
196-
.map(|part| PathBuf::from(OsStr::from_bytes(part)))
198+
fn is_separator(&b: &u8) -> bool {
199+
b == PATH_SEPARATOR
200+
}
201+
202+
fn into_pathbuf(part: &[u8]) -> PathBuf {
203+
PathBuf::from(OsStr::from_bytes(part))
204+
}
205+
206+
unparsed.as_bytes().split(is_separator).map(into_pathbuf)
197207
}
198208

199209
#[derive(Debug)]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Regression test for issue #146045 - ensure that the TAIT `SplitPaths` does not
2+
// require the borrowed string to be live.
3+
//@ check-pass
4+
//@ edition:2015
5+
6+
pub fn repro() -> Option<std::path::PathBuf> {
7+
let unparsed = std::ffi::OsString::new();
8+
std::env::split_paths(&unparsed).next()
9+
}
10+
11+
fn main() {}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /