Skip to content

Commit

Permalink
Inlined format args clippy --fix. (#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulku authored Oct 29, 2022
1 parent a1f1e64 commit 3396936
Show file tree
Hide file tree
Showing 57 changed files with 191 additions and 201 deletions.
1 change: 0 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ rustflags = [ # Global lints/warnings. Need to use underscore instead of -.
# New lints that we are not compliant yet
"-Aclippy::needless-borrow",
"-Aclippy::bool-to-int-with-if",
"-Aclippy::uninlined-format-args",
]
8 changes: 4 additions & 4 deletions cprover_bindings/src/goto_program/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub fn arithmetic_overflow_result_type(operand_type: Type) -> Type {
assert!(operand_type.is_integer());
// give the struct the name "overflow_result_<type>", e.g.
// "overflow_result_Unsignedbv"
let name: InternedString = format!("overflow_result_{:?}", operand_type).into();
let name: InternedString = format!("overflow_result_{operand_type:?}").into();
Type::struct_type(
name,
vec![
Expand Down Expand Up @@ -411,7 +411,7 @@ macro_rules! expr {
impl Expr {
/// `&self`
pub fn address_of(self) -> Self {
assert!(self.can_take_address_of(), "Can't take address of {:?}", self);
assert!(self.can_take_address_of(), "Can't take address of {self:?}");
expr!(AddressOf(self), self.typ.clone().to_pointer())
}

Expand Down Expand Up @@ -484,7 +484,7 @@ impl Expr {

/// `(typ) self`.
pub fn cast_to(self, typ: Type) -> Self {
assert!(self.can_cast_to(&typ), "Can't cast\n\n{:?} ({:?})\n\n{:?}", self, self.typ, typ);
assert!(self.can_cast_to(&typ), "Can't cast\n\n{self:?} ({:?})\n\n{typ:?}", self.typ);
if self.typ == typ {
self
} else if typ.is_bool() {
Expand Down Expand Up @@ -1379,7 +1379,7 @@ impl Expr {
} else if self.typ().is_array_like() {
self.index_array(idx)
} else {
panic!("Can't index: {:?}", self)
panic!("Can't index: {self:?}")
}
}

Expand Down
8 changes: 4 additions & 4 deletions cprover_bindings/src/goto_program/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ impl Location {
match self {
Location::None => "<none>".to_string(),
Location::BuiltinFunction { function_name, line: Some(line) } => {
format!("<{}>:{}", function_name, line)
format!("<{function_name}>:{line}")
}
Location::BuiltinFunction { function_name, line: None } => {
format!("<{}>", function_name)
format!("<{function_name}>")
}
Location::Loc { file, start_line: line, .. } => format!("{}:{}", file, line),
Location::Loc { file, start_line: line, .. } => format!("{file}:{line}"),
Location::Property { file, line, .. } => {
format!("<{:?}>:{}", file, line)
format!("<{file:?}>:{line}")
}
Location::PropertyUnknownLocation { .. } => "<none>".to_string(),
}
Expand Down
2 changes: 1 addition & 1 deletion cprover_bindings/src/goto_program/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl Stmt {

/// `__CPROVER_assume(cond);`
pub fn assume(cond: Expr, loc: Location) -> Self {
assert!(cond.typ().is_bool(), "Assume expected bool, got {:?}", cond);
assert!(cond.typ().is_bool(), "Assume expected bool, got {cond:?}");
stmt!(Assume { cond }, loc)
}

Expand Down
2 changes: 1 addition & 1 deletion cprover_bindings/src/goto_program/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl Symbol {
/// Setters
impl Symbol {
pub fn update_fn_declaration_with_definition(&mut self, body: Stmt) {
assert!(self.is_function_declaration(), "Expected function declaration, got {:?}", self);
assert!(self.is_function_declaration(), "Expected function declaration, got {self:?}");
self.value = SymbolValues::Stmt(body);
}

Expand Down
2 changes: 1 addition & 1 deletion cprover_bindings/src/goto_program/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl SymbolTable {
new_value: Symbol,
) {
let old_value = self.lookup(new_value.name);
assert!(checker_fn(old_value), "{:?}||{:?}", old_value, new_value);
assert!(checker_fn(old_value), "{old_value:?}||{new_value:?}");
self.symbol_table.insert(new_value.name, new_value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ impl NameTransformer {
let suffix = suffix.map(fix_name);

// Add `tag-` back in if it was present
let with_prefix = format!("{}{}", prefix, name);
let with_prefix = format!("{prefix}{name}");

// Reattach the variable name
let result = match suffix {
None => with_prefix,
Some(suffix) => format!("{}::{}", with_prefix, suffix),
Some(suffix) => format!("{with_prefix}::{suffix}"),
};

// Ensure result has not been used before
let result = if self.used_names.contains(&result) {
let mut suffix = 0;
loop {
let result = format!("{}_{}", result, suffix);
let result = format!("{result}_{suffix}");
if !self.used_names.contains(&result) {
break result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn do_passes(mut symtab: SymbolTable, pass_names: &[String]) -> SymbolTable
NameTransformer::transform(&symtab)
}
"identity" => IdentityTransformer::transform(&symtab),
_ => panic!("Invalid symbol table transformation: {}", pass_name),
_ => panic!("Invalid symbol table transformation: {pass_name}"),
}
}

Expand Down
36 changes: 18 additions & 18 deletions cprover_bindings/src/goto_program/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ impl Type {
T: TryInto<u64>,
T::Error: Debug,
{
assert!(self.typecheck_array_elem(), "Can't make array of type {:?}", self);
assert!(self.typecheck_array_elem(), "Can't make array of type {self:?}");
let size: u64 = size.try_into().unwrap();
Array { typ: Box::new(self), size }
}
Expand Down Expand Up @@ -1021,7 +1021,7 @@ impl Type {
}

pub fn infinite_array_of(self) -> Self {
assert!(self.typecheck_array_elem(), "Can't make infinite array of type {:?}", self);
assert!(self.typecheck_array_elem(), "Can't make infinite array of type {self:?}");
InfiniteArray { typ: Box::new(self) }
}

Expand Down Expand Up @@ -1299,7 +1299,7 @@ impl Type {
| FlexibleArray { .. }
| IncompleteStruct { .. }
| IncompleteUnion { .. }
| VariadicCode { .. } => panic!("Can't zero init {:?}", self),
| VariadicCode { .. } => panic!("Can't zero init {self:?}"),
}
}
}
Expand Down Expand Up @@ -1336,13 +1336,13 @@ impl Type {
// Use String instead of InternedString, since we don't want to intern temporaries.
match self {
Type::Array { typ, size } => {
format!("array_of_{}_{}", size, typ.to_identifier())
format!("array_of_{size}_{}", typ.to_identifier())
}
Type::Bool => "bool".to_string(),
Type::CBitField { width, typ } => {
format!("cbitfield_of_{}_{}", width, typ.to_identifier())
format!("cbitfield_of_{width}_{}", typ.to_identifier())
}
Type::CInteger(int_kind) => format!("c_int_{:?}", int_kind),
Type::CInteger(int_kind) => format!("c_int_{int_kind:?}"),
// e.g. `int my_func(double x, float_y) {`
// => "code_from_double_float_to_int"
Type::Code { parameters, return_type } => {
Expand All @@ -1352,7 +1352,7 @@ impl Type {
.collect::<Vec<_>>()
.join("_");
let return_string = return_type.to_identifier();
format!("code_from_{}_to_{}", parameter_string, return_string)
format!("code_from_{parameter_string}_to_{return_string}")
}
Type::Constructor => "constructor".to_string(),
Type::Double => "double".to_string(),
Expand All @@ -1365,13 +1365,13 @@ impl Type {
format!("infinite_array_of_{}", typ.to_identifier())
}
Type::Pointer { typ } => format!("pointer_to_{}", typ.to_identifier()),
Type::Signedbv { width } => format!("signed_bv_{}", width),
Type::Struct { tag, .. } => format!("struct_{}", tag),
Type::StructTag(tag) => format!("struct_tag_{}", tag),
Type::TypeDef { name: tag, .. } => format!("type_def_{}", tag),
Type::Union { tag, .. } => format!("union_{}", tag),
Type::UnionTag(tag) => format!("union_tag_{}", tag),
Type::Unsignedbv { width } => format!("unsigned_bv_{}", width),
Type::Signedbv { width } => format!("signed_bv_{width}"),
Type::Struct { tag, .. } => format!("struct_{tag}"),
Type::StructTag(tag) => format!("struct_tag_{tag}"),
Type::TypeDef { name: tag, .. } => format!("type_def_{tag}"),
Type::Union { tag, .. } => format!("union_{tag}"),
Type::UnionTag(tag) => format!("union_tag_{tag}"),
Type::Unsignedbv { width } => format!("unsigned_bv_{width}"),
// e.g. `int my_func(double x, float_y, ..) {`
// => "variadic_code_from_double_float_to_int"
Type::VariadicCode { parameters, return_type } => {
Expand All @@ -1381,10 +1381,10 @@ impl Type {
.collect::<Vec<_>>()
.join("_");
let return_string = return_type.to_identifier();
format!("variadic_code_from_{}_to_{}", parameter_string, return_string)
format!("variadic_code_from_{parameter_string}_to_{return_string}")
}
Type::Vector { size, typ } => {
format!("vec_of_{}_{}", size, typ.to_identifier())
format!("vec_of_{size}_{}", typ.to_identifier())
}
}
}
Expand All @@ -1404,7 +1404,7 @@ mod type_tests {
fn check_typedef_tag() {
let type_def = Bool.to_typedef(NAME);
assert_eq!(type_def.tag().unwrap().to_string().as_str(), NAME);
assert_eq!(type_def.type_name().unwrap().to_string(), format!("tag-{}", NAME));
assert_eq!(type_def.type_name().unwrap().to_string(), format!("tag-{NAME}"));
}

#[test]
Expand Down Expand Up @@ -1496,7 +1496,7 @@ mod type_tests {
// Insert a field to the sym table to represent the struct field.
let mut sym_table = SymbolTable::new(machine_model_test_stub());
sym_table.ensure(struct_type.type_name().unwrap(), |_, name| {
return Symbol::variable(name, name, struct_type.clone(), Location::none());
Symbol::variable(name, name, struct_type.clone(), Location::none())
});

check_properties(struct_type.clone());
Expand Down
2 changes: 1 addition & 1 deletion cprover_bindings/src/irep/irep_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ impl ToString for IrepId {
IrepId::FreeformString(s) => return s.to_string(),
IrepId::FreeformInteger(i) => return i.to_string(),
IrepId::FreeformBitPattern(i) => {
return format!("{:X}", i);
return format!("{i:X}");
}
_ => (),
}
Expand Down
2 changes: 1 addition & 1 deletion cprover_bindings/src/irep/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod test {
is_auxiliary: false,
is_weak: false,
};
sym_table.insert(symbol.clone());
sym_table.insert(symbol);
assert_ser_tokens(
&sym_table,
&[
Expand Down
5 changes: 1 addition & 4 deletions cprover_bindings/src/irep/to_irep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,7 @@ impl ToIrep for Location {
match self {
Location::None => Irep::nil(),
Location::BuiltinFunction { line, function_name } => Irep::just_named_sub(linear_map![
(
IrepId::File,
Irep::just_string_id(format!("<builtin-library-{}>", function_name)),
),
(IrepId::File, Irep::just_string_id(format!("<builtin-library-{function_name}>")),),
(IrepId::Function, Irep::just_string_id(function_name.to_string())),
])
.with_named_sub_option(IrepId::Line, line.map(Irep::just_int_id)),
Expand Down
2 changes: 1 addition & 1 deletion cprover_bindings/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use num_traits::Zero;
/// The aggregate name used in CBMC for aggregates of type `n`.
pub fn aggr_tag<T: Into<InternedString>>(n: T) -> InternedString {
let n = n.into();
format!("tag-{}", n).into()
format!("tag-{n}").into()
}

pub trait NumUtils {
Expand Down
4 changes: 2 additions & 2 deletions kani-compiler/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub fn main() {
let rustup_home = env::var("RUSTUP_HOME").unwrap();
let rustup_tc = env::var("RUSTUP_TOOLCHAIN").unwrap();
let rustup_lib = path_str!([&rustup_home, "toolchains", &rustup_tc, "lib"]);
println!("cargo:rustc-link-arg-bin=kani-compiler=-Wl,-rpath,{}", rustup_lib);
println!("cargo:rustc-link-arg-bin=kani-compiler=-Wl,-rpath,{rustup_lib}");

// While we hard-code the above for development purposes, for a release/install we look
// in a relative location for a symlink to the local rust toolchain
let origin = if cfg!(target_os = "macos") { "@loader_path" } else { "$ORIGIN" };
println!("cargo:rustc-link-arg-bin=kani-compiler=-Wl,-rpath,{}/../toolchain/lib", origin);
println!("cargo:rustc-link-arg-bin=kani-compiler=-Wl,-rpath,{origin}/../toolchain/lib");
}
2 changes: 1 addition & 1 deletion kani-compiler/src/codegen_cprover_gotoc/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
))
} else {
BuilderKind::Bsd(ar::Builder::new(File::create(&output).unwrap_or_else(|err| {
sess.fatal(&format!("error opening destination during archive building: {}", err));
sess.fatal(&format!("error opening destination during archive building: {err}"));
})))
};

Expand Down
20 changes: 10 additions & 10 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<'tcx> GotocCtx<'tcx> {
),
_ => self.codegen_fatal_error(
PropertyClass::UnsupportedConstruct,
&format!("Unsupported intrinsic {}", intrinsic),
&format!("Unsupported intrinsic {intrinsic}"),
span,
),
}
Expand Down Expand Up @@ -718,8 +718,8 @@ impl<'tcx> GotocCtx<'tcx> {
) -> Stmt {
let arg1 = fargs.remove(0);
let arg2 = fargs.remove(0);
let msg1 = format!("first argument for {} is finite", intrinsic);
let msg2 = format!("second argument for {} is finite", intrinsic);
let msg1 = format!("first argument for {intrinsic} is finite");
let msg2 = format!("second argument for {intrinsic} is finite");
let loc = self.codegen_span_option(span);
let finite_check1 = self.codegen_assert_assume(
arg1.is_finite(),
Expand Down Expand Up @@ -809,7 +809,7 @@ impl<'tcx> GotocCtx<'tcx> {
if layout.abi.is_uninhabited() {
return self.codegen_fatal_error(
PropertyClass::SafetyCheck,
&format!("attempted to instantiate uninhabited type `{}`", ty),
&format!("attempted to instantiate uninhabited type `{ty}`"),
span,
);
}
Expand All @@ -819,15 +819,15 @@ impl<'tcx> GotocCtx<'tcx> {
if intrinsic == "assert_zero_valid" && !self.tcx.permits_zero_init(layout) {
return self.codegen_fatal_error(
PropertyClass::SafetyCheck,
&format!("attempted to zero-initialize type `{}`, which is invalid", ty),
&format!("attempted to zero-initialize type `{ty}`, which is invalid"),
span,
);
}

if intrinsic == "assert_uninit_valid" && !self.tcx.permits_uninit_init(layout) {
return self.codegen_fatal_error(
PropertyClass::SafetyCheck,
&format!("attempted to leave type `{}` uninitialized, which is invalid", ty),
&format!("attempted to leave type `{ty}` uninitialized, which is invalid"),
span,
);
}
Expand Down Expand Up @@ -1180,7 +1180,7 @@ impl<'tcx> GotocCtx<'tcx> {
ret_ty: Ty<'tcx>,
p: &Place<'tcx>,
) -> Stmt {
assert!(fargs.len() == 1, "transmute had unexpected arguments {:?}", fargs);
assert!(fargs.len() == 1, "transmute had unexpected arguments {fargs:?}");
let arg = fargs.remove(0);
let cbmc_ret_ty = self.codegen_ty(ret_ty);
let expr = arg.transmute_to(cbmc_ret_ty, &self.symbol_table);
Expand Down Expand Up @@ -1344,7 +1344,7 @@ impl<'tcx> GotocCtx<'tcx> {
cbmc_ret_ty: Type,
loc: Location,
) -> Stmt {
assert!(fargs.len() == 3, "simd_insert had unexpected arguments {:?}", fargs);
assert!(fargs.len() == 3, "simd_insert had unexpected arguments {fargs:?}");
let vec = fargs.remove(0);
let index = fargs.remove(0);
let newval = fargs.remove(0);
Expand Down Expand Up @@ -1377,7 +1377,7 @@ impl<'tcx> GotocCtx<'tcx> {
cbmc_ret_ty: Type,
n: u64,
) -> Stmt {
assert!(fargs.len() == 3, "simd_shuffle had unexpected arguments {:?}", fargs);
assert!(fargs.len() == 3, "simd_shuffle had unexpected arguments {fargs:?}");
// vector, size n: translated as vector types which cbmc treats as arrays
let vec1 = fargs.remove(0);
let vec2 = fargs.remove(0);
Expand Down Expand Up @@ -1520,7 +1520,7 @@ impl<'tcx> GotocCtx<'tcx> {
let size_of_elem = Expr::int_constant(layout.size.bytes(), res_ty);
let size_of_count_elems = count.mul_overflow(size_of_elem);
let message =
format!("{}: attempt to compute number in bytes which would overflow", intrinsic);
format!("{intrinsic}: attempt to compute number in bytes which would overflow");
let assert_stmt = self.codegen_assert_assume(
size_of_count_elems.overflowed.not(),
PropertyClass::ArithmeticOverflow,
Expand Down
6 changes: 3 additions & 3 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,15 @@ impl<'tcx> GotocCtx<'tcx> {
// Full (mangled) crate name added so that allocations from different
// crates do not conflict. The name alone is insufficient because Rust
// allows different versions of the same crate to be used.
let name = format!("{}::{:?}", self.full_crate_name(), alloc_id);
let name = format!("{}::{alloc_id:?}", self.full_crate_name());
self.codegen_allocation(alloc.inner(), |_| name.clone(), Some(name.clone()))
}
GlobalAlloc::VTable(ty, trait_ref) => {
// This is similar to GlobalAlloc::Memory but the type is opaque to rust and it
// requires a bit more logic to get information about the allocation.
let alloc_id = self.tcx.vtable_allocation((ty, trait_ref));
let alloc = self.tcx.global_alloc(alloc_id).unwrap_memory();
let name = format!("{}::{:?}", self.full_crate_name(), alloc_id);
let name = format!("{}::{alloc_id:?}", self.full_crate_name());
self.codegen_allocation(alloc.inner(), |_| name.clone(), Some(name.clone()))
}
};
Expand Down Expand Up @@ -529,7 +529,7 @@ impl<'tcx> GotocCtx<'tcx> {
/// Codegen alloc as a static global variable with initial value
fn codegen_alloc_in_memory(&mut self, alloc: &'tcx Allocation, name: String) {
debug!("codegen_alloc_in_memory name: {}", name);
let struct_name = &format!("{}::struct", name);
let struct_name = &format!("{name}::struct");

// The declaration of a static variable may have one type and the constant initializer for
// a static variable may have a different type. This is because Rust uses bit patterns for
Expand Down
Loading

0 comments on commit 3396936

Please sign in to comment.