Skip to content

Commit cc9bc70

Browse files
committed
chore: Do a clippy pass.
1 parent 6e13d4f commit cc9bc70

File tree

9 files changed

+24
-31
lines changed

9 files changed

+24
-31
lines changed

bindgen-tests/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub fn main() {
3333
.replace(|c| !char::is_alphanumeric(c), "_")
3434
.replace("__", "_")
3535
.to_lowercase();
36+
// We actually want the quotes and escape
37+
#[allow(clippy::unnecessary_debug_formatting)]
3638
writeln!(dst, "test_header!(header_{func}, {:?});", entry.path())
3739
.unwrap();
3840
}

bindgen-tests/tests/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ fn error_diff_mismatch(
4141
filename: &Path,
4242
) -> Result<(), Error> {
4343
println!("diff expected generated");
44-
println!("--- expected: {filename:?}");
44+
println!("--- expected: {}", filename.display());
4545
if let Some(header) = header {
46-
println!("+++ generated from: {header:?}");
46+
println!("+++ generated from: {}", header.display());
4747
}
4848

4949
show_diff(expected, actual);

bindgen/ir/analysis/has_destructor.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> {
9393
}
9494

9595
let item = self.ctx.resolve_item(id);
96-
let ty = match item.as_type() {
97-
None => return ConstrainResult::Same,
98-
Some(ty) => ty,
96+
let Some(ty) = item.as_type() else {
97+
return ConstrainResult::Same;
9998
};
10099

101100
match *ty.kind() {

bindgen/ir/analysis/has_vtable.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> {
149149
trace!("constrain {id:?}");
150150

151151
let item = self.ctx.resolve_item(id);
152-
let ty = match item.as_type() {
153-
None => return ConstrainResult::Same,
154-
Some(ty) => ty,
152+
let Some(ty) = item.as_type() else {
153+
return ConstrainResult::Same;
155154
};
156155

157156
// TODO #851: figure out a way to handle deriving from template type parameters.

bindgen/ir/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
724724
self.need_bitfield_allocation.push(id);
725725
}
726726

727-
let old_item = mem::replace(&mut self.items[id.0], Some(item));
727+
let old_item = self.items[id.0].replace(item);
728728
assert!(
729729
old_item.is_none(),
730730
"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!"
827827
self.add_item_to_module(&item);
828828

829829
let id = item.id();
830-
let old_item = mem::replace(&mut self.items[id.0], Some(item));
830+
let old_item = self.items[id.0].replace(item);
831831
assert!(
832832
old_item.is_none(),
833833
"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!"
987987

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

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

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

bindgen/ir/function.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,9 +724,8 @@ impl ClangSubItemParser for Function {
724724
) -> Result<ParseResult<Self>, ParseError> {
725725
use clang_sys::*;
726726

727-
let kind = match FunctionKind::from_cursor(&cursor) {
728-
None => return Err(ParseError::Continue),
729-
Some(k) => k,
727+
let Some(kind) = FunctionKind::from_cursor(&cursor) else {
728+
return Err(ParseError::Continue);
730729
};
731730

732731
debug!("Function::parse({cursor:?}, {:?})", cursor.cur_type());

bindgen/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,11 @@ fn get_extra_clang_args(
301301
parse_callbacks: &[Rc<dyn callbacks::ParseCallbacks>],
302302
) -> Vec<String> {
303303
// Add any extra arguments from the environment to the clang command line.
304-
let extra_clang_args = match get_target_dependent_env_var(
304+
let Some(extra_clang_args) = get_target_dependent_env_var(
305305
parse_callbacks,
306306
"BINDGEN_EXTRA_CLANG_ARGS",
307-
) {
308-
None => return vec![],
309-
Some(s) => s,
307+
) else {
308+
return vec![];
310309
};
311310

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

844-
let clang = match clang_sys::support::Clang::find(
843+
let Some(clang) = clang_sys::support::Clang::find(
845844
None,
846845
&clang_args_for_clang_sys,
847-
) {
848-
None => return,
849-
Some(clang) => clang,
846+
) else {
847+
return;
850848
};
851849

852850
debug!("Found clang: {clang:?}");
@@ -980,7 +978,7 @@ impl Bindings {
980978
}
981979

982980
/// Gets the rustfmt path to rustfmt the generated bindings.
983-
fn rustfmt_path(&self) -> io::Result<Cow<'_, PathBuf>> {
981+
fn rustfmt_path(&self) -> io::Result<Cow<'_, Path>> {
984982
debug_assert!(matches!(self.options.formatter, Formatter::Rustfmt));
985983
if let Some(ref p) = self.options.rustfmt_path {
986984
return Ok(Cow::Borrowed(p));

bindgen/options/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ options! {
168168
as_args: "--use-specific-virtual-function-receiver",
169169
},
170170

171-
/// Whether we should distinguish between C++'s 'char16_t' and 'u16'.
171+
/// Whether we should distinguish between C++'s `char16_t` and `u16`.
172172
/// The C++ type `char16_t` is its own special type; it's not a typedef
173173
/// of some other integer (this differs from C).
174174
/// As standard, bindgen represents C++ `char16_t` as `u16`.
@@ -183,7 +183,7 @@ options! {
183183
/// real type.
184184
use_distinct_char16_t: bool {
185185
methods: {
186-
/// If this is true, denote 'char16_t' as a separate type from 'u16'
186+
/// If this is true, denote `char16_t` as a separate type from `u16`.
187187
/// Disabled by default.
188188
pub fn use_distinct_char16_t(mut self, doit: bool) -> Builder {
189189
self.options.use_distinct_char16_t = doit;
@@ -2101,7 +2101,7 @@ options! {
21012101
/// Whether to generate wrappers for `static` functions.
21022102
wrap_static_fns: bool {
21032103
methods: {
2104-
/// Set whether to generate wrappers for `static`` functions.
2104+
/// Set whether to generate wrappers for `static` functions.
21052105
///
21062106
/// Passing `true` to this method will generate a C source file with non-`static`
21072107
/// functions that call the `static` functions found in the input headers and can be

clippy.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
disallowed-methods = [
2-
{ path = "clang_sys::CXCursor_TranslationUnit", reason = "This value was changed in clang 15"},
3-
{ path = "clang_sys::CXCursor_LastStmt", reason = "This value was changed in clang 15"}
4-
]
51
missing-docs-in-crate-items = true

0 commit comments

Comments
 (0)