Skip to content

Commit 3ea9c4e

Browse files
emesaremkrasnitski
andcommitted
Misc clippy lints and clippy CI
Co-authored-by: Michael Krasnitski <michael.krasnitski@gmail.com>
1 parent 807526d commit 3ea9c4e

28 files changed

+87
-87
lines changed

.github/workflows/rust.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,23 @@ on:
1010
- 'rust/**'
1111

1212
jobs:
13-
# TODO: Cargo clippy (just warnings don't fail)
1413
# TODO: Cargo test (we would need to pull in binary ninja)
14+
# Check lints with clippy
15+
clippy:
16+
name: cargo clippy
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
# Ensure clippy is installed
21+
- uses: actions-rust-lang/setup-rust-toolchain@v1
22+
with:
23+
components: clippy
24+
- name: Clippy Check
25+
- uses: clechasseur/rs-clippy-check@v4
26+
with:
27+
working-directory: ./rust
28+
args: --all-features
29+
1530
# Check formatting with rustfmt
1631
formatting:
1732
name: cargo fmt

rust/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
let _ = std::fs::create_dir("target/doc");
66
let _ = std::fs::copy("../docs/img/favicon.ico", "target/doc/favicon.ico");
77
let _ = std::fs::copy(
8-
"under_construction.png",
8+
"assets/under_construction.png",
99
"target/doc/under_construction.png",
1010
);
1111
let _ = std::fs::copy("../docs/img/logo.png", "target/doc/logo.png");

rust/examples/workflow.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use binaryninja::binaryview::BinaryViewExt;
22
use binaryninja::llil::{ExprInfo, LiftedNonSSA, NonSSA, VisitorAction};
33
use binaryninja::workflow::{Activity, AnalysisContext, Workflow};
44

5-
const RUST_ACTIVITY_NAME: &'static str = "analysis.plugins.rustexample";
6-
const RUST_ACTIVITY_CONFIG: &'static str = r#"{
5+
const RUST_ACTIVITY_NAME: &str = "analysis.plugins.rustexample";
6+
const RUST_ACTIVITY_CONFIG: &str = r#"{
77
"name": "analysis.plugins.rustexample",
88
"title" : "Rust Example",
99
"description": "This analysis step logs out some information about the function...",
@@ -27,18 +27,15 @@ fn example_activity(analysis_context: &AnalysisContext) {
2727
for instr in basic_block.iter() {
2828
if let Some(llil_instr) = llil.instruction_at(instr) {
2929
llil_instr.visit_tree(&mut |expr, info| {
30-
match info {
31-
ExprInfo::Const(_op) => {
32-
// Replace all consts with 0x1337.
33-
println!(
34-
"Replacing llil expression @ 0x{:x} : {}",
35-
instr, expr.index
36-
);
37-
unsafe {
38-
llil.replace_expression(expr.index, llil.const_int(4, 0x1337))
39-
};
40-
}
41-
_ => {}
30+
if let ExprInfo::Const(_op) = info {
31+
// Replace all consts with 0x1337.
32+
println!(
33+
"Replacing llil expression @ 0x{:x} : {}",
34+
instr, expr.index
35+
);
36+
unsafe {
37+
llil.replace_expression(expr.index, llil.const_int(4, 0x1337))
38+
};
4239
}
4340
VisitorAction::Descend
4441
});

rust/src/architecture.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ impl From<BNInstructionInfo> for InstructionInfo {
200200
fn from(value: BNInstructionInfo) -> Self {
201201
// TODO: This is quite ugly, but we destructure the branch info so this will have to do.
202202
let mut branch_info = [None; NUM_BRANCH_INFO];
203+
#[allow(clippy::needless_range_loop)]
203204
for i in 0..value.branchCount.min(NUM_BRANCH_INFO) {
204205
let branch_target = value.branchTarget[i];
205206
branch_info[i] = Some(BranchInfo {

rust/src/basicblock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl<C: BlockContext> BasicBlock<C> {
240240
// TODO iterated dominance frontier
241241
}
242242

243-
impl<'a, C: BlockContext> IntoIterator for &'a BasicBlock<C> {
243+
impl<C: BlockContext> IntoIterator for &BasicBlock<C> {
244244
type Item = C::Instruction;
245245
type IntoIter = C::Iter;
246246

rust/src/binaryview.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ pub trait BinaryViewExt: BinaryViewBase {
678678
let name_array = unsafe { Array::<QualifiedName>::new(result_names, result_count, ()) };
679679
id_array
680680
.into_iter()
681-
.zip(name_array.into_iter())
681+
.zip(&name_array)
682682
.map(|(id, name)| (id.to_owned(), name))
683683
.collect()
684684
}

rust/src/component.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,10 @@ impl Component {
146146
}
147147

148148
/// Original name set for this component
149-
150149
/// :note: The `.display_name` property should be used for `bv.get_component_by_path()` lookups.
151-
152150
/// This can differ from the .display_name property if one of its sibling components has the same .original_name; In that
153151
/// case, .name will be an automatically generated unique name (e.g. "MyComponentName (1)") while .original_name will
154152
/// remain what was originally set (e.g. "MyComponentName")
155-
156153
/// If this component has a duplicate name and is moved to a component where none of its siblings share its name,
157154
/// .name will return the original "MyComponentName"
158155
pub fn name(&self) -> BnString {

rust/src/confidence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<T> From<T> for Conf<T> {
189189
}
190190
}
191191

192-
impl<'a> Conf<&'a Type> {
192+
impl Conf<&'_ Type> {
193193
pub(crate) fn into_raw(value: Self) -> BNTypeWithConfidence {
194194
BNTypeWithConfidence {
195195
type_: value.contents.handle,

rust/src/databuffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl DataBuffer {
172172

173173
impl Default for DataBuffer {
174174
fn default() -> Self {
175-
Self(unsafe { BNCreateDataBuffer([].as_ptr() as *const c_void, 0) })
175+
Self(unsafe { BNCreateDataBuffer([].as_ptr(), 0) })
176176
}
177177
}
178178

rust/src/demangle.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,7 @@ impl Demangler {
301301
})
302302
}
303303

304-
extern "C" fn cb_free_var_name<C>(_ctxt: *mut c_void, name: *mut BNQualifiedName)
305-
where
306-
C: CustomDemangler,
307-
{
304+
extern "C" fn cb_free_var_name(_ctxt: *mut c_void, name: *mut BNQualifiedName) {
308305
ffi_wrap!("CustomDemangler::cb_free_var_name", unsafe {
309306
// TODO: What is the point of this free callback?
310307
QualifiedName::free_raw(*name)
@@ -319,7 +316,7 @@ impl Demangler {
319316
context: ctxt as *mut c_void,
320317
isMangledString: Some(cb_is_mangled_string::<C>),
321318
demangle: Some(cb_demangle::<C>),
322-
freeVarName: Some(cb_free_var_name::<C>),
319+
freeVarName: Some(cb_free_var_name),
323320
};
324321

325322
unsafe {

0 commit comments

Comments
 (0)