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 "unused mut" warnings created by generated code. #3247

Merged
merged 5 commits into from
Jun 10, 2024
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
2 changes: 1 addition & 1 deletion library/kani_macros/src/sysroot/contracts/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<'a> ContractConditionsHandler<'a> {

let result = Ident::new(INTERNAL_RESULT_IDENT, Span::call_site());
self.output.extend(quote!(
#[allow(dead_code, unused_variables)]
#[allow(dead_code, unused_variables, unused_mut)]
#[kanitool::is_contract_generated(recursion_wrapper)]
#wrapper_sig {
static mut REENTRY: bool = false;
Expand Down
2 changes: 1 addition & 1 deletion library/kani_macros/src/sysroot/contracts/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'a> ContractConditionsHandler<'a> {
pub fn emit_common_header(&mut self) {
if self.function_state.emit_tag_attr() {
self.output.extend(quote!(
#[allow(dead_code, unused_variables)]
#[allow(dead_code, unused_variables, unused_mut)]
feliperodri marked this conversation as resolved.
Show resolved Hide resolved
));
}
self.output.extend(self.annotated_fn.attrs.iter().flat_map(Attribute::to_token_stream));
Expand Down
20 changes: 7 additions & 13 deletions tests/expected/function-contract/gcd_success.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Zfunction-contracts
#![deny(warnings)]
type T = u8;

/// Euclid's algorithm for calculating the GCD of two numbers
#[kani::requires(x != 0 && y != 0)]
#[kani::ensures(|result : &T| *result != 0 && x % *result == 0 && y % *result == 0)]
fn gcd(x: T, y: T) -> T {
let mut max = x;
let mut min = y;
if min > max {
let val = max;
max = min;
min = val;
}

fn gcd(mut x: T, mut y: T) -> T {
(x, y) = (if x > y { x } else { y }, if x > y { y } else { x });
loop {
let res = max % min;
let res = x % y;
if res == 0 {
return min;
return y;
}

max = min;
min = res;
x = y;
y = res;
}
}

Expand Down
Loading