Skip to content

Commit 9fda615

Browse files
Copilotnunoplopes
andcommitted
Auto-fix: apply rustfmt/clippy fixes; add auto-commit and tests-rs coverage to workflow
Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/010475b0-f8f3-444a-95d3-f622fb2e4daa Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
1 parent 3f305a4 commit 9fda615

25 files changed

Lines changed: 54 additions & 31 deletions

File tree

.github/workflows/format.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ jobs:
66
format:
77
runs-on: ubuntu-latest
88
permissions:
9-
contents: read
9+
contents: write
1010

1111
steps:
1212
- name: Checkout code
1313
uses: actions/checkout@v6
14+
with:
15+
ref: ${{ github.head_ref || github.ref_name }}
1416

1517
- name: Setup LLVM 22
1618
uses: ZhongRuoyu/setup-llvm@v0
@@ -29,6 +31,27 @@ jobs:
2931
toolchain: nightly
3032
components: clippy, rustc-dev
3133

34+
- name: Apply C++ formatting fixes
35+
run: find cpp2rust tests -name '*.cpp' -o -name '*.h' -o -name '*.c' | xargs clang-format -i
36+
37+
- name: Apply Rust lint fixes
38+
run: |
39+
cargo clippy --fix --allow-dirty --manifest-path rules/Cargo.toml --all-targets
40+
cargo +nightly clippy --fix --allow-dirty --manifest-path rule-preprocessor/Cargo.toml --all-targets
41+
cargo clippy --fix --allow-dirty --manifest-path libcc2rs/Cargo.toml --all-targets
42+
43+
- name: Apply Rust formatting fixes
44+
run: |
45+
cargo fmt --manifest-path rules/Cargo.toml
46+
cargo fmt --manifest-path rule-preprocessor/Cargo.toml
47+
cargo fmt --manifest-path libcc2rs/Cargo.toml
48+
find tests -name '*.rs' -print0 | xargs -0 rustfmt
49+
50+
- name: Commit auto-fixes
51+
uses: stefanzweifel/git-auto-commit-action@v5
52+
with:
53+
commit_message: "style: apply automatic formatting and lint fixes"
54+
3255
- name: Check C++ formatting
3356
run: find cpp2rust tests -name '*.cpp' -o -name '*.h' -o -name '*.c' | xargs clang-format --dry-run --Werror
3457

@@ -37,6 +60,7 @@ jobs:
3760
cargo fmt --manifest-path rules/Cargo.toml -- --check
3861
cargo fmt --manifest-path rule-preprocessor/Cargo.toml -- --check
3962
cargo fmt --manifest-path libcc2rs/Cargo.toml -- --check
63+
find tests -name '*.rs' -print0 | xargs -0 rustfmt --check
4064
4165
- name: Check Rust lints
4266
run: |

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();

tests/unit/out/refcount/bit_cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ extern crate libc;
33
use libc::*;
44
extern crate libcc2rs;
55
use libcc2rs::{prepostfix::*, rc::*};
6-
use std::rc::{Rc, Weak};
76
use std::cell::RefCell;
7+
use std::rc::{Rc, Weak};
88
pub fn decay_cast(a1: Value<Pointer<u32>>) {}
99
pub fn bit_cast(p: Value<Pointer<dyn std::any::Any>>) {}
1010
pub fn main() {

tests/unit/out/refcount/ub1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate libcc2rs;
22
use libcc2rs::{prepostfix::*, rc::*};
3-
use std::rc::{Rc, Weak};
43
use std::cell::RefCell;
4+
use std::rc::{Rc, Weak};
55
pub fn dangling() -> Reference<i32> {
66
let x: Value<i32> = Rc::new(RefCell::new(1_i32));
77
let p: Value<Pointer<i32>> = Rc::new(RefCell::new(x.as_pointer()));

tests/unit/out/refcount/ub10.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate libcc2rs;
22
use libcc2rs::{prepostfix::*, rc::*};
3-
use std::rc::{Rc, Weak};
43
use std::cell::RefCell;
4+
use std::rc::{Rc, Weak};
55
pub fn main() {
66
std::process::exit(*main_0().borrow() as i32);
77
}

tests/unit/out/refcount/ub11.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate libcc2rs;
22
use libcc2rs::{prepostfix::*, rc::*};
3-
use std::rc::{Rc, Weak};
43
use std::cell::RefCell;
4+
use std::rc::{Rc, Weak};
55
pub fn main() {
66
std::process::exit(*main_0().borrow() as i32);
77
}

tests/unit/out/refcount/ub12.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate libcc2rs;
22
use libcc2rs::{prepostfix::*, rc::*};
3-
use std::rc::{Rc, Weak};
43
use std::cell::RefCell;
4+
use std::rc::{Rc, Weak};
55
pub fn escape(ptr: Value<Pointer<i32>>) {
66
(*ptr.borrow()).delete();
77
}

tests/unit/out/refcount/ub13.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate libcc2rs;
22
use libcc2rs::{prepostfix::*, rc::*};
3-
use std::rc::{Rc, Weak};
43
use std::cell::RefCell;
4+
use std::rc::{Rc, Weak};
55
pub fn escape(p: Value<Pointer<i32>>) {
66
(*p.borrow()).delete();
77
}

tests/unit/out/refcount/ub14.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate libcc2rs;
22
use libcc2rs::{prepostfix::*, rc::*};
3-
use std::rc::{Rc, Weak};
43
use std::cell::RefCell;
4+
use std::rc::{Rc, Weak};
55
pub fn main() {
66
std::process::exit(*main_0().borrow() as i32);
77
}

tests/unit/out/refcount/ub15.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate libcc2rs;
22
use libcc2rs::{prepostfix::*, rc::*};
3-
use std::rc::{Rc, Weak};
43
use std::cell::RefCell;
4+
use std::rc::{Rc, Weak};
55
pub fn main() {
66
std::process::exit(*main_0().borrow() as i32);
77
}

0 commit comments

Comments
 (0)