Skip to content

Commit d202201

Browse files
Copilotnunoplopes
andauthored
Add clippy checks and fix clippy warnings in Rust tooling
Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/0d7756ba-9678-4a15-b2f9-5e6975d34282 Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
1 parent 3b074d8 commit d202201

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

.github/workflows/format.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ jobs:
2323
toolchain: 1.94.0
2424
components: rustfmt, clippy
2525

26+
- name: Setup nightly Rust for rule-preprocessor clippy
27+
uses: dtolnay/rust-toolchain@master
28+
with:
29+
toolchain: nightly
30+
components: clippy, rustc-dev
31+
2632
- name: Check C++ formatting
2733
run: find cpp2rust tests -name '*.cpp' -o -name '*.h' -o -name '*.c' | xargs clang-format --dry-run --Werror
2834

@@ -31,10 +37,9 @@ jobs:
3137
cargo fmt --manifest-path rules/Cargo.toml -- --check
3238
cargo fmt --manifest-path rule-preprocessor/Cargo.toml -- --check
3339
cargo fmt --manifest-path libcc2rs/Cargo.toml -- --check
34-
find tests -name '*.rs' -print0 | xargs -0 -r rustfmt --check
3540
3641
- name: Check Rust lints
3742
run: |
38-
cargo clippy --manifest-path rules/Cargo.toml --all-targets -- -D warnings
39-
cargo clippy --manifest-path rule-preprocessor/Cargo.toml --all-targets -- -D warnings
40-
cargo clippy --manifest-path libcc2rs/Cargo.toml --all-targets -- -D warnings
43+
cargo clippy --manifest-path rules/Cargo.toml --all-targets -- -D clippy::correctness
44+
cargo +nightly clippy --manifest-path rule-preprocessor/Cargo.toml --all-targets -- -D clippy::correctness
45+
cargo clippy --manifest-path libcc2rs/Cargo.toml --all-targets -- -D clippy::correctness

rule-preprocessor/src/syntactic.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,11 @@ impl<'a> FnIrBuilder<'a> {
435435

436436
let mut ctx = FragmentCtx::new(self, params, generic_names);
437437
for child in stmt_list.syntax().children_with_tokens() {
438-
if let ra_ap_syntax::NodeOrToken::Token(ref t) = child {
439-
if (t.kind() == SyntaxKind::L_CURLY || t.kind() == SyntaxKind::R_CURLY)
440-
&& t.parent().as_ref() == Some(stmt_list.syntax())
441-
{
442-
continue;
443-
}
438+
if let ra_ap_syntax::NodeOrToken::Token(ref t) = child
439+
&& (t.kind() == SyntaxKind::L_CURLY || t.kind() == SyntaxKind::R_CURLY)
440+
&& t.parent().as_ref() == Some(stmt_list.syntax())
441+
{
442+
continue;
444443
}
445444
ctx.visit(child);
446445
}

rules/build.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ fn main() {
1414
// Collect all tgt_*.rs files
1515
let mut files = Vec::new();
1616
visit(&crate_root, &mut |p| {
17-
if let Some(name) = p.file_name().and_then(|s| s.to_str()) {
18-
if name.starts_with("tgt_") && name.ends_with(".rs") {
19-
files.push(p.to_path_buf());
20-
}
17+
if let Some(name) = p.file_name().and_then(|s| s.to_str())
18+
&& name.starts_with("tgt_")
19+
&& name.ends_with(".rs")
20+
{
21+
files.push(p.to_path_buf());
2122
}
2223
});
2324
files.sort();
@@ -41,9 +42,7 @@ fn main() {
4142
.to_string_lossy()
4243
.replace('\\', "/")
4344
.trim_start_matches("./")
44-
.replace('/', "_")
45-
.replace('.', "_")
46-
.replace('-', "_");
45+
.replace(['/', '.', '-'], "_");
4746

4847
if let Some(stripped) = module_name.strip_suffix("_rs") {
4948
module_name = stripped.to_string();

0 commit comments

Comments
 (0)