Skip to content

chore: Do a clippy pass. #3231

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

Merged
merged 1 commit into from
Jun 18, 2025
Merged
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
2 changes: 2 additions & 0 deletions bindgen-tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub fn main() {
.replace(|c| !char::is_alphanumeric(c), "_")
.replace("__", "_")
.to_lowercase();
// We actually want the quotes and escape
#[allow(clippy::unnecessary_debug_formatting)]
writeln!(dst, "test_header!(header_{func}, {:?});", entry.path())
.unwrap();
}
Expand Down
4 changes: 2 additions & 2 deletions bindgen-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ fn error_diff_mismatch(
filename: &Path,
) -> Result<(), Error> {
println!("diff expected generated");
println!("--- expected: {filename:?}");
println!("--- expected: {}", filename.display());
if let Some(header) = header {
println!("+++ generated from: {header:?}");
println!("+++ generated from: {}", header.display());
}

show_diff(expected, actual);
Expand Down
5 changes: 2 additions & 3 deletions bindgen/ir/analysis/has_destructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> {
}

let item = self.ctx.resolve_item(id);
let ty = match item.as_type() {
None => return ConstrainResult::Same,
Some(ty) => ty,
let Some(ty) = item.as_type() else {
return ConstrainResult::Same;
};

match *ty.kind() {
Expand Down
5 changes: 2 additions & 3 deletions bindgen/ir/analysis/has_vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> {
trace!("constrain {id:?}");

let item = self.ctx.resolve_item(id);
let ty = match item.as_type() {
None => return ConstrainResult::Same,
Some(ty) => ty,
let Some(ty) = item.as_type() else {
return ConstrainResult::Same;
};

// TODO #851: figure out a way to handle deriving from template type parameters.
Expand Down
8 changes: 4 additions & 4 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
self.need_bitfield_allocation.push(id);
}

let old_item = mem::replace(&mut self.items[id.0], Some(item));
let old_item = self.items[id.0].replace(item);
assert!(
old_item.is_none(),
"should not have already associated an item with the given id"
Expand Down Expand Up @@ -827,7 +827,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
self.add_item_to_module(&item);

let id = item.id();
let old_item = mem::replace(&mut self.items[id.0], Some(item));
let old_item = self.items[id.0].replace(item);
assert!(
old_item.is_none(),
"should not have already associated an item with the given id"
Expand Down Expand Up @@ -987,7 +987,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"

let result = f(self, &mut item);

let existing = mem::replace(&mut self.items[id.0], Some(item));
let existing = self.items[id.0].replace(item);
assert!(existing.is_none());

result
Expand Down Expand Up @@ -1434,7 +1434,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
debug_assert!(item.kind().is_type());
self.add_item_to_module(&item);
let id = item.id();
let old_item = mem::replace(&mut self.items[id.0], Some(item));
let old_item = self.items[id.0].replace(item);
assert!(old_item.is_none(), "Inserted type twice?");
}

Expand Down
5 changes: 2 additions & 3 deletions bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,8 @@ impl ClangSubItemParser for Function {
) -> Result<ParseResult<Self>, ParseError> {
use clang_sys::*;

let kind = match FunctionKind::from_cursor(&cursor) {
None => return Err(ParseError::Continue),
Some(k) => k,
let Some(kind) = FunctionKind::from_cursor(&cursor) else {
return Err(ParseError::Continue);
};

debug!("Function::parse({cursor:?}, {:?})", cursor.cur_type());
Expand Down
16 changes: 7 additions & 9 deletions bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,11 @@ fn get_extra_clang_args(
parse_callbacks: &[Rc<dyn callbacks::ParseCallbacks>],
) -> Vec<String> {
// Add any extra arguments from the environment to the clang command line.
let extra_clang_args = match get_target_dependent_env_var(
let Some(extra_clang_args) = get_target_dependent_env_var(
parse_callbacks,
"BINDGEN_EXTRA_CLANG_ARGS",
) {
None => return vec![],
Some(s) => s,
) else {
return vec![];
};

// Try to parse it with shell quoting. If we fail, make it one single big argument.
Expand Down Expand Up @@ -841,12 +840,11 @@ impl Bindings {
"Trying to find clang with flags: {clang_args_for_clang_sys:?}"
);

let clang = match clang_sys::support::Clang::find(
let Some(clang) = clang_sys::support::Clang::find(
None,
&clang_args_for_clang_sys,
) {
None => return,
Some(clang) => clang,
) else {
return;
};

debug!("Found clang: {clang:?}");
Expand Down Expand Up @@ -980,7 +978,7 @@ impl Bindings {
}

/// Gets the rustfmt path to rustfmt the generated bindings.
fn rustfmt_path(&self) -> io::Result<Cow<'_, PathBuf>> {
fn rustfmt_path(&self) -> io::Result<Cow<'_, Path>> {
debug_assert!(matches!(self.options.formatter, Formatter::Rustfmt));
if let Some(ref p) = self.options.rustfmt_path {
return Ok(Cow::Borrowed(p));
Expand Down
6 changes: 3 additions & 3 deletions bindgen/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ options! {
as_args: "--use-specific-virtual-function-receiver",
},

/// Whether we should distinguish between C++'s 'char16_t' and 'u16'.
/// Whether we should distinguish between C++'s `char16_t` and `u16`.
/// The C++ type `char16_t` is its own special type; it's not a typedef
/// of some other integer (this differs from C).
/// As standard, bindgen represents C++ `char16_t` as `u16`.
Expand All @@ -183,7 +183,7 @@ options! {
/// real type.
use_distinct_char16_t: bool {
methods: {
/// If this is true, denote 'char16_t' as a separate type from 'u16'
/// If this is true, denote `char16_t` as a separate type from `u16`.
/// Disabled by default.
pub fn use_distinct_char16_t(mut self, doit: bool) -> Builder {
self.options.use_distinct_char16_t = doit;
Expand Down Expand Up @@ -2101,7 +2101,7 @@ options! {
/// Whether to generate wrappers for `static` functions.
wrap_static_fns: bool {
methods: {
/// Set whether to generate wrappers for `static`` functions.
/// Set whether to generate wrappers for `static` functions.
///
/// Passing `true` to this method will generate a C source file with non-`static`
/// functions that call the `static` functions found in the input headers and can be
Expand Down
4 changes: 0 additions & 4 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
disallowed-methods = [
{ path = "clang_sys::CXCursor_TranslationUnit", reason = "This value was changed in clang 15"},
{ path = "clang_sys::CXCursor_LastStmt", reason = "This value was changed in clang 15"}
]
missing-docs-in-crate-items = true