Skip to content

Commit e510971

Browse files
committed
Convert Vec<&Path> arguments to Vec<PathBuf>
1 parent 437d9be commit e510971

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Diff for: src/bootstrap/src/core/builder.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl PathSet {
274274
/// This is used for `StepDescription::krate`, which passes all matching crates at once to
275275
/// `Step::make_run`, rather than calling it many times with a single crate.
276276
/// See `tests.rs` for examples.
277-
fn intersection_removing_matches(&self, needles: &mut Vec<&Path>, module: Kind) -> PathSet {
277+
fn intersection_removing_matches(&self, needles: &mut Vec<PathBuf>, module: Kind) -> PathSet {
278278
let mut check = |p| {
279279
for (i, n) in needles.iter().enumerate() {
280280
let matched = Self::check(p, n, module);
@@ -346,7 +346,7 @@ const PATH_REMAP: &[(&str, &[&str])] = &[
346346
),
347347
];
348348

349-
fn remap_paths(paths: &mut Vec<&Path>) {
349+
fn remap_paths(paths: &mut Vec<PathBuf>) {
350350
let mut remove = vec![];
351351
let mut add = vec![];
352352
for (i, path) in paths.iter().enumerate().filter_map(|(i, path)| path.to_str().map(|s| (i, s)))
@@ -355,7 +355,7 @@ fn remap_paths(paths: &mut Vec<&Path>) {
355355
// Remove leading and trailing slashes so `tests/` and `tests` are equivalent
356356
if path.trim_matches(std::path::is_separator) == search {
357357
remove.push(i);
358-
add.extend(replace.iter().map(Path::new));
358+
add.extend(replace.iter().map(PathBuf::from));
359359
break;
360360
}
361361
}
@@ -439,7 +439,7 @@ impl StepDescription {
439439
}
440440

441441
// Attempt to resolve paths to be relative to the builder source directory.
442-
let paths: Vec<_> = paths
442+
let mut paths: Vec<PathBuf> = paths
443443
.iter()
444444
.map(|p| {
445445
// If the path does not exist, it may represent the name of a Step, such as `tidy` in `x test tidy`
@@ -458,9 +458,6 @@ impl StepDescription {
458458
})
459459
.collect();
460460

461-
// Convert Vec<PathBuf> to `Vec<&Path>`
462-
let mut paths: Vec<&Path> = paths.iter().map(|p| p.as_ref()).collect();
463-
464461
remap_paths(&mut paths);
465462

466463
// Handle all test suite paths.
@@ -649,7 +646,7 @@ impl<'a> ShouldRun<'a> {
649646
/// (for now, just `all_krates` and `paths`, but we may want to add an `aliases` function in the future?)
650647
fn pathset_for_paths_removing_matches(
651648
&self,
652-
paths: &mut Vec<&Path>,
649+
paths: &mut Vec<PathBuf>,
653650
kind: Kind,
654651
) -> Vec<PathSet> {
655652
let mut sets = vec![];

Diff for: src/bootstrap/src/core/builder/tests.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,14 @@ fn test_intersection() {
122122
PathSet::Set(paths.into_iter().map(|p| TaskPath { path: p.into(), kind: None }).collect())
123123
};
124124
let library_set = set(&["library/core", "library/alloc", "library/std"]);
125-
let mut command_paths =
126-
vec![Path::new("library/core"), Path::new("library/alloc"), Path::new("library/stdarch")];
125+
let mut command_paths = vec![
126+
PathBuf::from("library/core"),
127+
PathBuf::from("library/alloc"),
128+
PathBuf::from("library/stdarch"),
129+
];
127130
let subset = library_set.intersection_removing_matches(&mut command_paths, Kind::Build);
128131
assert_eq!(subset, set(&["library/core", "library/alloc"]),);
129-
assert_eq!(command_paths, vec![Path::new("library/stdarch")]);
132+
assert_eq!(command_paths, vec![PathBuf::from("library/stdarch")]);
130133
}
131134

132135
#[test]

0 commit comments

Comments
 (0)