bless clippy

This commit is contained in:
Ralf Jung 2022-10-25 19:59:36 +02:00
parent 543afa8896
commit 5a5a3e4ef4
14 changed files with 34 additions and 34 deletions

View File

@ -4,5 +4,5 @@ fn main() {
// Re-export the TARGET environment variable so it can // Re-export the TARGET environment variable so it can
// be accessed by miri. // be accessed by miri.
let target = std::env::var("TARGET").unwrap(); let target = std::env::var("TARGET").unwrap();
println!("cargo:rustc-env=TARGET={}", target); println!("cargo:rustc-env=TARGET={target}");
} }

View File

@ -34,7 +34,7 @@ Examples:
"#; "#;
fn show_help() { fn show_help() {
println!("{}", CARGO_MIRI_HELP); println!("{CARGO_MIRI_HELP}");
} }
fn show_version() { fn show_version() {
@ -52,7 +52,7 @@ fn forward_patched_extern_arg(args: &mut impl Iterator<Item = String>, cmd: &mut
let path = args.next().expect("`--extern` should be followed by a filename"); let path = args.next().expect("`--extern` should be followed by a filename");
if let Some(lib) = path.strip_suffix(".rlib") { if let Some(lib) = path.strip_suffix(".rlib") {
// If this is an rlib, make it an rmeta. // If this is an rlib, make it an rmeta.
cmd.arg(format!("{}.rmeta", lib)); cmd.arg(format!("{lib}.rmeta"));
} else { } else {
// Some other extern file (e.g. a `.so`). Forward unchanged. // Some other extern file (e.g. a `.so`). Forward unchanged.
cmd.arg(path); cmd.arg(path);
@ -336,7 +336,7 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
"[cargo-miri rustc inside rustdoc] captured input:\n{}", "[cargo-miri rustc inside rustdoc] captured input:\n{}",
std::str::from_utf8(&env.stdin).unwrap() std::str::from_utf8(&env.stdin).unwrap()
); );
eprintln!("[cargo-miri rustc inside rustdoc] going to run:\n{:?}", cmd); eprintln!("[cargo-miri rustc inside rustdoc] going to run:\n{cmd:?}");
} }
exec_with_pipe(cmd, &env.stdin, format!("{}.stdin", out_filename("", "").display())); exec_with_pipe(cmd, &env.stdin, format!("{}.stdin", out_filename("", "").display()));
@ -374,7 +374,7 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
val.push("metadata"); val.push("metadata");
} }
} }
cmd.arg(format!("{}={}", emit_flag, val.join(","))); cmd.arg(format!("{emit_flag}={}", val.join(",")));
} else if arg == "--extern" { } else if arg == "--extern" {
// Patch `--extern` filenames, since Cargo sometimes passes stub `.rlib` files: // Patch `--extern` filenames, since Cargo sometimes passes stub `.rlib` files:
// https://github.com/rust-lang/miri/issues/1705 // https://github.com/rust-lang/miri/issues/1705
@ -535,7 +535,7 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
// Run it. // Run it.
debug_cmd("[cargo-miri runner]", verbose, &cmd); debug_cmd("[cargo-miri runner]", verbose, &cmd);
match phase { match phase {
RunnerPhase::Rustdoc => exec_with_pipe(cmd, &info.stdin, format!("{}.stdin", binary)), RunnerPhase::Rustdoc => exec_with_pipe(cmd, &info.stdin, format!("{binary}.stdin")),
RunnerPhase::Cargo => exec(cmd), RunnerPhase::Cargo => exec(cmd),
} }
} }

View File

@ -83,7 +83,7 @@ pub fn escape_for_toml(s: &str) -> String {
// We want to surround this string in quotes `"`. So we first escape all quotes, // We want to surround this string in quotes `"`. So we first escape all quotes,
// and also all backslashes (that are used to escape quotes). // and also all backslashes (that are used to escape quotes).
let s = s.replace('\\', r#"\\"#).replace('"', r#"\""#); let s = s.replace('\\', r#"\\"#).replace('"', r#"\""#);
format!("\"{}\"", s) format!("\"{s}\"")
} }
/// Returns the path to the `miri` binary /// Returns the path to the `miri` binary
@ -175,7 +175,7 @@ pub fn ask_to_run(mut cmd: Command, ask: bool, text: &str) {
let is_ci = env::var_os("CI").is_some() || env::var_os("TF_BUILD").is_some(); let is_ci = env::var_os("CI").is_some() || env::var_os("TF_BUILD").is_some();
if ask && !is_ci { if ask && !is_ci {
let mut buf = String::new(); let mut buf = String::new();
print!("I will run `{:?}` to {}. Proceed? [Y/n] ", cmd, text); print!("I will run `{cmd:?}` to {text}. Proceed? [Y/n] ");
io::stdout().flush().unwrap(); io::stdout().flush().unwrap();
io::stdin().read_line(&mut buf).unwrap(); io::stdin().read_line(&mut buf).unwrap();
match buf.trim().to_lowercase().as_ref() { match buf.trim().to_lowercase().as_ref() {
@ -185,10 +185,10 @@ pub fn ask_to_run(mut cmd: Command, ask: bool, text: &str) {
a => show_error!("invalid answer `{}`", a), a => show_error!("invalid answer `{}`", a),
}; };
} else { } else {
eprintln!("Running `{:?}` to {}.", cmd, text); eprintln!("Running `{cmd:?}` to {text}.");
} }
if cmd.status().unwrap_or_else(|_| panic!("failed to execute {:?}", cmd)).success().not() { if cmd.status().unwrap_or_else(|_| panic!("failed to execute {cmd:?}")).success().not() {
show_error!("failed to {}", text); show_error!("failed to {}", text);
} }
} }
@ -276,12 +276,12 @@ pub fn debug_cmd(prefix: &str, verbose: usize, cmd: &Command) {
// Print only what has been changed for this `cmd`. // Print only what has been changed for this `cmd`.
for (var, val) in cmd.get_envs() { for (var, val) in cmd.get_envs() {
if let Some(val) = val { if let Some(val) = val {
writeln!(out, "{}={:?} \\", var.to_string_lossy(), val).unwrap(); writeln!(out, "{}={val:?} \\", var.to_string_lossy()).unwrap();
} else { } else {
writeln!(out, "--unset={}", var.to_string_lossy()).unwrap(); writeln!(out, "--unset={}", var.to_string_lossy()).unwrap();
} }
} }
} }
write!(out, "{cmd:?}").unwrap(); write!(out, "{cmd:?}").unwrap();
eprintln!("{}", out); eprintln!("{out}");
} }

View File

@ -192,7 +192,7 @@ fn init_late_loggers(tcx: TyCtxt<'_>) {
if log::Level::from_str(&var).is_ok() { if log::Level::from_str(&var).is_ok() {
env::set_var( env::set_var(
"RUSTC_LOG", "RUSTC_LOG",
&format!( format!(
"rustc_middle::mir::interpret={0},rustc_const_eval::interpret={0}", "rustc_middle::mir::interpret={0},rustc_const_eval::interpret={0}",
var var
), ),
@ -243,7 +243,7 @@ fn host_sysroot() -> Option<String> {
) )
} }
} }
format!("{}/toolchains/{}", home, toolchain) format!("{home}/toolchains/{toolchain}")
} }
_ => option_env!("RUST_SYSROOT") _ => option_env!("RUST_SYSROOT")
.unwrap_or_else(|| { .unwrap_or_else(|| {
@ -330,7 +330,7 @@ fn main() {
} else if crate_kind == "host" { } else if crate_kind == "host" {
false false
} else { } else {
panic!("invalid `MIRI_BE_RUSTC` value: {:?}", crate_kind) panic!("invalid `MIRI_BE_RUSTC` value: {crate_kind:?}")
}; };
// We cannot use `rustc_driver::main` as we need to adjust the CLI arguments. // We cannot use `rustc_driver::main` as we need to adjust the CLI arguments.

View File

@ -399,7 +399,7 @@ mod tests {
//Test partial_cmp //Test partial_cmp
let compare = l.partial_cmp(&r); let compare = l.partial_cmp(&r);
assert_eq!(compare, o, "Invalid comparison\n l: {:?}\n r: {:?}", l, r); assert_eq!(compare, o, "Invalid comparison\n l: {l:?}\n r: {r:?}");
let alt_compare = r.partial_cmp(&l); let alt_compare = r.partial_cmp(&l);
assert_eq!( assert_eq!(
alt_compare, alt_compare,

View File

@ -263,7 +263,7 @@ pub fn report_error<'tcx, 'mir>(
msg.insert(0, e.to_string()); msg.insert(0, e.to_string());
report_msg( report_msg(
DiagLevel::Error, DiagLevel::Error,
&if let Some(title) = title { format!("{}: {}", title, msg[0]) } else { msg[0].clone() }, &if let Some(title) = title { format!("{title}: {}", msg[0]) } else { msg[0].clone() },
msg, msg,
vec![], vec![],
helps, helps,

View File

@ -107,7 +107,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
/// Gets an instance for a path. /// Gets an instance for a path.
fn resolve_path(&self, path: &[&str]) -> ty::Instance<'tcx> { fn resolve_path(&self, path: &[&str]) -> ty::Instance<'tcx> {
self.try_resolve_path(path) self.try_resolve_path(path)
.unwrap_or_else(|| panic!("failed to find required Rust item: {:?}", path)) .unwrap_or_else(|| panic!("failed to find required Rust item: {path:?}"))
} }
/// Evaluates the scalar at the specified path. Returns Some(val) /// Evaluates the scalar at the specified path. Returns Some(val)
@ -505,7 +505,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
RejectOpWith::WarningWithoutBacktrace => { RejectOpWith::WarningWithoutBacktrace => {
this.tcx this.tcx
.sess .sess
.warn(&format!("{} was made to return an error due to isolation", op_name)); .warn(format!("{op_name} was made to return an error due to isolation"));
Ok(()) Ok(())
} }
RejectOpWith::Warning => { RejectOpWith::Warning => {

View File

@ -191,12 +191,12 @@ impl interpret::Provenance for Provenance {
Provenance::Concrete { alloc_id, sb } => { Provenance::Concrete { alloc_id, sb } => {
// Forward `alternate` flag to `alloc_id` printing. // Forward `alternate` flag to `alloc_id` printing.
if f.alternate() { if f.alternate() {
write!(f, "[{:#?}]", alloc_id)?; write!(f, "[{alloc_id:#?}]")?;
} else { } else {
write!(f, "[{:?}]", alloc_id)?; write!(f, "[{alloc_id:?}]")?;
} }
// Print Stacked Borrows tag. // Print Stacked Borrows tag.
write!(f, "{:?}", sb)?; write!(f, "{sb:?}")?;
} }
Provenance::Wildcard => { Provenance::Wildcard => {
write!(f, "[wildcard]")?; write!(f, "[wildcard]")?;

View File

@ -40,7 +40,7 @@ impl<T> RangeMap<T> {
let mut left = 0usize; // inclusive let mut left = 0usize; // inclusive
let mut right = self.v.len(); // exclusive let mut right = self.v.len(); // exclusive
loop { loop {
debug_assert!(left < right, "find_offset: offset {} is out-of-bounds", offset); debug_assert!(left < right, "find_offset: offset {offset} is out-of-bounds");
let candidate = left.checked_add(right).unwrap() / 2; let candidate = left.checked_add(right).unwrap() / 2;
let elem = &self.v[candidate]; let elem = &self.v[candidate];
if offset < elem.range.start { if offset < elem.range.start {

View File

@ -321,7 +321,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
return Ok(Some(body)); return Ok(Some(body));
} }
this.handle_unsupported(format!("can't call foreign function: {}", link_name))?; this.handle_unsupported(format!("can't call foreign function: {link_name}"))?;
return Ok(None); return Ok(None);
} }
} }

View File

@ -621,7 +621,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
return Ok(-1); return Ok(-1);
} }
let fd = options.open(&path).map(|file| { let fd = options.open(path).map(|file| {
let fh = &mut this.machine.file_handler; let fh = &mut this.machine.file_handler;
fh.insert_fd(Box::new(FileHandle { file, writable })) fh.insert_fd(Box::new(FileHandle { file, writable }))
}); });
@ -1862,7 +1862,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let possibly_unique = std::env::temp_dir().join::<PathBuf>(p.into()); let possibly_unique = std::env::temp_dir().join::<PathBuf>(p.into());
let file = fopts.open(&possibly_unique); let file = fopts.open(possibly_unique);
match file { match file {
Ok(f) => { Ok(f) => {

View File

@ -126,7 +126,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
futex(this, &args[1..], dest)?; futex(this, &args[1..], dest)?;
} }
id => { id => {
this.handle_unsupported(format!("can't execute syscall with ID {}", id))?; this.handle_unsupported(format!("can't execute syscall with ID {id}"))?;
return Ok(EmulateByNameResult::AlreadyJumped); return Ok(EmulateByNameResult::AlreadyJumped);
} }
} }

View File

@ -86,12 +86,12 @@ impl Invalidation {
impl fmt::Display for InvalidationCause { impl fmt::Display for InvalidationCause {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
InvalidationCause::Access(kind) => write!(f, "{}", kind), InvalidationCause::Access(kind) => write!(f, "{kind}"),
InvalidationCause::Retag(perm, kind) => InvalidationCause::Retag(perm, kind) =>
if *kind == RetagCause::FnEntry { if *kind == RetagCause::FnEntry {
write!(f, "{:?} FnEntry retag", perm) write!(f, "{perm:?} FnEntry retag")
} else { } else {
write!(f, "{:?} retag", perm) write!(f, "{perm:?} retag")
}, },
} }
} }
@ -339,7 +339,7 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
// this allocation. // this allocation.
if self.history.base.0.tag() == tag { if self.history.base.0.tag() == tag {
Some(( Some((
format!("{:?} was created here, as the base tag for {:?}", tag, self.history.id), format!("{tag:?} was created here, as the base tag for {:?}", self.history.id),
self.history.base.1.data() self.history.base.1.data()
)) ))
} else { } else {
@ -381,7 +381,7 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
self.offset.bytes(), self.offset.bytes(),
); );
err_sb_ub( err_sb_ub(
format!("{}{}", action, error_cause(stack, op.orig_tag)), format!("{action}{}", error_cause(stack, op.orig_tag)),
Some(operation_summary(&op.cause.summary(), self.history.id, op.range)), Some(operation_summary(&op.cause.summary(), self.history.id, op.range)),
op.orig_tag.and_then(|orig_tag| self.get_logs_relevant_to(orig_tag, None)), op.orig_tag.and_then(|orig_tag| self.get_logs_relevant_to(orig_tag, None)),
) )
@ -401,7 +401,7 @@ impl<'span, 'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'span, 'history, 'ecx, 'mir
offset = self.offset.bytes(), offset = self.offset.bytes(),
); );
err_sb_ub( err_sb_ub(
format!("{}{}", action, error_cause(stack, op.tag)), format!("{action}{}", error_cause(stack, op.tag)),
Some(operation_summary("an access", self.history.id, op.range)), Some(operation_summary("an access", self.history.id, op.range)),
op.tag.and_then(|tag| self.get_logs_relevant_to(tag, None)), op.tag.and_then(|tag| self.get_logs_relevant_to(tag, None)),
) )

View File

@ -1153,7 +1153,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let alloc_extra = this.get_alloc_extra(alloc_id)?; let alloc_extra = this.get_alloc_extra(alloc_id)?;
let stacks = alloc_extra.stacked_borrows.as_ref().unwrap().borrow(); let stacks = alloc_extra.stacked_borrows.as_ref().unwrap().borrow();
for (range, stack) in stacks.stacks.iter_all() { for (range, stack) in stacks.stacks.iter_all() {
print!("{:?}: [", range); print!("{range:?}: [");
for i in 0..stack.len() { for i in 0..stack.len() {
let item = stack.get(i).unwrap(); let item = stack.get(i).unwrap();
print!(" {:?}{:?}", item.perm(), item.tag()); print!(" {:?}{:?}", item.perm(), item.tag());