Skip to content

Commit 6db6210

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

File tree

1 file changed

+15
-5
lines changed
  • std/src/sys/pal/unix

1 file changed

+15
-5
lines changed

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)]

0 commit comments

Comments
 (0)