From 1131a7241b06b6a26a4b1d5bf372735bef379b83 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 1 Feb 2025 17:54:39 -0500 Subject: [PATCH 1/5] chore: fix new clippy lints, enforce in CI --- .github/workflows/bindgen.yml | 10 +--------- bindgen-tests/build.rs | 2 +- bindgen/ir/dot.rs | 2 +- bindgen/lib.rs | 2 +- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index df17f2c579..4e8f94c5b7 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -18,19 +18,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install stable - uses: dtolnay/rust-toolchain@master - with: - # TODO: Should ideally be stable, but we use some nightly-only - # features. - toolchain: nightly - components: rustfmt, clippy - - name: Run rustfmt run: cargo fmt -- --check - name: Run clippy - run: cargo clippy --all-targets --workspace --exclude bindgen-integration --exclude tests_expectations + run: cargo clippy --all-targets --workspace --exclude bindgen-integration --exclude tests_expectations -- -D warnings msrv: runs-on: ubuntu-latest diff --git a/bindgen-tests/build.rs b/bindgen-tests/build.rs index b261ed0a35..8fb33716a1 100644 --- a/bindgen-tests/build.rs +++ b/bindgen-tests/build.rs @@ -23,7 +23,7 @@ pub fn main() { for entry in entries { // TODO: file_is_cpp() in bindgen/lib.rs checks for hpp,hxx,hh, and h++ - should this be consistent? - if entry.path().extension().map_or(false, |ext| { + if entry.path().extension().is_some_and(|ext| { ext.eq_ignore_ascii_case("h") || ext.eq_ignore_ascii_case("hpp") }) { let func = entry diff --git a/bindgen/ir/dot.rs b/bindgen/ir/dot.rs index 0ccee42c0d..9bfc559f41 100644 --- a/bindgen/ir/dot.rs +++ b/bindgen/ir/dot.rs @@ -41,7 +41,7 @@ where if is_allowlisted { "black" } else { "gray" } )?; item.dot_attributes(ctx, &mut dot_file)?; - writeln!(&mut dot_file, r#" >];"#)?; + writeln!(&mut dot_file, " >];")?; item.trace( ctx, diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 1a15d51d67..25877e8f6d 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -86,7 +86,7 @@ pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern"; fn file_is_cpp(name_file: &str) -> bool { - Path::new(name_file).extension().map_or(false, |ext| { + Path::new(name_file).extension().is_some_and(|ext| { ext.eq_ignore_ascii_case("hpp") || ext.eq_ignore_ascii_case("hxx") || ext.eq_ignore_ascii_case("hh") || From 71f6ad8f645f3bd58afc46cedcd883cabae1b538 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 1 Feb 2025 18:28:01 -0500 Subject: [PATCH 2/5] remove check-cfg, separate clippy from nightly --- .github/workflows/bindgen.yml | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 4e8f94c5b7..94022c21e1 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -12,14 +12,24 @@ on: - main jobs: - rustfmt-clippy: + rustfmt: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 + - name: Install nightly + uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + components: rustfmt + - name: Run rustfmt - run: cargo fmt -- --check + run: cargo +nightly fmt -- --check + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 - name: Run clippy run: cargo clippy --all-targets --workspace --exclude bindgen-integration --exclude tests_expectations -- -D warnings @@ -166,21 +176,6 @@ jobs: BINDGEN_RUST_FOR_LINUX_TEST: ${{matrix.os == 'ubuntu-latest' && matrix.llvm_version == '16.0' && matrix.feature_extra_asserts == 0 && 1 || 0}} run: ./ci/test.sh - check-cfg: - runs-on: ubuntu-latest - env: - RUSTFLAGS: -D warnings - steps: - - uses: actions/checkout@v4 - - - name: Install nightly - uses: dtolnay/rust-toolchain@master - with: - toolchain: nightly - - - name: Check cfg - run: cargo check -Z unstable-options -Z check-cfg - test-book: runs-on: ubuntu-latest steps: @@ -213,7 +208,7 @@ jobs: # separately. success: runs-on: ubuntu-latest - needs: [rustfmt-clippy, msrv, minimal, docs, quickchecking, test-expectations, test, check-cfg, test-book, test-no-headers] + needs: [rustfmt, clippy, msrv, minimal, docs, quickchecking, test-expectations, test, test-book, test-no-headers] # GitHub branch protection is exceedingly silly and treats "jobs skipped # because a dependency failed" as success. So we have to do some # contortions to ensure the job fails if any of its dependencies fails. From 539a943815c5994c59041c08757476df56bb2d04 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 1 Feb 2025 18:31:05 -0500 Subject: [PATCH 3/5] remove stable rust installation --- .github/workflows/bindgen.yml | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 94022c21e1..1778de1d2b 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -66,12 +66,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install stable - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - - - name: Check without default features + - name: Check without default features run: cargo check -p bindgen --no-default-features --features=runtime docs: @@ -81,12 +76,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install stable - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - - - name: Generate documentation for `bindgen` + - name: Generate documentation for `bindgen` run: cargo doc --document-private-items --no-deps -p bindgen - name: Generate documentation for `bindgen-cli` @@ -97,11 +87,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install stable - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - # TODO: Actually run quickchecks once `bindgen` is reliable enough. - name: Build quickcheck tests run: cd bindgen-tests/tests/quickchecking && cargo test @@ -114,11 +99,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install stable - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - - name: Test expectations run: cd bindgen-tests/tests/expectations && cargo test From c52e575eb959a89c9bda1d88c97d77bb674a7deb Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 2 Feb 2025 20:32:47 -0500 Subject: [PATCH 4/5] another minor clippy lint --- bindgen/codegen/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index a899ac4de9..652dd15f83 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4649,7 +4649,7 @@ impl CodeGenerator for Function { mangled_name, Some(abi), )) - .then(|| mangled_name) + .then_some(mangled_name) }); if let Some(link_name) = link_name_attr { From 785d0addc5563828a746116cc0a96618f6541f36 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 11 Feb 2025 13:19:49 -0500 Subject: [PATCH 5/5] fix clippy issues --- bindgen/ir/context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 78790d61c4..85dab01e61 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2105,13 +2105,13 @@ If you encounter an error missing from this list, please file an issue or a PR!" pch.clone().into_boxed_str(), ]; let mut skip_next = false; - for arg in self.options.fallback_clang_args.iter() { + for arg in &self.options.fallback_clang_args { if arg.as_ref() == "-include" { skip_next = true; } else if skip_next { skip_next = false; } else { - c_args.push(arg.clone()) + c_args.push(arg.clone()); } } self.fallback_tu =