Skip to content

Commit 7eb0d84

Browse files
committed
refactor: replace &PathBuf with &Path to enhance generality
1 parent 978c659 commit 7eb0d84

File tree

8 files changed

+15
-18
lines changed

8 files changed

+15
-18
lines changed

compiler/rustc_driver_impl/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::fmt::Write as _;
2626
use std::fs::{self, File};
2727
use std::io::{self, IsTerminal, Read, Write};
2828
use std::panic::{self, PanicHookInfo, catch_unwind};
29-
use std::path::PathBuf;
29+
use std::path::{Path, PathBuf};
3030
use std::process::{self, Command, Stdio};
3131
use std::sync::atomic::{AtomicBool, Ordering};
3232
use std::sync::{Arc, OnceLock};
@@ -460,7 +460,7 @@ fn run_compiler(
460460
})
461461
}
462462

463-
fn dump_feature_usage_metrics(tcxt: TyCtxt<'_>, metrics_dir: &PathBuf) {
463+
fn dump_feature_usage_metrics(tcxt: TyCtxt<'_>, metrics_dir: &Path) {
464464
let output_filenames = tcxt.output_filenames(());
465465
let mut metrics_file_name = std::ffi::OsString::from("unstable_feature_usage_metrics-");
466466
let mut metrics_path = output_filenames.with_directory_and_extension(metrics_dir, "json");

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ impl OutputFilenames {
10761076
self.with_directory_and_extension(&self.out_directory, extension)
10771077
}
10781078

1079-
pub fn with_directory_and_extension(&self, directory: &PathBuf, extension: &str) -> PathBuf {
1079+
pub fn with_directory_and_extension(&self, directory: &Path, extension: &str) -> PathBuf {
10801080
let mut path = directory.join(&self.filestem);
10811081
path.set_extension(extension);
10821082
path

src/bootstrap/src/core/build_steps/setup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub fn setup(config: &Config, profile: Profile) {
209209
setup_config_toml(path, profile, config);
210210
}
211211

212-
fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
212+
fn setup_config_toml(path: &Path, profile: Profile, config: &Config) {
213213
if profile == Profile::None {
214214
return;
215215
}

src/bootstrap/src/core/config/config.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,7 @@ impl Config {
19421942
);
19431943

19441944
let channel = config
1945-
.read_file_by_commit(&PathBuf::from("src/ci/channel"), commit)
1945+
.read_file_by_commit(Path::new("src/ci/channel"), commit)
19461946
.trim()
19471947
.to_owned();
19481948

@@ -2383,12 +2383,10 @@ impl Config {
23832383
/// Return the version it would have used for the given commit.
23842384
pub(crate) fn artifact_version_part(&self, commit: &str) -> String {
23852385
let (channel, version) = if self.rust_info.is_managed_git_subrepository() {
2386-
let channel = self
2387-
.read_file_by_commit(&PathBuf::from("src/ci/channel"), commit)
2388-
.trim()
2389-
.to_owned();
2386+
let channel =
2387+
self.read_file_by_commit(Path::new("src/ci/channel"), commit).trim().to_owned();
23902388
let version =
2391-
self.read_file_by_commit(&PathBuf::from("src/version"), commit).trim().to_owned();
2389+
self.read_file_by_commit(Path::new("src/version"), commit).trim().to_owned();
23922390
(channel, version)
23932391
} else {
23942392
let channel = fs::read_to_string(self.src.join("src/ci/channel"));

src/tools/compiletest/src/debuggers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::env;
22
use std::ffi::OsString;
3-
use std::path::PathBuf;
3+
use std::path::{Path, PathBuf};
44
use std::process::Command;
55
use std::sync::Arc;
66

@@ -141,7 +141,7 @@ pub(crate) fn extract_cdb_version(full_version_line: &str) -> Option<[u16; 4]> {
141141
pub(crate) fn analyze_gdb(
142142
gdb: Option<String>,
143143
target: &str,
144-
android_cross_path: &PathBuf,
144+
android_cross_path: &Path,
145145
) -> (Option<String>, Option<u32>) {
146146
#[cfg(not(windows))]
147147
const GDB_FALLBACK: &str = "gdb";

src/tools/compiletest/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,9 @@ pub fn collect_and_make_tests(config: Arc<Config>) -> Vec<test::TestDescAndFn> {
598598
let mut collector =
599599
TestCollector { tests: vec![], found_path_stems: HashSet::new(), poisoned: false };
600600

601-
collect_tests_from_dir(&cx, &mut collector, &cx.config.src_base, &PathBuf::new())
602-
.unwrap_or_else(|reason| {
603-
panic!("Could not read tests from {}: {reason}", cx.config.src_base.display())
604-
});
601+
collect_tests_from_dir(&cx, &mut collector, &cx.config.src_base, Path::new("")).unwrap_or_else(
602+
|reason| panic!("Could not read tests from {}: {reason}", cx.config.src_base.display()),
603+
);
605604

606605
let TestCollector { tests, found_path_stems, poisoned } = collector;
607606

src/tools/compiletest/src/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ impl<'test> TestCx<'test> {
25602560
})
25612561
}
25622562

2563-
fn delete_file(&self, file: &PathBuf) {
2563+
fn delete_file(&self, file: &Path) {
25642564
if !file.exists() {
25652565
// Deleting a nonexistent file would error.
25662566
return;

src/tools/rustc-perf-wrapper/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn apply_shared_opts(cmd: &mut Command, opts: &SharedOpts) {
163163
}
164164
}
165165

166-
fn execute_benchmark(cmd: &mut Command, compiler: &PathBuf) {
166+
fn execute_benchmark(cmd: &mut Command, compiler: &Path) {
167167
cmd.arg(compiler);
168168
println!("Running `rustc-perf` using `{}`", compiler.display());
169169

0 commit comments

Comments
 (0)