Skip to content

Addressed clippy warnings from clippy 0.1.67 (ec56537c 2022-12-15) #1717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cargo/bootstrap/bootstrap_installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn install() -> std::io::Result<u64> {

fn main() {
if let Err(err) = install() {
eprintln!("{:?}", err);
eprintln!("{err:?}");
std::process::exit(1);
};
}
11 changes: 5 additions & 6 deletions cargo/cargo_build_script_runner/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn run_buildrs() -> Result<(), String> {
format!(
"Build script process failed{}\n--stdout:\n{}\n--stderr:\n{}",
if let Some(exit_code) = process_output.status.code() {
format!(" with exit code {}", exit_code)
format!(" with exit code {exit_code}")
} else {
String::new()
},
Expand Down Expand Up @@ -236,15 +236,14 @@ fn get_target_env_vars<P: AsRef<Path>>(rustc: &P) -> Result<BTreeMap<String, Str
env::var("TARGET").expect("missing TARGET")
))
.output()
.map_err(|err| format!("Error running rustc to get target information: {}", err))?;
.map_err(|err| format!("Error running rustc to get target information: {err}"))?;
if !output.status.success() {
return Err(format!(
"Error running rustc to get target information: {:?}",
output
"Error running rustc to get target information: {output:?}",
));
}
let stdout = std::str::from_utf8(&output.stdout)
.map_err(|err| format!("Non-UTF8 stdout from rustc: {:?}", err))?;
.map_err(|err| format!("Non-UTF8 stdout from rustc: {err:?}"))?;

Ok(parse_rustc_cfg_output(stdout))
}
Expand Down Expand Up @@ -280,7 +279,7 @@ fn main() {
Ok(_) => 0,
Err(err) => {
// Neatly print errors
eprintln!("{}", err);
eprintln!("{err}");
1
}
});
Expand Down
8 changes: 4 additions & 4 deletions cargo/cargo_build_script_runner/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ impl BuildScriptOutput {

for flag in outputs {
match flag {
BuildScriptOutput::Cfg(e) => compile_flags.push(format!("--cfg={}", e)),
BuildScriptOutput::Cfg(e) => compile_flags.push(format!("--cfg={e}")),
BuildScriptOutput::Flags(e) => compile_flags.push(e.to_owned()),
BuildScriptOutput::LinkArg(e) => compile_flags.push(format!("-Clink-arg={}", e)),
BuildScriptOutput::LinkLib(e) => link_flags.push(format!("-l{}", e)),
BuildScriptOutput::LinkSearch(e) => link_search_paths.push(format!("-L{}", e)),
BuildScriptOutput::LinkArg(e) => compile_flags.push(format!("-Clink-arg={e}")),
BuildScriptOutput::LinkLib(e) => link_flags.push(format!("-l{e}")),
BuildScriptOutput::LinkSearch(e) => link_search_paths.push(format!("-L{e}")),
_ => {}
}
}
Expand Down
7 changes: 2 additions & 5 deletions crate_universe/src/cli/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,15 @@ pub fn query(opt: QueryOptions) -> Result<()> {
&opt.rustc,
)?;
if digest != expected {
return announce_repin(&format!(
"Digests do not match: {:?} != {:?}",
digest, expected
));
return announce_repin(&format!("Digests do not match: {digest:?} != {expected:?}",));
}

// There is no need to repin
Ok(())
}

fn announce_repin(reason: &str) -> Result<()> {
eprintln!("{}", reason);
eprintln!("{reason}");
println!("repin");
Ok(())
}
5 changes: 2 additions & 3 deletions crate_universe/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl Add for CrateAnnotations {
};

let concat_string = |lhs: &mut String, rhs: String| {
*lhs = format!("{}{}", lhs, rhs);
*lhs = format!("{lhs}{rhs}");
};

#[rustfmt::skip]
Expand Down Expand Up @@ -415,8 +415,7 @@ impl<'de> Visitor<'de> for CrateIdVisitor {
})
.ok_or_else(|| {
E::custom(format!(
"Expected string value of `{{name}} {{version}}`. Got '{}'",
v
"Expected string value of `{{name}} {{version}}`. Got '{v}'"
))
})
}
Expand Down
6 changes: 3 additions & 3 deletions crate_universe/src/context/platforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn resolve_cfg_platforms(
// (`x86_64-unknown-linux-gun` vs `cfg(target = "x86_64-unkonwn-linux-gnu")`). So
// in order to parse configurations, the text is renamed for the check but the
// original is retained for comaptibility with the manifest.
let rename = |cfg: &str| -> String { format!("cfg(target = \"{}\")", cfg) };
let rename = |cfg: &str| -> String { format!("cfg(target = \"{cfg}\")") };
let original_cfgs: HashMap<String, String> = configurations
.iter()
.filter(|cfg| !cfg.starts_with("cfg("))
Expand All @@ -73,8 +73,8 @@ pub fn resolve_cfg_platforms(
})
// Check the current configuration with against each supported triple
.map(|cfg| {
let expression = Expression::parse(&cfg)
.context(format!("Failed to parse expression: '{}'", cfg))?;
let expression =
Expression::parse(&cfg).context(format!("Failed to parse expression: '{cfg}'"))?;

let triples = target_infos
.iter()
Expand Down
2 changes: 1 addition & 1 deletion crate_universe/src/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn write_lockfile(lockfile: Context, path: &Path, dry_run: bool) -> Result<(
let content = serde_json::to_string_pretty(&lockfile)?;

if dry_run {
println!("{:#?}", content);
println!("{content:#?}");
} else {
// Ensure the parent directory exists
if let Some(parent) = path.parent() {
Expand Down
2 changes: 1 addition & 1 deletion crate_universe/src/metadata/metadata_annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ mod test {
let result = Annotations::new(test::metadata::no_deps(), test::lockfile::no_deps(), config);
assert!(result.is_err());

let result_str = format!("{:?}", result);
let result_str = format!("{result:?}");
assert!(result_str.contains("Unused annotations were provided. Please remove them"));
assert!(result_str.contains("mock-crate"));
}
Expand Down
4 changes: 2 additions & 2 deletions crate_universe/src/rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn write_outputs(
println!(
"==============================================================================="
);
println!("{}\n", content);
println!("{content}\n");
}
} else {
for (path, content) in outputs {
Expand Down Expand Up @@ -513,7 +513,7 @@ mod test {
assert!(build_file_content.replace(' ', "").contains(
&rustc_flags
.iter()
.map(|s| format!("\"{}\",", s))
.map(|s| format!("\"{s}\","))
.collect::<Vec<String>>()
.join("\n")
));
Expand Down
2 changes: 1 addition & 1 deletion crate_universe/src/rendering/template_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl TemplateEngine {
context.insert(
"default_package_name",
&match render_config.default_package_name.as_ref() {
Some(pkg_name) => format!("\"{}\"", pkg_name),
Some(pkg_name) => format!("\"{pkg_name}\""),
None => "None".to_owned(),
},
);
Expand Down
4 changes: 2 additions & 2 deletions crate_universe/src/splicing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ impl WorkspaceMetadata {

// Load the index for the current url
let index = crates_index::Index::from_url(index_url)
.with_context(|| format!("Failed to load index for url: {}", index_url))?;
.with_context(|| format!("Failed to load index for url: {index_url}"))?;

// Ensure each index has a valid index config
index.index_config().with_context(|| {
format!("`config.json` not found in index: {}", index_url)
format!("`config.json` not found in index: {index_url}")
})?;

index
Expand Down
20 changes: 8 additions & 12 deletions crate_universe/src/splicing/splicer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'a> SplicerKind<'a> {
.keys()
.map(|p| {
p.normalize()
.with_context(|| format!("Failed to normalize path {:?}", p))
.with_context(|| format!("Failed to normalize path {p:?}"))
})
.collect::<Result<_, _>>()?,
)
Expand Down Expand Up @@ -165,7 +165,7 @@ impl<'a> SplicerKind<'a> {
.map(|member| {
let path = root_manifest_dir.join(member).join("Cargo.toml");
path.normalize()
.with_context(|| format!("Failed to normalize path {:?}", path))
.with_context(|| format!("Failed to normalize path {path:?}"))
})
.collect::<Result<BTreeSet<normpath::BasePathBuf>, _>>()?;

Expand All @@ -178,10 +178,7 @@ impl<'a> SplicerKind<'a> {
.map(|workspace_manifest_path| {
let label = Label::from_absolute_path(workspace_manifest_path.as_path())
.with_context(|| {
format!(
"Failed to identify label for path {:?}",
workspace_manifest_path
)
format!("Failed to identify label for path {workspace_manifest_path:?}")
})?;
Ok(label.to_string())
})
Expand Down Expand Up @@ -548,9 +545,8 @@ pub fn default_cargo_workspace_manifest(
let mut manifest = cargo_toml::Manifest::from_str(&textwrap::dedent(&format!(
r#"
[workspace]
resolver = "{}"
resolver = "{resolver_version}"
"#,
resolver_version,
)))
.unwrap();

Expand Down Expand Up @@ -867,7 +863,7 @@ mod test {

splicing_manifest.manifests.insert(
manifest_path,
Label::from_str(&format!("//{}:Cargo.toml", pkg)).unwrap(),
Label::from_str(&format!("//{pkg}:Cargo.toml")).unwrap(),
);
}

Expand Down Expand Up @@ -925,7 +921,7 @@ mod test {

splicing_manifest.manifests.insert(
manifest_path,
Label::from_str(&format!("//{}:Cargo.toml", pkg)).unwrap(),
Label::from_str(&format!("//{pkg}:Cargo.toml")).unwrap(),
);
}

Expand Down Expand Up @@ -1008,11 +1004,11 @@ mod test {

if is_root {
PackageId {
repr: format!("{} 0.0.1 (path+file://{})", name, workspace_root),
repr: format!("{name} 0.0.1 (path+file://{workspace_root})"),
}
} else {
PackageId {
repr: format!("{} 0.0.1 (path+file://{}/{})", name, workspace_root, name,),
repr: format!("{name} 0.0.1 (path+file://{workspace_root}/{name})"),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crate_universe/src/utils/starlark/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl FromStr for Label {
let re = Regex::new(r"^(@@?[\w\d\-_\.]*)?/{0,2}([\w\d\-_\./+]+)?(:([\+\w\d\-_\./]+))?$")?;
let cap = re
.captures(s)
.with_context(|| format!("Failed to parse label from string: {}", s))?;
.with_context(|| format!("Failed to parse label from string: {s}"))?;

let repository = cap
.get(1)
Expand Down Expand Up @@ -57,14 +57,14 @@ impl Display for Label {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Add the repository
if let Some(repo) = &self.repository {
write!(f, "@{}", repo)?;
write!(f, "@{repo}")?;
}

write!(f, "//")?;

// Add the package
if let Some(pkg) = &self.package {
write!(f, "{}", pkg)?;
write!(f, "{pkg}")?;
}

write!(f, ":{}", self.target)?;
Expand Down
2 changes: 1 addition & 1 deletion crate_universe/src/utils/starlark/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<T: Ord> SelectList<T> {
}

// TODO: This should probably be added to the [Select] trait
pub fn get_iter<'a>(&'a self, config: Option<&String>) -> Option<btree_set::Iter<T>> {
pub fn get_iter(&self, config: Option<&String>) -> Option<btree_set::Iter<T>> {
match config {
Some(conf) => self.selects.get(conf).map(|set| set.iter()),
None => Some(self.common.iter()),
Expand Down
4 changes: 2 additions & 2 deletions crate_universe/tools/cross_installer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Options {
fn prepare_workspace(workspace_root: &Path) {
let src = PathBuf::from(env!("CROSS_CONFIG"));
let dest = workspace_root.join("Cross.toml");
println!("{:?} -> {:?}", src, dest);
println!("{src:?} -> {dest:?}");
fs::copy(src, dest).unwrap();

// Unfortunately, cross runs into issues when cross compiling incramentally.
Expand All @@ -46,7 +46,7 @@ fn execute_cross(working_dir: &Path, target_triple: &str) {
.arg("--locked")
.arg("--bin")
.arg("cargo-bazel")
.arg(format!("--target={}", target_triple))
.arg(format!("--target={target_triple}"))
.status()
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion crate_universe/tools/urls_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn locate_artifacts(artifacts_dir: &Path, url_prefix: &str) -> Vec<Artifact> {
.map(|ext| format!(".{}", ext.to_string_lossy()))
.unwrap_or_default();
Artifact {
url: format!("{}/{}-{}{}", url_prefix, stem, triple, extension),
url: format!("{url_prefix}/{stem}-{triple}{extension}"),
triple: triple.to_string(),
sha256: calculate_sha256(&f_entry.path()),
}
Expand Down
2 changes: 1 addition & 1 deletion proto/optional_output_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn main() {
Err(e) => {
println!("Usage: [optional_output1...optional_outputN] -- program [arg1...argn]");
println!("{:?}", args());
println!("{:?}", e);
println!("{e:?}");
-1
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/chained_direct_deps/mod2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate mod1;

pub fn greeter(name: &str) -> String {
format!("Hello, {}!", name)
format!("Hello, {name}!")
}

pub fn default_greeter() -> String {
Expand Down
1 change: 1 addition & 0 deletions test/process_wrapper/rustc_quit_on_rmeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod test {

/// fake_rustc runs the fake_rustc binary under process_wrapper with the specified
/// process wrapper arguments. No arguments are passed to fake_rustc itself.
///
fn fake_rustc(process_wrapper_args: &[&'static str]) -> String {
let r = Runfiles::create().unwrap();
let fake_rustc = r.rlocation(
Expand Down
2 changes: 1 addition & 1 deletion test/renamed_deps/mod2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate mod1;

pub fn greeter(name: &str) -> String {
format!("Hello, {}!", name)
format!("Hello, {name}!")
}

pub fn default_greeter() -> String {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/exports/lib_a/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub fn greeting_from(from: &str) -> String {
format!("Hello from {}!", from)
format!("Hello from {from}!")
}

pub fn greeting_a() -> String {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/is_proc_macro_dep/proc_macro_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use proc_macro::TokenStream;
#[proc_macro]
pub fn make_answer(_item: TokenStream) -> TokenStream {
let answer = proc_macro_dep::proc_macro_dep();
format!("fn answer() -> u32 {{ {} }}", answer)
format!("fn answer() -> u32 {{ {answer} }}")
.parse()
.unwrap()
}
2 changes: 1 addition & 1 deletion test/versioned_dylib/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C" {

fn main() {
let zero = unsafe { return_zero() };
println!("Got {} from our shared lib", zero);
println!("Got {zero} from our shared lib");
}

#[cfg(test)]
Expand Down
Loading