Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zhassan-aws committed Feb 18, 2024
1 parent a7a35f1 commit 1024a7b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
12 changes: 7 additions & 5 deletions cprover_bindings/src/goto_program/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use self::BuiltinFn::*;
use super::{Expr, Location, Symbol, Type};

use std::fmt::Display;

#[derive(Debug, Clone, Copy)]
pub enum BuiltinFn {
Abort,
Expand Down Expand Up @@ -67,9 +69,9 @@ pub enum BuiltinFn {
Unlink,
}

impl ToString for BuiltinFn {
fn to_string(&self) -> String {
match self {
impl Display for BuiltinFn {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let func = match self {
Abort => "abort",
Assert => "assert",
CProverAssume => "__CPROVER_assume",
Expand Down Expand Up @@ -129,8 +131,8 @@ impl ToString for BuiltinFn {
Trunc => "trunc",
Truncf => "truncf",
Unlink => "unlink",
}
.to_string()
};
write!(f, "{func}")
}
}

Expand Down
15 changes: 8 additions & 7 deletions cprover_bindings/src/goto_program/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use super::super::utils::aggr_tag;
use super::{DatatypeComponent, Expr, Location, Parameter, Stmt, Type};
use crate::{InternStringOption, InternedString};

use std::fmt::Display;

/// Based off the CBMC symbol implementation here:
/// <https://github.com/diffblue/cbmc/blob/develop/src/util/symbol.h>
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -452,14 +454,13 @@ impl SymbolValues {
}
}

/// ToString

impl ToString for SymbolModes {
fn to_string(&self) -> String {
match self {
/// Display
impl Display for SymbolModes {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mode = match self {
SymbolModes::C => "C",
SymbolModes::Rust => "Rust",
}
.to_string()
};
write!(f, "{mode}")
}
}
20 changes: 13 additions & 7 deletions cprover_bindings/src/irep/irep_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::cbmc_string::InternedString;
use crate::utils::NumUtils;
use num::bigint::{BigInt, BigUint, Sign};

use std::fmt::Display;

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
pub enum IrepId {
/// In addition to the standard enums defined below, CBMC also allows ids to be strings.
Expand Down Expand Up @@ -872,15 +874,19 @@ impl IrepId {
}
}

impl ToString for IrepId {
fn to_string(&self) -> String {
impl Display for IrepId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
IrepId::FreeformString(s) => return s.to_string(),
IrepId::FreeformInteger(i) => return i.to_string(),
IrepId::FreeformString(s) => {
return write!(f, "{s}");
}
IrepId::FreeformInteger(i) => {
return write!(f, "{i}");
}
IrepId::FreeformBitPattern(i) => {
return format!("{i:X}");
return write!(f, "{i:X}");
}
_ => (),
_ => {}
}

let s = match self {
Expand Down Expand Up @@ -1708,7 +1714,7 @@ impl ToString for IrepId {
IrepId::VectorGt => "vector->",
IrepId::VectorLt => "vector-<",
};
s.to_string()
write!(f, "{s}")
}
}

Expand Down
4 changes: 2 additions & 2 deletions kani-compiler/src/kani_middle/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ fn resolve_rust_intrinsic<'tcx>(
func_ty: Ty<'tcx>,
) -> Option<(Symbol, GenericArgsRef<'tcx>)> {
if let ty::FnDef(def_id, args) = *func_ty.kind() {
if tcx.is_intrinsic(def_id) {
return Some((tcx.item_name(def_id), args));
if let Some(symbol) = tcx.intrinsic(def_id) {
return Some((symbol, args));
}
}
None
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# SPDX-License-Identifier: Apache-2.0 OR MIT

[toolchain]
channel = "nightly-2024-02-15"
channel = "nightly-2024-02-17"
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]

0 comments on commit 1024a7b

Please sign in to comment.