Skip to content
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

Fix some clippy warnings #1429

Merged
merged 4 commits into from
Aug 2, 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
15 changes: 0 additions & 15 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,14 @@ rustflags = [ # Global lints/warnings. Need to use underscore instead of -.
"-Aclippy::or_fun_call",

# todo address the following lints.
"-Aclippy::cargo_common_metadata",
"-Aclippy::derive_partial_eq_without_eq",
"-Aclippy::explicit_auto_deref",
"-Aclippy::if_same_then_else",
"-Aclippy::iter_nth_zero",
"-Aclippy::let_and_return",
"-Aclippy::manual_map",
"-Aclippy::manual_range_contains",
"-Aclippy::manual_strip",
"-Aclippy::map_entry",
"-Aclippy::match_like_matches_macro",
"-Aclippy::missing_safety_doc",
"-Aclippy::module_inception",
"-Aclippy::needless_arbitrary_self_type",
"-Aclippy::needless_bool",
"-Aclippy::needless_return",
"-Aclippy::new_ret_no_self",
"-Aclippy::new_without_default",
"-Aclippy::redundant_clone",
"-Aclippy::too_many_arguments",
"-Aclippy::type_complexity",
"-Aclippy::unnecessary_lazy_evaluations",
"-Aclippy::useless_conversion",
"-Aclippy::needless_borrow",
"-Aclippy::unnecessary_filter_map",
]
1 change: 1 addition & 0 deletions cprover_bindings/src/goto_program/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ impl Expr {
pub fn can_cast_from(source: &Type, target: &Type) -> bool {
let source = source.unwrap_typedef();
let target = target.unwrap_typedef();
#[allow(clippy::needless_bool)]
if source == target {
true
} else if target.is_bool() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ pub fn do_passes(mut symtab: SymbolTable, pass_names: &[String]) -> SymbolTable
// the other two identifiers
let symtab = ExprTransformer::transform(&symtab);
let symtab = NondetTransformer::transform(&symtab);
let symtab = NameTransformer::transform(&symtab);
symtab
NameTransformer::transform(&symtab)
}
"identity" => IdentityTransformer::transform(&symtab),
_ => panic!("Invalid symbol table transformation: {}", pass_name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ impl<'tcx> GotocCtx<'tcx> {
self.tcx
.sess
.span_err(attr.span, "Exactly one Unwind Argument as Integer accepted");
return;
}
Some(unwind_integer_value) => {
let val: Result<u32, _> = unwind_integer_value.try_into();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ impl<'tcx> GotocCtx<'tcx> {
"simd_rem" => unstable_codegen!(codegen_intrinsic_binop!(rem)),
"simd_shl" => unstable_codegen!(codegen_intrinsic_binop!(shl)),
"simd_shr" => {
// Remove this attribute once unstable_codegen! is removed.
#[allow(clippy::if_same_then_else)]
if fargs[0].typ().base_type().unwrap().is_signed(self.symbol_table.machine_model())
{
unstable_codegen!(codegen_intrinsic_binop!(ashr))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ impl<'tcx> GotocCtx<'tcx> {
let fn_singleton = self.ensure_global_var(
&fn_singleton_name,
false,
fn_struct_ty.clone(),
fn_struct_ty,
Location::none(),
|_, _| None, // zero-sized, so no initialization necessary
);
Expand Down
4 changes: 2 additions & 2 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl<'tcx> GotocCtx<'tcx> {
}
ty::Closure(..) => Ok(res.member(&f.index().to_string(), &self.symbol_table)),
ty::Generator(..) => {
let field_name = self.generator_field_name(f.index().into());
let field_name = self.generator_field_name(f.index());
Ok(res
.member("direct_fields", &self.symbol_table)
.member(field_name, &self.symbol_table))
Expand All @@ -291,7 +291,7 @@ impl<'tcx> GotocCtx<'tcx> {
Ok(res.member(&field.name.to_string(), &self.symbol_table))
}
TypeOrVariant::GeneratorVariant(_var_idx) => {
let field_name = self.generator_field_name(f.index().into());
let field_name = self.generator_field_name(f.index());
Ok(res.member(field_name, &self.symbol_table))
}
}
Expand Down
10 changes: 4 additions & 6 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,10 @@ impl<'tcx> GotocCtx<'tcx> {
.tcx
.normalize_erasing_regions(ty::ParamEnv::reveal_all(), src_subt);
match src_subt.kind() {
ty::Slice(_) | ty::Str | ty::Dynamic(..) => {
return self
.codegen_operand(src)
.member("data", &self.symbol_table)
.cast_to(self.codegen_ty(dst_t));
}
ty::Slice(_) | ty::Str | ty::Dynamic(..) => self
.codegen_operand(src)
.member("data", &self.symbol_table)
.cast_to(self.codegen_ty(dst_t)),
_ => self.codegen_operand(src).cast_to(self.codegen_ty(dst_t)),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,23 +609,23 @@ impl<'tcx> GotocCtx<'tcx> {
}
};
stmts.push(self.codegen_end_call(target.as_ref(), loc));
return Stmt::block(stmts, loc);
Stmt::block(stmts, loc)
}
// Function call through a pointer
ty::FnPtr(_) => {
let func_expr = self.codegen_operand(func).dereference();
// Actually generate the function call and return.
return Stmt::block(
Stmt::block(
vec![
self.codegen_expr_to_place(destination, func_expr.call(fargs))
.with_location(loc),
Stmt::goto(self.current_fn().find_label(&target.unwrap()), loc),
],
loc,
);
)
}
x => unreachable!("Function call where the function was of unexpected type: {:?}", x),
};
}
}

/// Extract a reference to self for virtual method calls.
Expand Down
20 changes: 10 additions & 10 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ impl<'tcx> GotocCtx<'tcx> {
self.ensure_struct(
self.ty_mangled_name(ty),
self.ty_pretty_name(ty),
|tcx, _| tcx.codegen_ty_tuple_fields(ty, *ts),
|tcx, _| tcx.codegen_ty_tuple_fields(ty, ts),
)
}
}
Expand Down Expand Up @@ -786,7 +786,7 @@ impl<'tcx> GotocCtx<'tcx> {
}
final_fields.extend(self.codegen_alignment_padding(
offset,
&layout,
layout,
final_fields.len(),
));
final_fields
Expand Down Expand Up @@ -991,7 +991,7 @@ impl<'tcx> GotocCtx<'tcx> {
let field_name = if Some(idx) == discriminant_field {
"case".into()
} else {
ctx.generator_field_name(idx).into()
ctx.generator_field_name(idx)
};
let field_ty = type_and_layout.field(ctx, idx).ty;
let field_offset = type_and_layout.fields.offset(idx);
Expand Down Expand Up @@ -1139,24 +1139,24 @@ impl<'tcx> GotocCtx<'tcx> {
let params = sig
.inputs()
.iter()
.filter_map(|arg_type| {
.map(|arg_type| {
if is_first {
is_first = false;
debug!(self_type=?arg_type, fn_signature=?sig, "codegen_dynamic_function_sig");
if arg_type.is_ref() {
// Convert fat pointer to thin pointer to data portion.
let first_ty = pointee_type(*arg_type).unwrap();
Some(self.codegen_trait_data_pointer(first_ty))
self.codegen_trait_data_pointer(first_ty)
} else if arg_type.is_trait() {
// Convert dyn T to thin pointer.
Some(self.codegen_trait_data_pointer(*arg_type))
self.codegen_trait_data_pointer(*arg_type)
} else {
// Codegen type with thin pointer (E.g.: Box<dyn T> -> Box<data_ptr>).
Some(self.codegen_trait_receiver(*arg_type))
self.codegen_trait_receiver(*arg_type)
}
} else {
debug!("Using type {:?} in function signature", arg_type);
Some(self.codegen_ty(*arg_type))
self.codegen_ty(*arg_type)
}
})
.collect();
Expand Down Expand Up @@ -1404,7 +1404,7 @@ impl<'tcx> GotocCtx<'tcx> {
// fields.
Some(
lo.fields()
.offset(lo.fields().index_by_increasing_offset().nth(0).unwrap()),
.offset(lo.fields().index_by_increasing_offset().next().unwrap()),
)
}
})
Expand Down Expand Up @@ -1700,7 +1700,7 @@ impl<'tcx> GotocCtx<'tcx> {
/// Pre-condition: The argument must be a valid receiver for dispatchable trait functions.
/// See <https://doc.rust-lang.org/reference/items/traits.html#object-safety> for more details.
pub fn receiver_data_path<'a>(
self: &'a Self,
&'a self,
typ: Ty<'tcx>,
) -> impl Iterator<Item = (String, Ty<'tcx>)> + 'a {
struct ReceiverIter<'tcx, 'a> {
Expand Down
4 changes: 2 additions & 2 deletions kani-driver/src/call_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ impl KaniSession {
outdir: outdir.clone(),
symtabs: vec![outdir.join("*.symtab.json")],
metadata: vec![outdir.join("*.kani-metadata.json")],
restrictions: self.args.restrict_vtable().then(|| outdir),
restrictions: self.args.restrict_vtable().then_some(outdir),
});
}

Ok(CargoOutputs {
outdir: outdir.clone(),
symtabs: glob(&outdir.join("*.symtab.json"))?,
metadata: glob(&outdir.join("*.kani-metadata.json"))?,
restrictions: self.args.restrict_vtable().then(|| outdir),
restrictions: self.args.restrict_vtable().then_some(outdir),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>
let ln = ln.trim();
if ln.starts_with("fn") || ln.starts_with("mod") {
return;
} else if ln.starts_with(comment) {
it(None, ln[comment.len()..].trim_start());
} else if let Some(rest) = ln.strip_prefix(comment) {
it(None, rest.trim_start());
}
}
}
Expand Down