Skip to content

Commit 43cb18c

Browse files
authored
Fix some clippy warnings (rust-lang#1429)
1 parent 2f5bdf2 commit 43cb18c

File tree

12 files changed

+29
-45
lines changed

12 files changed

+29
-45
lines changed

.cargo/config.toml

-15
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,14 @@ rustflags = [ # Global lints/warnings. Need to use underscore instead of -.
99
"-Aclippy::or_fun_call",
1010

1111
# todo address the following lints.
12-
"-Aclippy::cargo_common_metadata",
1312
"-Aclippy::derive_partial_eq_without_eq",
14-
"-Aclippy::explicit_auto_deref",
15-
"-Aclippy::if_same_then_else",
16-
"-Aclippy::iter_nth_zero",
17-
"-Aclippy::let_and_return",
1813
"-Aclippy::manual_map",
1914
"-Aclippy::manual_range_contains",
20-
"-Aclippy::manual_strip",
2115
"-Aclippy::map_entry",
22-
"-Aclippy::match_like_matches_macro",
2316
"-Aclippy::missing_safety_doc",
2417
"-Aclippy::module_inception",
25-
"-Aclippy::needless_arbitrary_self_type",
26-
"-Aclippy::needless_bool",
27-
"-Aclippy::needless_return",
2818
"-Aclippy::new_ret_no_self",
2919
"-Aclippy::new_without_default",
30-
"-Aclippy::redundant_clone",
3120
"-Aclippy::too_many_arguments",
3221
"-Aclippy::type_complexity",
33-
"-Aclippy::unnecessary_lazy_evaluations",
34-
"-Aclippy::useless_conversion",
35-
"-Aclippy::needless_borrow",
36-
"-Aclippy::unnecessary_filter_map",
3722
]

cprover_bindings/src/goto_program/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ impl Expr {
330330
pub fn can_cast_from(source: &Type, target: &Type) -> bool {
331331
let source = source.unwrap_typedef();
332332
let target = target.unwrap_typedef();
333+
#[allow(clippy::needless_bool)]
333334
if source == target {
334335
true
335336
} else if target.is_bool() {

cprover_bindings/src/goto_program/symtab_transformer/passes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ pub fn do_passes(mut symtab: SymbolTable, pass_names: &[String]) -> SymbolTable
1616
// the other two identifiers
1717
let symtab = ExprTransformer::transform(&symtab);
1818
let symtab = NondetTransformer::transform(&symtab);
19-
let symtab = NameTransformer::transform(&symtab);
20-
symtab
19+
NameTransformer::transform(&symtab)
2120
}
2221
"identity" => IdentityTransformer::transform(&symtab),
2322
_ => panic!("Invalid symbol table transformation: {}", pass_name),

kani-compiler/src/codegen_cprover_gotoc/codegen/function.rs

-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ impl<'tcx> GotocCtx<'tcx> {
335335
self.tcx
336336
.sess
337337
.span_err(attr.span, "Exactly one Unwind Argument as Integer accepted");
338-
return;
339338
}
340339
Some(unwind_integer_value) => {
341340
let val: Result<u32, _> = unwind_integer_value.try_into();

kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,8 @@ impl<'tcx> GotocCtx<'tcx> {
604604
"simd_rem" => unstable_codegen!(codegen_intrinsic_binop!(rem)),
605605
"simd_shl" => unstable_codegen!(codegen_intrinsic_binop!(shl)),
606606
"simd_shr" => {
607+
// Remove this attribute once unstable_codegen! is removed.
608+
#[allow(clippy::if_same_then_else)]
607609
if fargs[0].typ().base_type().unwrap().is_signed(self.symbol_table.machine_model())
608610
{
609611
unstable_codegen!(codegen_intrinsic_binop!(ashr))

kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ impl<'tcx> GotocCtx<'tcx> {
681681
let fn_singleton = self.ensure_global_var(
682682
&fn_singleton_name,
683683
false,
684-
fn_struct_ty.clone(),
684+
fn_struct_ty,
685685
Location::none(),
686686
|_, _| None, // zero-sized, so no initialization necessary
687687
);

kani-compiler/src/codegen_cprover_gotoc/codegen/place.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<'tcx> GotocCtx<'tcx> {
277277
}
278278
ty::Closure(..) => Ok(res.member(&f.index().to_string(), &self.symbol_table)),
279279
ty::Generator(..) => {
280-
let field_name = self.generator_field_name(f.index().into());
280+
let field_name = self.generator_field_name(f.index());
281281
Ok(res
282282
.member("direct_fields", &self.symbol_table)
283283
.member(field_name, &self.symbol_table))
@@ -291,7 +291,7 @@ impl<'tcx> GotocCtx<'tcx> {
291291
Ok(res.member(&field.name.to_string(), &self.symbol_table))
292292
}
293293
TypeOrVariant::GeneratorVariant(_var_idx) => {
294-
let field_name = self.generator_field_name(f.index().into());
294+
let field_name = self.generator_field_name(f.index());
295295
Ok(res.member(field_name, &self.symbol_table))
296296
}
297297
}

kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,10 @@ impl<'tcx> GotocCtx<'tcx> {
689689
.tcx
690690
.normalize_erasing_regions(ty::ParamEnv::reveal_all(), src_subt);
691691
match src_subt.kind() {
692-
ty::Slice(_) | ty::Str | ty::Dynamic(..) => {
693-
return self
694-
.codegen_operand(src)
695-
.member("data", &self.symbol_table)
696-
.cast_to(self.codegen_ty(dst_t));
697-
}
692+
ty::Slice(_) | ty::Str | ty::Dynamic(..) => self
693+
.codegen_operand(src)
694+
.member("data", &self.symbol_table)
695+
.cast_to(self.codegen_ty(dst_t)),
698696
_ => self.codegen_operand(src).cast_to(self.codegen_ty(dst_t)),
699697
}
700698
}

kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -609,23 +609,23 @@ impl<'tcx> GotocCtx<'tcx> {
609609
}
610610
};
611611
stmts.push(self.codegen_end_call(target.as_ref(), loc));
612-
return Stmt::block(stmts, loc);
612+
Stmt::block(stmts, loc)
613613
}
614614
// Function call through a pointer
615615
ty::FnPtr(_) => {
616616
let func_expr = self.codegen_operand(func).dereference();
617617
// Actually generate the function call and return.
618-
return Stmt::block(
618+
Stmt::block(
619619
vec![
620620
self.codegen_expr_to_place(destination, func_expr.call(fargs))
621621
.with_location(loc),
622622
Stmt::goto(self.current_fn().find_label(&target.unwrap()), loc),
623623
],
624624
loc,
625-
);
625+
)
626626
}
627627
x => unreachable!("Function call where the function was of unexpected type: {:?}", x),
628-
};
628+
}
629629
}
630630

631631
/// Extract a reference to self for virtual method calls.

kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ impl<'tcx> GotocCtx<'tcx> {
667667
self.ensure_struct(
668668
self.ty_mangled_name(ty),
669669
self.ty_pretty_name(ty),
670-
|tcx, _| tcx.codegen_ty_tuple_fields(ty, *ts),
670+
|tcx, _| tcx.codegen_ty_tuple_fields(ty, ts),
671671
)
672672
}
673673
}
@@ -786,7 +786,7 @@ impl<'tcx> GotocCtx<'tcx> {
786786
}
787787
final_fields.extend(self.codegen_alignment_padding(
788788
offset,
789-
&layout,
789+
layout,
790790
final_fields.len(),
791791
));
792792
final_fields
@@ -991,7 +991,7 @@ impl<'tcx> GotocCtx<'tcx> {
991991
let field_name = if Some(idx) == discriminant_field {
992992
"case".into()
993993
} else {
994-
ctx.generator_field_name(idx).into()
994+
ctx.generator_field_name(idx)
995995
};
996996
let field_ty = type_and_layout.field(ctx, idx).ty;
997997
let field_offset = type_and_layout.fields.offset(idx);
@@ -1139,24 +1139,24 @@ impl<'tcx> GotocCtx<'tcx> {
11391139
let params = sig
11401140
.inputs()
11411141
.iter()
1142-
.filter_map(|arg_type| {
1142+
.map(|arg_type| {
11431143
if is_first {
11441144
is_first = false;
11451145
debug!(self_type=?arg_type, fn_signature=?sig, "codegen_dynamic_function_sig");
11461146
if arg_type.is_ref() {
11471147
// Convert fat pointer to thin pointer to data portion.
11481148
let first_ty = pointee_type(*arg_type).unwrap();
1149-
Some(self.codegen_trait_data_pointer(first_ty))
1149+
self.codegen_trait_data_pointer(first_ty)
11501150
} else if arg_type.is_trait() {
11511151
// Convert dyn T to thin pointer.
1152-
Some(self.codegen_trait_data_pointer(*arg_type))
1152+
self.codegen_trait_data_pointer(*arg_type)
11531153
} else {
11541154
// Codegen type with thin pointer (E.g.: Box<dyn T> -> Box<data_ptr>).
1155-
Some(self.codegen_trait_receiver(*arg_type))
1155+
self.codegen_trait_receiver(*arg_type)
11561156
}
11571157
} else {
11581158
debug!("Using type {:?} in function signature", arg_type);
1159-
Some(self.codegen_ty(*arg_type))
1159+
self.codegen_ty(*arg_type)
11601160
}
11611161
})
11621162
.collect();
@@ -1404,7 +1404,7 @@ impl<'tcx> GotocCtx<'tcx> {
14041404
// fields.
14051405
Some(
14061406
lo.fields()
1407-
.offset(lo.fields().index_by_increasing_offset().nth(0).unwrap()),
1407+
.offset(lo.fields().index_by_increasing_offset().next().unwrap()),
14081408
)
14091409
}
14101410
})
@@ -1700,7 +1700,7 @@ impl<'tcx> GotocCtx<'tcx> {
17001700
/// Pre-condition: The argument must be a valid receiver for dispatchable trait functions.
17011701
/// See <https://doc.rust-lang.org/reference/items/traits.html#object-safety> for more details.
17021702
pub fn receiver_data_path<'a>(
1703-
self: &'a Self,
1703+
&'a self,
17041704
typ: Ty<'tcx>,
17051705
) -> impl Iterator<Item = (String, Ty<'tcx>)> + 'a {
17061706
struct ReceiverIter<'tcx, 'a> {

kani-driver/src/call_cargo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ impl KaniSession {
7676
outdir: outdir.clone(),
7777
symtabs: vec![outdir.join("*.symtab.json")],
7878
metadata: vec![outdir.join("*.kani-metadata.json")],
79-
restrictions: self.args.restrict_vtable().then(|| outdir),
79+
restrictions: self.args.restrict_vtable().then_some(outdir),
8080
});
8181
}
8282

8383
Ok(CargoOutputs {
8484
outdir: outdir.clone(),
8585
symtabs: glob(&outdir.join("*.symtab.json"))?,
8686
metadata: glob(&outdir.join("*.kani-metadata.json"))?,
87-
restrictions: self.args.restrict_vtable().then(|| outdir),
87+
restrictions: self.args.restrict_vtable().then_some(outdir),
8888
})
8989
}
9090
}

tools/compiletest/src/header.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ fn iter_header<R: Read>(testfile: &Path, rdr: R, it: &mut dyn FnMut(Option<&str>
115115
let ln = ln.trim();
116116
if ln.starts_with("fn") || ln.starts_with("mod") {
117117
return;
118-
} else if ln.starts_with(comment) {
119-
it(None, ln[comment.len()..].trim_start());
118+
} else if let Some(rest) = ln.strip_prefix(comment) {
119+
it(None, rest.trim_start());
120120
}
121121
}
122122
}

0 commit comments

Comments
 (0)