Skip to content

Commit ea1d036

Browse files
committed
Consolidate clippy configuration
Move all clippy configurations to one central place, except for the expected tests - they seem to require their own handling for now due to a Cargo limitation. Also, fixed a lot of `unused_qualifications` lints.
1 parent c4440b3 commit ea1d036

File tree

24 files changed

+95
-75
lines changed

24 files changed

+95
-75
lines changed

Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ shlex = "1"
2020
syn = "2.0"
2121
proc-macro2 = { version = "1", default-features = false }
2222

23+
[workspace.lints.rust]
24+
deprecated = "allow"
25+
invalid-value = "allow"
26+
non-snake-case = "allow"
27+
unexpected-cfgs = "allow"
28+
unsupported_calling_conventions = "allow"
29+
unused_qualifications = "warn"
30+
31+
[workspace.lints.clippy]
32+
disallowed-names = "allow"
33+
manual-c-str-literals = "allow"
34+
missing-safety-doc = "allow"
35+
op-ref = "allow"
36+
ptr-offset-with-cast = "allow"
37+
too-many-arguments = "allow"
38+
transmute-int-to-bool = "allow"
39+
unnecessary-cast = "allow"
40+
useless-transmute = "allow"
41+
2342
# Config for 'cargo dist'
2443
[workspace.metadata.dist]
2544
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)

bindgen-cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
lints.workspace = true
2+
13
[package]
24
authors = [
35
"The rust-bindgen project contributors",

bindgen-integration/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
lints.workspace = true
2+
13
[package]
24
name = "bindgen-integration"
35
description = "A package to test various bindgen features"

bindgen-integration/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn setup_macro_test() {
183183
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
184184
let out_rust_file = out_path.join("test.rs");
185185
let out_rust_file_relative = out_rust_file
186-
.strip_prefix(std::env::current_dir().unwrap().parent().unwrap())
186+
.strip_prefix(env::current_dir().unwrap().parent().unwrap())
187187
.unwrap();
188188
let out_dep_file = out_path.join("test.d");
189189

bindgen-tests/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
lints.workspace = true
2+
13
[package]
24
name = "bindgen-tests"
35
edition = "2021"

bindgen-tests/tests/expectations/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ block = "0.1"
1515
libloading = "0.7"
1616
objc = "0.2"
1717

18+
# Both of these sections need to be copied here from the workspace because
19+
# Cargo currently does not allow overriding workspace settings in a member
1820
[lints.rust]
1921
### FIXME: these might need to be fixed,
2022
### esp the calling convention, because it is a hard error now
@@ -23,6 +25,7 @@ objc = "0.2"
2325
# unsupported_calling_conventions = "allow"
2426
non-snake-case = "allow"
2527
unexpected-cfgs = "allow"
28+
unused_qualifications = "allow" # Different from the workspace
2629

2730
[lints.clippy]
2831
disallowed-names = "allow"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#![allow(dead_code)]
22
#![allow(non_camel_case_types)]
33
#![allow(non_upper_case_globals)]
4+
#![allow(unused_qualifications)]

bindgen-tests/tests/quickchecking/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
lints.workspace = true
2+
13
[package]
24
name = "quickchecking"
35
description = "Bindgen property tests with quickcheck. Generate random valid C code and pass it to the csmith/predicate.py script"

bindgen-tests/tests/tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ include!(concat!(env!("OUT_DIR"), "/tests.rs"));
371371
#[test]
372372
#[cfg_attr(target_os = "windows", ignore)]
373373
fn test_clang_env_args() {
374-
std::env::set_var(
374+
env::set_var(
375375
"BINDGEN_EXTRA_CLANG_ARGS",
376376
"-D_ENV_ONE=1 -D_ENV_TWO=\"2 -DNOT_THREE=1\"",
377377
);
@@ -653,8 +653,8 @@ fn emit_depfile() {
653653
builder.into_builder(check_roundtrip).unwrap();
654654
let _bindings = builder.generate().unwrap();
655655

656-
let observed = std::fs::read_to_string(observed_depfile).unwrap();
657-
let expected = std::fs::read_to_string(expected_depfile).unwrap();
656+
let observed = fs::read_to_string(observed_depfile).unwrap();
657+
let expected = fs::read_to_string(expected_depfile).unwrap();
658658
assert_eq!(observed.trim(), expected.trim());
659659
}
660660

@@ -694,7 +694,7 @@ fn dump_preprocessed_input() {
694694
);
695695
}
696696

697-
fn build_flags_output_helper(builder: &bindgen::Builder) {
697+
fn build_flags_output_helper(builder: &Builder) {
698698
let mut command_line_flags = builder.command_line_flags();
699699
command_line_flags.insert(0, "bindgen".to_string());
700700

@@ -712,7 +712,7 @@ fn build_flags_output_helper(builder: &bindgen::Builder) {
712712

713713
#[test]
714714
fn commandline_multiple_headers() {
715-
let bindings = bindgen::Builder::default()
715+
let bindings = Builder::default()
716716
.header("tests/headers/char.h")
717717
.header("tests/headers/func_ptr.h")
718718
.header("tests/headers/16-byte-alignment.h");

bindgen/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
lints.workspace = true
2+
13
[package]
24
authors = [
35
"Jyun-Yan You <[email protected]>",

bindgen/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ fn main() {
2020
println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS");
2121
println!(
2222
"cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}",
23-
std::env::var("TARGET").unwrap()
23+
env::var("TARGET").unwrap()
2424
);
2525
println!(
2626
"cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}",
27-
std::env::var("TARGET").unwrap().replace('-', "_")
27+
env::var("TARGET").unwrap().replace('-', "_")
2828
);
2929
}

bindgen/clang.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -961,13 +961,11 @@ impl Cursor {
961961
///
962962
/// Returns None if the cursor does not include a file, otherwise the file's full name
963963
pub(crate) fn get_included_file_name(&self) -> Option<String> {
964-
let file = unsafe { clang_sys::clang_getIncludedFile(self.x) };
964+
let file = unsafe { clang_getIncludedFile(self.x) };
965965
if file.is_null() {
966966
None
967967
} else {
968-
Some(unsafe {
969-
cxstring_into_string(clang_sys::clang_getFileName(file))
970-
})
968+
Some(unsafe { cxstring_into_string(clang_getFileName(file)) })
971969
}
972970
}
973971

bindgen/codegen/dyngen.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) struct DynamicItems {
1414
/// ...
1515
/// }
1616
/// ```
17-
struct_members: Vec<proc_macro2::TokenStream>,
17+
struct_members: Vec<TokenStream>,
1818

1919
/// Tracks the tokens that will appear inside the library struct's implementation, e.g.:
2020
///
@@ -26,7 +26,7 @@ pub(crate) struct DynamicItems {
2626
/// }
2727
/// }
2828
/// ```
29-
struct_implementation: Vec<proc_macro2::TokenStream>,
29+
struct_implementation: Vec<TokenStream>,
3030

3131
/// Tracks the initialization of the fields inside the `::new` constructor of the library
3232
/// struct, e.g.:
@@ -45,7 +45,7 @@ pub(crate) struct DynamicItems {
4545
/// ...
4646
/// }
4747
/// ```
48-
constructor_inits: Vec<proc_macro2::TokenStream>,
48+
constructor_inits: Vec<TokenStream>,
4949

5050
/// Tracks the information that is passed to the library struct at the end of the `::new`
5151
/// constructor, e.g.:
@@ -65,7 +65,7 @@ pub(crate) struct DynamicItems {
6565
/// }
6666
/// }
6767
/// ```
68-
init_fields: Vec<proc_macro2::TokenStream>,
68+
init_fields: Vec<TokenStream>,
6969
}
7070

7171
impl DynamicItems {
@@ -77,7 +77,7 @@ impl DynamicItems {
7777
&self,
7878
lib_ident: Ident,
7979
ctx: &BindgenContext,
80-
) -> proc_macro2::TokenStream {
80+
) -> TokenStream {
8181
let struct_members = &self.struct_members;
8282
let constructor_inits = &self.constructor_inits;
8383
let init_fields = &self.init_fields;
@@ -134,11 +134,11 @@ impl DynamicItems {
134134
abi: ClangAbi,
135135
is_variadic: bool,
136136
is_required: bool,
137-
args: Vec<proc_macro2::TokenStream>,
138-
args_identifiers: Vec<proc_macro2::TokenStream>,
139-
ret: proc_macro2::TokenStream,
140-
ret_ty: proc_macro2::TokenStream,
141-
attributes: Vec<proc_macro2::TokenStream>,
137+
args: Vec<TokenStream>,
138+
args_identifiers: Vec<TokenStream>,
139+
ret: TokenStream,
140+
ret_ty: TokenStream,
141+
attributes: Vec<TokenStream>,
142142
ctx: &BindgenContext,
143143
) {
144144
if !is_variadic {

bindgen/codegen/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,7 +3185,7 @@ impl fmt::Display for EnumVariation {
31853185
}
31863186
}
31873187

3188-
impl std::str::FromStr for EnumVariation {
3188+
impl FromStr for EnumVariation {
31893189
type Err = std::io::Error;
31903190

31913191
/// Create a `EnumVariation` from a string.
@@ -3892,7 +3892,7 @@ impl fmt::Display for MacroTypeVariation {
38923892
}
38933893
}
38943894

3895-
impl std::str::FromStr for MacroTypeVariation {
3895+
impl FromStr for MacroTypeVariation {
38963896
type Err = std::io::Error;
38973897

38983898
/// Create a `MacroTypeVariation` from a string.
@@ -3935,7 +3935,7 @@ impl fmt::Display for AliasVariation {
39353935
}
39363936
}
39373937

3938-
impl std::str::FromStr for AliasVariation {
3938+
impl FromStr for AliasVariation {
39393939
type Err = std::io::Error;
39403940

39413941
/// Create an `AliasVariation` from a string.
@@ -3984,7 +3984,7 @@ impl Default for NonCopyUnionStyle {
39843984
}
39853985
}
39863986

3987-
impl std::str::FromStr for NonCopyUnionStyle {
3987+
impl FromStr for NonCopyUnionStyle {
39883988
type Err = std::io::Error;
39893989

39903990
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -4102,7 +4102,7 @@ where
41024102
if let Ok(layout) = self.try_get_layout(ctx, extra) {
41034103
Ok(helpers::blob(layout))
41044104
} else {
4105-
Err(error::Error::NoLayoutForOpaqueBlob)
4105+
Err(Error::NoLayoutForOpaqueBlob)
41064106
}
41074107
})
41084108
}
@@ -4213,7 +4213,7 @@ impl TryToOpaque for Type {
42134213
ctx: &BindgenContext,
42144214
_: &Item,
42154215
) -> error::Result<Layout> {
4216-
self.layout(ctx).ok_or(error::Error::NoLayoutForOpaqueBlob)
4216+
self.layout(ctx).ok_or(Error::NoLayoutForOpaqueBlob)
42174217
}
42184218
}
42194219

@@ -4371,7 +4371,7 @@ impl TryToOpaque for TemplateInstantiation {
43714371
) -> error::Result<Layout> {
43724372
item.expect_type()
43734373
.layout(ctx)
4374-
.ok_or(error::Error::NoLayoutForOpaqueBlob)
4374+
.ok_or(Error::NoLayoutForOpaqueBlob)
43754375
}
43764376
}
43774377

@@ -4384,7 +4384,7 @@ impl TryToRustTy for TemplateInstantiation {
43844384
item: &Item,
43854385
) -> error::Result<syn::Type> {
43864386
if self.is_opaque(ctx, item) {
4387-
return Err(error::Error::InstantiationOfOpaqueType);
4387+
return Err(Error::InstantiationOfOpaqueType);
43884388
}
43894389

43904390
let def = self
@@ -4406,7 +4406,7 @@ impl TryToRustTy for TemplateInstantiation {
44064406
// template specialization, and we've hit an instantiation of
44074407
// that partial specialization.
44084408
extra_assert!(def.is_opaque(ctx, &()));
4409-
return Err(error::Error::InstantiationOfOpaqueType);
4409+
return Err(Error::InstantiationOfOpaqueType);
44104410
}
44114411

44124412
// TODO: If the definition type is a template class/struct
@@ -4458,7 +4458,7 @@ impl TryToRustTy for FunctionSig {
44584458
syn::parse_quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret },
44594459
),
44604460
Err(err) => {
4461-
if matches!(err, error::Error::UnsupportedAbi(_)) {
4461+
if matches!(err, Error::UnsupportedAbi(_)) {
44624462
unsupported_abi_diagnostic(
44634463
self.name(),
44644464
self.is_variadic(),
@@ -4574,7 +4574,7 @@ impl CodeGenerator for Function {
45744574

45754575
let abi = match signature.abi(ctx, Some(name)) {
45764576
Err(err) => {
4577-
if matches!(err, error::Error::UnsupportedAbi(_)) {
4577+
if matches!(err, Error::UnsupportedAbi(_)) {
45784578
unsupported_abi_diagnostic(
45794579
name,
45804580
signature.is_variadic(),
@@ -4715,7 +4715,7 @@ fn unsupported_abi_diagnostic(
47154715
variadic: bool,
47164716
location: Option<&crate::clang::SourceLocation>,
47174717
ctx: &BindgenContext,
4718-
error: &error::Error,
4718+
error: &Error,
47194719
) {
47204720
warn!(
47214721
"Skipping {}function `{}` because the {}",
@@ -5689,7 +5689,7 @@ pub(crate) mod utils {
56895689

56905690
pub(crate) fn fnsig_arguments_iter<
56915691
'a,
5692-
I: Iterator<Item = &'a (Option<String>, crate::ir::context::TypeId)>,
5692+
I: Iterator<Item = &'a (Option<String>, TypeId)>,
56935693
>(
56945694
ctx: &BindgenContext,
56955695
args_iter: I,

bindgen/ir/comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ enum Kind {
1313

1414
/// Preprocesses a C/C++ comment so that it is a valid Rust comment.
1515
pub(crate) fn preprocess(comment: &str) -> String {
16-
match self::kind(comment) {
16+
match kind(comment) {
1717
Some(Kind::SingleLines) => preprocess_single_lines(comment),
1818
Some(Kind::MultiLine) => preprocess_multi_line(comment),
1919
None => comment.to_owned(),

bindgen/ir/comp.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,8 +1474,7 @@ impl CompInfo {
14741474
ty: type_id,
14751475
kind,
14761476
field_name,
1477-
is_pub: cur.access_specifier() ==
1478-
clang_sys::CX_CXXPublic,
1477+
is_pub: cur.access_specifier() == CX_CXXPublic,
14791478
});
14801479
}
14811480
CXCursor_Constructor | CXCursor_Destructor |

0 commit comments

Comments
 (0)