diff --git a/bindgen-tests/build.rs b/bindgen-tests/build.rs index 8fb33716a1..cf929b4b65 100644 --- a/bindgen-tests/build.rs +++ b/bindgen-tests/build.rs @@ -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(); } diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 3cc7cbe415..bcf9b7fcfa 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -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); diff --git a/bindgen/ir/analysis/has_destructor.rs b/bindgen/ir/analysis/has_destructor.rs index 4893f8f807..44ef33c21b 100644 --- a/bindgen/ir/analysis/has_destructor.rs +++ b/bindgen/ir/analysis/has_destructor.rs @@ -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() { diff --git a/bindgen/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs index 3ff64a6d2b..b8ecc6088e 100644 --- a/bindgen/ir/analysis/has_vtable.rs +++ b/bindgen/ir/analysis/has_vtable.rs @@ -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. diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index c0201a114b..6adbcd5989 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -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" @@ -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" @@ -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 @@ -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?"); } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 65a12d4bb2..6f8c00fa89 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -724,9 +724,8 @@ impl ClangSubItemParser for Function { ) -> Result, 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()); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index b2fecc2c3b..e4294c505a 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -301,12 +301,11 @@ fn get_extra_clang_args( parse_callbacks: &[Rc], ) -> Vec { // 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. @@ -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:?}"); @@ -980,7 +978,7 @@ impl Bindings { } /// Gets the rustfmt path to rustfmt the generated bindings. - fn rustfmt_path(&self) -> io::Result> { + fn rustfmt_path(&self) -> io::Result> { debug_assert!(matches!(self.options.formatter, Formatter::Rustfmt)); if let Some(ref p) = self.options.rustfmt_path { return Ok(Cow::Borrowed(p)); diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index c9ef7c8b49..b876b4d5b3 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -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`. @@ -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; @@ -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 diff --git a/clippy.toml b/clippy.toml index 26a0605343..ec210a9878 100644 --- a/clippy.toml +++ b/clippy.toml @@ -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