Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix last clippy lints and enforce in CI #3106

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 13 additions & 46 deletions .github/workflows/bindgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@ on:
- main

jobs:
rustfmt-clippy:
rustfmt:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install stable
- name: Install nightly
uses: dtolnay/rust-toolchain@master
with:
# TODO: Should ideally be stable, but we use some nightly-only
# features.
toolchain: nightly
components: rustfmt, clippy
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
run: cargo clippy --all-targets --workspace --exclude bindgen-integration --exclude tests_expectations -- -D warnings

msrv:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -64,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:
Expand All @@ -79,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`
Expand All @@ -95,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
Expand All @@ -112,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

Expand Down Expand Up @@ -174,21 +156,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:
Expand Down Expand Up @@ -221,7 +188,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.
Expand Down
2 changes: 1 addition & 1 deletion bindgen-tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
if is_allowlisted { "black" } else { "gray" }
)?;
item.dot_attributes(ctx, &mut dot_file)?;
writeln!(&mut dot_file, r#"</table> >];"#)?;
writeln!(&mut dot_file, "</table> >];")?;

item.trace(
ctx,
Expand Down
2 changes: 1 addition & 1 deletion bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand Down