Skip to content

Commit 2495248

Browse files
committed
Fix unused qualifications in runfiles
1 parent e0c8ac2 commit 2495248

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

rust/runfiles/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ rust_library(
99
name = "runfiles",
1010
srcs = ["runfiles.rs"],
1111
edition = "2018",
12+
rustc_flags = ["-Dunused-qualifications"],
1213
visibility = ["//visibility:public"],
1314
)
1415

1516
rust_test(
1617
name = "runfiles_test",
1718
crate = ":runfiles",
1819
data = ["data/sample.txt"],
20+
rustc_flags = ["-Dunused-qualifications"],
1921
)
2022

2123
rust_doc(

rust/runfiles/runfiles.rs

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
3333
use std::collections::{BTreeMap, HashMap};
3434
use std::env;
35+
use std::fmt;
3536
use std::fs;
3637
use std::io;
3738
use std::path::Path;
@@ -83,8 +84,8 @@ pub enum RunfilesError {
8384
RunfileIoError(io::Error),
8485
}
8586

86-
impl std::fmt::Display for RunfilesError {
87-
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
87+
impl fmt::Display for RunfilesError {
88+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8889
match self {
8990
RunfilesError::RunfilesDirNotFound => write!(f, "RunfilesDirNotFound"),
9091
RunfilesError::RunfilesDirIoError(err) => write!(f, "RunfilesDirIoError: {:?}", err),
@@ -200,7 +201,7 @@ impl Runfiles {
200201
/// environment variable is present, with an non-empty value, or a directory
201202
/// based Runfiles object otherwise.
202203
pub fn create() -> Result<Self> {
203-
let mode = match std::env::var_os(MANIFEST_FILE_ENV_VAR) {
204+
let mode = match env::var_os(MANIFEST_FILE_ENV_VAR) {
204205
Some(manifest_file) if !manifest_file.is_empty() => {
205206
Self::create_manifest_based(Path::new(&manifest_file))?
206207
}
@@ -227,8 +228,8 @@ impl Runfiles {
227228
}
228229

229230
fn create_manifest_based(manifest_path: &Path) -> Result<Mode> {
230-
let manifest_content = std::fs::read_to_string(manifest_path)
231-
.map_err(RunfilesError::RunfilesManifestIoError)?;
231+
let manifest_content =
232+
fs::read_to_string(manifest_path).map_err(RunfilesError::RunfilesManifestIoError)?;
232233
let path_mapping = manifest_content
233234
.lines()
234235
.flat_map(|line| {
@@ -299,7 +300,7 @@ fn parse_repo_mapping(path: PathBuf) -> Result<RepoMapping> {
299300
let mut exact = HashMap::new();
300301
let mut prefixes = BTreeMap::new();
301302

302-
for line in std::fs::read_to_string(path)
303+
for line in fs::read_to_string(path)
303304
.map_err(RunfilesError::RepoMappingIoError)?
304305
.lines()
305306
{
@@ -332,7 +333,7 @@ fn parse_repo_mapping(path: PathBuf) -> Result<RepoMapping> {
332333

333334
/// Returns the .runfiles directory for the currently executing binary.
334335
pub fn find_runfiles_dir() -> Result<PathBuf> {
335-
if let Some(value) = std::env::var_os(MANIFEST_FILE_ENV_VAR) {
336+
if let Some(value) = env::var_os(MANIFEST_FILE_ENV_VAR) {
336337
assert!(
337338
value.is_empty(),
338339
"Unexpected call when {} exists",
@@ -341,19 +342,19 @@ pub fn find_runfiles_dir() -> Result<PathBuf> {
341342
}
342343

343344
// If Bazel told us about the runfiles dir, use that without looking further.
344-
if let Some(runfiles_dir) = std::env::var_os(RUNFILES_DIR_ENV_VAR).map(PathBuf::from) {
345+
if let Some(runfiles_dir) = env::var_os(RUNFILES_DIR_ENV_VAR).map(PathBuf::from) {
345346
if runfiles_dir.is_dir() {
346347
return Ok(runfiles_dir);
347348
}
348349
}
349-
if let Some(test_srcdir) = std::env::var_os(TEST_SRCDIR_ENV_VAR).map(PathBuf::from) {
350+
if let Some(test_srcdir) = env::var_os(TEST_SRCDIR_ENV_VAR).map(PathBuf::from) {
350351
if test_srcdir.is_dir() {
351352
return Ok(test_srcdir);
352353
}
353354
}
354355

355356
// Consume the first argument (argv[0])
356-
let exec_path = std::env::args().next().expect("arg 0 was not set");
357+
let exec_path = env::args().next().expect("arg 0 was not set");
357358

358359
let current_dir =
359360
env::current_dir().expect("The current working directory is always expected to be set.");
@@ -439,14 +440,14 @@ mod test {
439440
// Replace or remove requested environment variables.
440441
for (env, val) in kvs.as_ref() {
441442
// Track the original state of the variable.
442-
match std::env::var_os(env) {
443+
match env::var_os(env) {
443444
Some(v) => old_env.insert(env, Some(v)),
444445
None => old_env.insert(env, None::<OsString>),
445446
};
446447

447448
match val {
448-
Some(v) => std::env::set_var(env, v),
449-
None => std::env::remove_var(env),
449+
Some(v) => env::set_var(env, v),
450+
None => env::remove_var(env),
450451
}
451452
}
452453

@@ -456,8 +457,8 @@ mod test {
456457
// Restore original environment
457458
for (env, val) in old_env {
458459
match val {
459-
Some(v) => std::env::set_var(env, v),
460-
None => std::env::remove_var(env),
460+
Some(v) => env::set_var(env, v),
461+
None => env::remove_var(env),
461462
}
462463
}
463464

@@ -466,18 +467,18 @@ mod test {
466467

467468
#[test]
468469
fn test_mock_env() {
469-
let original_name = std::env::var("TEST_WORKSPACE").unwrap();
470+
let original_name = env::var("TEST_WORKSPACE").unwrap();
470471
assert!(
471472
!original_name.is_empty(),
472473
"In Bazel tests, `TEST_WORKSPACE` is expected to be populated."
473474
);
474475

475476
let mocked_name = with_mock_env([("TEST_WORKSPACE", Some("foobar"))], || {
476-
std::env::var("TEST_WORKSPACE").unwrap()
477+
env::var("TEST_WORKSPACE").unwrap()
477478
});
478479

479480
assert_eq!(mocked_name, "foobar");
480-
assert_eq!(original_name, std::env::var("TEST_WORKSPACE").unwrap());
481+
assert_eq!(original_name, env::var("TEST_WORKSPACE").unwrap());
481482
}
482483

483484
/// Create a temp directory to act as a runfiles directory for testing
@@ -489,14 +490,14 @@ mod test {
489490
let path = "rules_rust/rust/runfiles/data/sample.txt";
490491
let f = rlocation!(r, path).unwrap();
491492

492-
let temp_dir = PathBuf::from(std::env::var("TEST_TMPDIR").unwrap());
493+
let temp_dir = PathBuf::from(env::var("TEST_TMPDIR").unwrap());
493494
let runfiles_dir = temp_dir.join(name);
494495
let test_path = runfiles_dir.join(path);
495496
if let Some(parent) = test_path.parent() {
496-
std::fs::create_dir_all(parent).expect("Failed to create test path parents.");
497+
fs::create_dir_all(parent).expect("Failed to create test path parents.");
497498
}
498499

499-
std::fs::copy(f, test_path).expect("Failed to copy test file");
500+
fs::copy(f, test_path).expect("Failed to copy test file");
500501

501502
runfiles_dir.to_str().unwrap().to_string()
502503
})
@@ -666,11 +667,11 @@ mod test {
666667

667668
#[test]
668669
fn test_parse_repo_mapping() {
669-
let temp_dir = PathBuf::from(std::env::var("TEST_TMPDIR").unwrap());
670-
std::fs::create_dir_all(&temp_dir).unwrap();
670+
let temp_dir = PathBuf::from(env::var("TEST_TMPDIR").unwrap());
671+
fs::create_dir_all(&temp_dir).unwrap();
671672

672673
let valid = temp_dir.join("test_parse_repo_mapping.txt");
673-
std::fs::write(
674+
fs::write(
674675
&valid,
675676
dedent(
676677
r#",rules_rust,rules_rust
@@ -733,8 +734,8 @@ mod test {
733734

734735
#[test]
735736
fn test_parse_repo_mapping_invalid_file() {
736-
let temp_dir = PathBuf::from(std::env::var("TEST_TMPDIR").unwrap());
737-
std::fs::create_dir_all(&temp_dir).unwrap();
737+
let temp_dir = PathBuf::from(env::var("TEST_TMPDIR").unwrap());
738+
fs::create_dir_all(&temp_dir).unwrap();
738739

739740
let invalid = temp_dir.join("test_parse_repo_mapping_invalid_file.txt");
740741

@@ -743,7 +744,7 @@ mod test {
743744
RunfilesError::RepoMappingIoError(_)
744745
));
745746

746-
std::fs::write(&invalid, "invalid").unwrap();
747+
fs::write(&invalid, "invalid").unwrap();
747748

748749
assert_eq!(
749750
parse_repo_mapping(invalid),
@@ -753,11 +754,11 @@ mod test {
753754

754755
#[test]
755756
fn test_parse_repo_mapping_with_wildcard() {
756-
let temp_dir = PathBuf::from(std::env::var("TEST_TMPDIR").unwrap());
757-
std::fs::create_dir_all(&temp_dir).unwrap();
757+
let temp_dir = PathBuf::from(env::var("TEST_TMPDIR").unwrap());
758+
fs::create_dir_all(&temp_dir).unwrap();
758759

759760
let mapping_file = temp_dir.join("test_parse_repo_mapping_with_wildcard.txt");
760-
std::fs::write(
761+
fs::write(
761762
&mapping_file,
762763
dedent(
763764
r#"+deps+*,aaa,_main
@@ -801,12 +802,12 @@ mod test {
801802

802803
#[test]
803804
fn test_rlocation_from_with_wildcard() {
804-
let temp_dir = PathBuf::from(std::env::var("TEST_TMPDIR").unwrap());
805-
std::fs::create_dir_all(&temp_dir).unwrap();
805+
let temp_dir = PathBuf::from(env::var("TEST_TMPDIR").unwrap());
806+
fs::create_dir_all(&temp_dir).unwrap();
806807

807808
// Create a mock runfiles directory
808809
let runfiles_dir = temp_dir.join("test_rlocation_from_with_wildcard.runfiles");
809-
std::fs::create_dir_all(&runfiles_dir).unwrap();
810+
fs::create_dir_all(&runfiles_dir).unwrap();
810811

811812
let r = Runfiles {
812813
mode: Mode::DirectoryBased(runfiles_dir.clone()),

0 commit comments

Comments
 (0)