Skip to content

Commit 484cd30

Browse files
author
Carolyn Zech
authored
CI Formatting Fixes (model-checking#4028)
The majority of the changes in this PR were made automatically by running the command specified in 5314a5d, so the actual diff to review is much smaller than it initially appears. 1. If `--check` was provided to`kani-fmt.sh`, it would run `cargo fmt --check` but not `rustfmt --check`. This meant that our regression would catch formatting errors from `cargo fmt` but not `rustfmt` (it would just format the problematic files, which isn't useful in CI--we want it to fail instead). So add the `--check` flag to the `rustfmt` calls as well. 2. Run clippy with `kani_sysroot` feature enabled as well to catch more formatting errors. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 717e99d commit 484cd30

File tree

51 files changed

+286
-276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+286
-276
lines changed

.github/workflows/format-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
- name: 'Run Clippy'
4949
run: |
5050
cargo clippy --workspace -- -D warnings
51+
RUSTFLAGS="--cfg=kani_sysroot" cargo clippy --workspace -- -D warnings
5152
5253
- name: 'Print Clippy Statistics'
5354
run: |

cprover_bindings/src/irep/goto_binary_serde.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl IrepNumbering {
275275
return self.inv_cache.index[*number];
276276
}
277277
// This is where the key gets its unique number assigned.
278-
let number = self.inv_cache.add_key(&key);
278+
let number = self.inv_cache.add_key(key);
279279
self.cache.insert(key.clone(), number);
280280
self.inv_cache.index[number]
281281
}
@@ -449,17 +449,17 @@ where
449449
self.write_usize_varenc(num);
450450

451451
if self.is_first_write_irep(num) {
452-
let id = &self.numbering.id(&irep);
452+
let id = &self.numbering.id(irep);
453453
self.write_numbered_string_ref(id);
454454

455-
for sub_idx in 0..(self.numbering.nof_sub(&irep)) {
455+
for sub_idx in 0..(self.numbering.nof_sub(irep)) {
456456
self.write_u8(b'S');
457-
self.write_numbered_irep_ref(&self.numbering.sub(&irep, sub_idx));
457+
self.write_numbered_irep_ref(&self.numbering.sub(irep, sub_idx));
458458
}
459459

460-
for named_sub_idx in 0..(self.numbering.nof_named_sub(&irep)) {
460+
for named_sub_idx in 0..(self.numbering.nof_named_sub(irep)) {
461461
self.write_u8(b'N');
462-
let (k, v) = self.numbering.named_sub(&irep, named_sub_idx);
462+
let (k, v) = self.numbering.named_sub(irep, named_sub_idx);
463463
self.write_numbered_string_ref(&k);
464464
self.write_numbered_irep_ref(&v);
465465
}
@@ -1339,7 +1339,7 @@ mod tests {
13391339
let mut writer = BufWriter::new(&mut vec);
13401340
let mut serializer = GotoBinarySerializer::new(&mut writer);
13411341
for string in strings.iter() {
1342-
serializer.write_string_ref(&string);
1342+
serializer.write_string_ref(string);
13431343
}
13441344
println!("Serializer stats {:?}", serializer.get_stats());
13451345
}
@@ -1365,12 +1365,12 @@ mod tests {
13651365
let mut serializer = GotoBinarySerializer::new(&mut writer);
13661366

13671367
// Number an irep
1368-
let num1 = serializer.numbering.number_irep(&irep1);
1368+
let num1 = serializer.numbering.number_irep(irep1);
13691369

13701370
// Number an structurally different irep
13711371
let identifiers2 = vec!["foo", "bar", "baz", "different", "zab", "rab", "oof"];
13721372
let irep2 = &fold_with_op(&identifiers2, IrepId::And);
1373-
let num2 = serializer.numbering.number_irep(&irep2);
1373+
let num2 = serializer.numbering.number_irep(irep2);
13741374

13751375
// Check that they have the different numbers.
13761376
assert_ne!(num1, num2);

cprover_bindings/src/irep/symbol_table.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ pub struct SymbolTable {
1212
}
1313

1414
/// Constructors
15+
impl Default for SymbolTable {
16+
fn default() -> Self {
17+
Self::new()
18+
}
19+
}
20+
1521
impl SymbolTable {
1622
pub fn new() -> SymbolTable {
1723
SymbolTable { symbol_table: BTreeMap::new() }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ impl GotocCtx<'_> {
564564
self.intrinsics_typecheck_fail(span, "ctpop", "integer type", arg_rust_ty)
565565
} else {
566566
let loc = self.codegen_span_stable(span);
567-
self.codegen_expr_to_place_stable(&target_place, arg.popcount(), loc)
567+
self.codegen_expr_to_place_stable(target_place, arg.popcount(), loc)
568568
}
569569
}
570570

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl<'tcx> GotocCtx<'tcx> {
335335
let typ = self.codegen_ty_stable(ty);
336336
let operation_name = "C string literal";
337337
self.codegen_unimplemented_expr(
338-
&operation_name,
338+
operation_name,
339339
typ,
340340
loc,
341341
"https://github.com/model-checking/kani/issues/2549",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl GotocCtx<'_> {
731731
}
732732
}
733733
}
734-
AggregateKind::Coroutine(_, _, _) => self.codegen_rvalue_coroutine(&operands, res_ty),
734+
AggregateKind::Coroutine(_, _, _) => self.codegen_rvalue_coroutine(operands, res_ty),
735735
AggregateKind::CoroutineClosure(_, _) => {
736736
let ty = self.codegen_ty_stable(res_ty);
737737
self.codegen_unimplemented_expr(
@@ -751,10 +751,10 @@ impl GotocCtx<'_> {
751751
Rvalue::Use(p) => self.codegen_operand_stable(p),
752752
Rvalue::Repeat(op, sz) => self.codegen_rvalue_repeat(op, sz, loc),
753753
Rvalue::Ref(_, _, p) | Rvalue::AddressOf(_, p) => {
754-
let place_ref = self.codegen_place_ref_stable(&p, loc);
754+
let place_ref = self.codegen_place_ref_stable(p, loc);
755755
let place_ref_type = place_ref.typ().clone();
756756
match self.codegen_raw_ptr_deref_validity_check(
757-
&p,
757+
p,
758758
place_ref.clone(),
759759
self.place_ty_stable(p),
760760
&loc,

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ impl GotocCtx<'_> {
5959
let arg = parse_word(attr).expect(
6060
"incorrect value passed to `disable_checks`, expected a single identifier",
6161
);
62-
*PRAGMAS.get(arg.as_str()).expect(format!(
63-
"attempting to disable an unexisting check, the possible options are {:?}",
64-
PRAGMAS.keys()
65-
).as_str())
62+
*PRAGMAS.get(arg.as_str()).unwrap_or_else(|| panic!("attempting to disable an unexisting check, the possible options are {:?}",
63+
PRAGMAS.keys()))
6664
})
6765
.collect::<Vec<_>>()
6866
.leak() // This is to preserve `Location` being Copy, but could blow up the memory utilization of compiler.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl GotocCtx<'_> {
148148
// Pack the operands and their types, then call `codegen_copy`
149149
let fargs =
150150
operands.iter().map(|op| self.codegen_operand_stable(op)).collect::<Vec<_>>();
151-
let farg_types = operands.map(|op| self.operand_ty_stable(&op));
151+
let farg_types = operands.map(|op| self.operand_ty_stable(op));
152152
self.codegen_copy("copy_nonoverlapping", true, fargs, &farg_types, None, location)
153153
}
154154
// https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/mir/enum.NonDivergingIntrinsic.html#variant.Assume
@@ -168,7 +168,7 @@ impl GotocCtx<'_> {
168168
let instance = self.current_fn().instance_stable();
169169
let counter_data = format!("{coverage_opaque:?} ${function_name}$");
170170
let maybe_source_region =
171-
region_from_coverage_opaque(self.tcx, &coverage_opaque, instance);
171+
region_from_coverage_opaque(self.tcx, coverage_opaque, instance);
172172
if let Some((source_region, file_name)) = maybe_source_region {
173173
let coverage_stmt =
174174
self.codegen_coverage(&counter_data, stmt.span, source_region, &file_name);
@@ -621,8 +621,8 @@ impl GotocCtx<'_> {
621621
if def.as_intrinsic().unwrap().must_be_overridden() || !instance.has_body() {
622622
return self.codegen_funcall_of_intrinsic(
623623
instance,
624-
&args,
625-
&destination,
624+
args,
625+
destination,
626626
target.map(|bb| bb),
627627
span,
628628
);
@@ -638,10 +638,10 @@ impl GotocCtx<'_> {
638638
let mut fargs = if args.is_empty()
639639
|| fn_def.fn_sig().unwrap().value.abi != Abi::RustCall
640640
{
641-
self.codegen_funcall_args(&fn_abi, &args)
641+
self.codegen_funcall_args(&fn_abi, args)
642642
} else {
643643
let (untupled, first_args) = args.split_last().unwrap();
644-
let mut fargs = self.codegen_funcall_args(&fn_abi, &first_args);
644+
let mut fargs = self.codegen_funcall_args(&fn_abi, first_args);
645645
fargs.append(
646646
&mut self.codegen_untupled_args(untupled, &fn_abi.args[first_args.len()..]),
647647
);
@@ -688,11 +688,11 @@ impl GotocCtx<'_> {
688688
self.tcx
689689
.fn_abi_of_fn_ptr(
690690
TypingEnv::fully_monomorphized()
691-
.as_query_input((fn_sig_internal, &List::empty())),
691+
.as_query_input((fn_sig_internal, List::empty())),
692692
)
693693
.unwrap(),
694694
);
695-
let fargs = self.codegen_funcall_args(&fn_ptr_abi, &args);
695+
let fargs = self.codegen_funcall_args(&fn_ptr_abi, args);
696696
let func_expr = self.codegen_operand_stable(func).dereference();
697697
// Actually generate the function call and return.
698698
Stmt::block(

kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ impl GotocCodegenBackend {
201201
// No output should be generated if user selected no_codegen.
202202
if !tcx.sess.opts.unstable_opts.no_codegen && tcx.sess.opts.output_types.should_codegen() {
203203
let pretty = self.queries.lock().unwrap().args().output_pretty_json;
204-
write_file(&symtab_goto, ArtifactType::PrettyNameMap, &pretty_name_map, pretty);
204+
write_file(symtab_goto, ArtifactType::PrettyNameMap, &pretty_name_map, pretty);
205205
write_goto_binary_file(symtab_goto, &gcx.symbol_table);
206-
write_file(&symtab_goto, ArtifactType::TypeMap, &type_map, pretty);
206+
write_file(symtab_goto, ArtifactType::TypeMap, &type_map, pretty);
207207
// If they exist, write out vtable virtual call function pointer restrictions
208208
if let Some(restrictions) = vtable_restrictions {
209-
write_file(&symtab_goto, ArtifactType::VTableRestriction, &restrictions, pretty);
209+
write_file(symtab_goto, ArtifactType::VTableRestriction, &restrictions, pretty);
210210
}
211211
}
212212

@@ -294,7 +294,7 @@ impl CodegenBackend for GotocCodegenBackend {
294294
// We reset the body cache for now because each codegen unit has different
295295
// configurations that affect how we transform the instance body.
296296
for harness in &unit.harnesses {
297-
let transformer = BodyTransformation::new(&queries, tcx, &unit);
297+
let transformer = BodyTransformation::new(&queries, tcx, unit);
298298
let model_path = units.harness_model_path(*harness).unwrap();
299299
let is_automatic_harness = units.is_automatic_harness(harness);
300300
let contract_metadata =
@@ -355,14 +355,15 @@ impl CodegenBackend for GotocCodegenBackend {
355355
for (test_fn, test_desc) in harnesses.iter().zip(descriptions.iter()) {
356356
let instance =
357357
if let MonoItem::Fn(instance) = test_fn { instance } else { continue };
358-
let metadata =
359-
gen_test_metadata(tcx, *test_desc, *instance, &base_filename);
358+
let metadata = gen_test_metadata(tcx, *test_desc, *instance, base_filename);
360359
let test_model_path = &metadata.goto_file.as_ref().unwrap();
361-
std::fs::copy(&model_path, test_model_path).expect(&format!(
362-
"Failed to copy {} to {}",
363-
model_path.display(),
364-
test_model_path.display()
365-
));
360+
std::fs::copy(&model_path, test_model_path).unwrap_or_else(|_| {
361+
panic!(
362+
"Failed to copy {} to {}",
363+
model_path.display(),
364+
test_model_path.display()
365+
)
366+
});
366367
results.harnesses.push(metadata);
367368
}
368369
}
@@ -405,7 +406,7 @@ impl CodegenBackend for GotocCodegenBackend {
405406
// To avoid overriding the metadata for its verification, we skip this step when
406407
// reachability is None, even because there is nothing to record.
407408
write_file(
408-
&base_filename,
409+
base_filename,
409410
ArtifactType::Metadata,
410411
&results.generate_metadata(),
411412
queries.args().output_pretty_json,

kani-compiler/src/kani_middle/attributes.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,19 @@ impl<'tcx> KaniAttributes<'tcx> {
357357
}
358358
match kind {
359359
KaniAttributeKind::ShouldPanic => {
360-
expect_single(self.tcx, kind, &attrs);
360+
expect_single(self.tcx, kind, attrs);
361361
attrs.iter().for_each(|attr| {
362362
expect_no_args(self.tcx, kind, attr);
363363
})
364364
}
365365
KaniAttributeKind::Recursion => {
366-
expect_single(self.tcx, kind, &attrs);
366+
expect_single(self.tcx, kind, attrs);
367367
attrs.iter().for_each(|attr| {
368368
expect_no_args(self.tcx, kind, attr);
369369
})
370370
}
371371
KaniAttributeKind::Solver => {
372-
expect_single(self.tcx, kind, &attrs);
372+
expect_single(self.tcx, kind, attrs);
373373
attrs.iter().for_each(|attr| {
374374
parse_solver(self.tcx, attr);
375375
})
@@ -378,7 +378,7 @@ impl<'tcx> KaniAttributes<'tcx> {
378378
parse_stubs(self.tcx, self.item, attrs);
379379
}
380380
KaniAttributeKind::Unwind => {
381-
expect_single(self.tcx, kind, &attrs);
381+
expect_single(self.tcx, kind, attrs);
382382
attrs.iter().for_each(|attr| {
383383
parse_unwind(self.tcx, attr);
384384
})
@@ -389,7 +389,7 @@ impl<'tcx> KaniAttributes<'tcx> {
389389
"`proof` and `proof_for_contract` may not be used on the same function.".to_string(),
390390
);
391391
}
392-
expect_single(self.tcx, kind, &attrs);
392+
expect_single(self.tcx, kind, attrs);
393393
attrs.iter().for_each(|attr| self.check_proof_attribute(kind, attr))
394394
}
395395
KaniAttributeKind::Unstable => attrs.iter().for_each(|attr| {
@@ -401,7 +401,7 @@ impl<'tcx> KaniAttributes<'tcx> {
401401
"`proof` and `proof_for_contract` may not be used on the same function.".to_string(),
402402
);
403403
}
404-
expect_single(self.tcx, kind, &attrs);
404+
expect_single(self.tcx, kind, attrs);
405405
attrs.iter().for_each(|attr| self.check_proof_attribute(kind, attr))
406406
}
407407
KaniAttributeKind::StubVerified => {
@@ -721,7 +721,7 @@ pub fn test_harness_name(tcx: TyCtxt, def: &impl CrateDef) -> String {
721721
let def_id = rustc_internal::internal(tcx, def.def_id());
722722
let attrs = tcx.get_attrs_unchecked(def_id);
723723
let marker = attr::find_by_name(attrs, rustc_span::symbol::sym::rustc_test_marker).unwrap();
724-
parse_str_value(&marker).unwrap()
724+
parse_str_value(marker).unwrap()
725725
}
726726

727727
/// Expect the contents of this attribute to be of the format #[attribute =
@@ -749,9 +749,9 @@ fn expect_single<'a>(
749749
kind: KaniAttributeKind,
750750
attributes: &'a Vec<&'a Attribute>,
751751
) -> &'a Attribute {
752-
let attr = attributes
753-
.first()
754-
.expect(&format!("expected at least one attribute {} in {attributes:?}", kind.as_ref()));
752+
let attr = attributes.first().unwrap_or_else(|| {
753+
panic!("expected at least one attribute {} in {attributes:?}", kind.as_ref())
754+
});
755755
if attributes.len() > 1 {
756756
tcx.dcx().span_err(
757757
attr.span(),
@@ -1061,7 +1061,7 @@ fn syn_attr(tcx: TyCtxt, attr: &Attribute) -> syn::Attribute {
10611061
/// Parse a stable attribute using `syn`.
10621062
fn syn_attr_stable(attr: &AttributeStable) -> syn::Attribute {
10631063
let parser = syn::Attribute::parse_outer;
1064-
parser.parse_str(&attr.as_str()).unwrap().pop().unwrap()
1064+
parser.parse_str(attr.as_str()).unwrap().pop().unwrap()
10651065
}
10661066

10671067
/// Return a more user-friendly string for path by trying to remove unneeded whitespace.

0 commit comments

Comments
 (0)