Skip to content

Commit

Permalink
refactor: replace &PathBuf with &Path to enhance generality
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech committed Dec 17, 2024
1 parent 978c659 commit 01bd99b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::fmt::Write as _;
use std::fs::{self, File};
use std::io::{self, IsTerminal, Read, Write};
use std::panic::{self, PanicHookInfo, catch_unwind};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::{self, Command, Stdio};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, OnceLock};
Expand Down Expand Up @@ -460,7 +460,7 @@ fn run_compiler(
})
}

fn dump_feature_usage_metrics(tcxt: TyCtxt<'_>, metrics_dir: &PathBuf) {
fn dump_feature_usage_metrics(tcxt: TyCtxt<'_>, metrics_dir: &Path) {
let output_filenames = tcxt.output_filenames(());
let mut metrics_file_name = std::ffi::OsString::from("unstable_feature_usage_metrics-");
let mut metrics_path = output_filenames.with_directory_and_extension(metrics_dir, "json");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ impl OutputFilenames {
self.with_directory_and_extension(&self.out_directory, extension)
}

pub fn with_directory_and_extension(&self, directory: &PathBuf, extension: &str) -> PathBuf {
pub fn with_directory_and_extension(&self, directory: &Path, extension: &str) -> PathBuf {
let mut path = directory.join(&self.filestem);
path.set_extension(extension);
path
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub fn setup(config: &Config, profile: Profile) {
setup_config_toml(path, profile, config);
}

fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
fn setup_config_toml(path: &Path, profile: Profile, config: &Config) {
if profile == Profile::None {
return;
}
Expand Down
10 changes: 4 additions & 6 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,7 @@ impl Config {
);

let channel = config
.read_file_by_commit(&PathBuf::from("src/ci/channel"), commit)
.read_file_by_commit(Path::new("src/ci/channel"), commit)
.trim()
.to_owned();

Expand Down Expand Up @@ -2383,12 +2383,10 @@ impl Config {
/// Return the version it would have used for the given commit.
pub(crate) fn artifact_version_part(&self, commit: &str) -> String {
let (channel, version) = if self.rust_info.is_managed_git_subrepository() {
let channel = self
.read_file_by_commit(&PathBuf::from("src/ci/channel"), commit)
.trim()
.to_owned();
let channel =
self.read_file_by_commit(Path::new("src/ci/channel"), commit).trim().to_owned();
let version =
self.read_file_by_commit(&PathBuf::from("src/version"), commit).trim().to_owned();
self.read_file_by_commit(Path::new("src/version"), commit).trim().to_owned();
(channel, version)
} else {
let channel = fs::read_to_string(self.src.join("src/ci/channel"));
Expand Down
4 changes: 2 additions & 2 deletions src/tools/compiletest/src/debuggers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;
use std::ffi::OsString;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::Arc;

Expand Down Expand Up @@ -141,7 +141,7 @@ pub(crate) fn extract_cdb_version(full_version_line: &str) -> Option<[u16; 4]> {
pub(crate) fn analyze_gdb(
gdb: Option<String>,
target: &str,
android_cross_path: &PathBuf,
android_cross_path: &Path,
) -> (Option<String>, Option<u32>) {
#[cfg(not(windows))]
const GDB_FALLBACK: &str = "gdb";
Expand Down
7 changes: 3 additions & 4 deletions src/tools/compiletest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,9 @@ pub fn collect_and_make_tests(config: Arc<Config>) -> Vec<test::TestDescAndFn> {
let mut collector =
TestCollector { tests: vec![], found_path_stems: HashSet::new(), poisoned: false };

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ impl<'test> TestCx<'test> {
})
}

fn delete_file(&self, file: &PathBuf) {
fn delete_file(&self, file: &Path) {
if !file.exists() {
// Deleting a nonexistent file would error.
return;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustc-perf-wrapper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn apply_shared_opts(cmd: &mut Command, opts: &SharedOpts) {
}
}

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

Expand Down
6 changes: 3 additions & 3 deletions src/tools/rustfmt/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ fn check_files(files: Vec<PathBuf>, opt_config: &Option<PathBuf>) -> (Vec<Format

debug!("Testing '{}'...", file_name.display());

match idempotent_check(&file_name, opt_config) {
match idempotent_check(&file_name, opt_config.as_deref()) {
Ok(ref report) if report.has_warnings() => {
print!("{}", FormatReportFormatterBuilder::new(report).build());
fails += 1;
Expand Down Expand Up @@ -775,8 +775,8 @@ fn get_editions_from_comments(
}

fn idempotent_check(
filename: &PathBuf,
opt_config: &Option<PathBuf>,
filename: &Path,
opt_config: Option<&Path>,
) -> Result<FormatReport, IdempotentCheckError> {
let sig_comments = read_significant_comments(filename);
let config = if let Some(ref config_file_path) = opt_config {
Expand Down

0 comments on commit 01bd99b

Please sign in to comment.