Skip to content

Commit e30655c

Browse files
committed
Clippy fix and add CI workflows
1 parent f786255 commit e30655c

5 files changed

Lines changed: 19 additions & 15 deletions

File tree

.github/workflows/tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ jobs:
5757
- name: Ensure correct dependency resolution
5858
run: |
5959
bazel mod deps --lockfile_mode=update
60+
- name: Run Libclang Parser Tooling clippy
61+
run: |
62+
bazel build //cpp/libclang/... --config=clippy
63+
- name: Run Libclang Parser Tooling tests
64+
run: |
65+
bazel test //cpp/libclang/...

cpp/libclang/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct Args {
4949

5050
fn parse_file(
5151
file: &PathBuf,
52-
compilation_flags: &Vec<String>,
52+
compilation_flags: &[String],
5353
index: &clang::Index,
5454
ast_file_output_path: &PathBuf,
5555
all_classes: &mut BTreeMap<String, context::TypeMapValue>,
@@ -64,7 +64,7 @@ fn parse_file(
6464
}
6565
};
6666

67-
let parse_result = index.parser(&file).arguments(&compilation_flags).parse();
67+
let parse_result = index.parser(file).arguments(compilation_flags).parse();
6868

6969
match parse_result {
7070
Ok(parsed) => {
@@ -76,7 +76,7 @@ fn parse_file(
7676
}
7777

7878
let entity = parsed.get_entity();
79-
print_entity(&entity, 0, PrintMode::File(&ast_file_output_path));
79+
print_entity(&entity, 0, PrintMode::File(ast_file_output_path));
8080
print_entity(&entity, 0, PrintMode::Stdout);
8181

8282
let mut ctx = VisitContext::default();
@@ -139,8 +139,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
139139
let compilation_flags = &command_line_args.extra_args;
140140

141141
parse_file(
142-
&file,
143-
&compilation_flags,
142+
file,
143+
compilation_flags,
144144
&index,
145145
&ast_file_output_path,
146146
&mut all_classes,

cpp/libclang/src/visitor/src/class_parser_helper.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
// SPDX-License-Identifier: Apache-2.0
1212
////////////////////////////////////////////////////////////////////////////////////
13+
#![cfg_attr(test, allow(dead_code))]
14+
1315
use clang::{Entity, EntityKind, Type, TypeKind};
1416
use serde::{Deserialize, Serialize};
1517

@@ -450,7 +452,7 @@ fn resolve_unqualified_type(original: &Type, canonical: &Type) -> ResolvedType {
450452

451453
ResolvedType::Array {
452454
element: Box::new(element),
453-
size: original.get_size().map(|s| s as usize),
455+
size: original.get_size(),
454456
}
455457
}
456458

@@ -624,7 +626,7 @@ fn build_fqn_from_entity(entity: &Entity) -> String {
624626
// Traversal is semantic (not lexical) so aliases/nested constructs resolve to
625627
// stable ownership hierarchy used by relationship and id matching.
626628
let mut parts: Vec<(String, bool)> = Vec::new();
627-
let mut current = Some(entity.clone());
629+
let mut current = Some(*entity);
628630

629631
while let Some(entity) = current {
630632
match entity.get_kind() {

cpp/libclang/src/visitor/src/class_visitor.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl ClassVisitor {
7474
};
7575

7676
let mut class_entity = SimpleEntity {
77-
id: id,
77+
id,
7878
name: name.clone(),
7979
enclosing_namespace_id: namespace.map(|ns| ns.to_string()),
8080
..Default::default()
@@ -153,12 +153,8 @@ fn parse_source_location(entity: &Entity) -> (Option<String>, Option<u32>) {
153153
}
154154

155155
fn collect_variable_type(entity: &Entity) -> Option<ParsedVariableType> {
156-
let Some(name) = entity.get_name() else {
157-
return None;
158-
};
159-
let Some(field_type) = entity.get_type() else {
160-
return None;
161-
};
156+
let name = entity.get_name()?;
157+
let field_type = entity.get_type()?;
162158

163159
Some(ParsedVariableType {
164160
name,

cpp/libclang/src/visitor/src/enum_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl EnumVisitor {
3636
};
3737
Some(SimpleEntity {
3838
id: full_qualified_id,
39-
name: name,
39+
name,
4040
enclosing_namespace_id: namespace_id,
4141
entity_type: EntityType::Enum,
4242
enum_literals: get_literals(entity),

0 commit comments

Comments
 (0)