Skip to content

Commit

Permalink
Fix a lot of unused_qualifications lints
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik authored and pvdrz committed Dec 1, 2024
1 parent 6bb890b commit 76a1134
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 75 deletions.
2 changes: 1 addition & 1 deletion bindgen-integration/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn setup_macro_test() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let out_rust_file = out_path.join("test.rs");
let out_rust_file_relative = out_rust_file
.strip_prefix(std::env::current_dir().unwrap().parent().unwrap())
.strip_prefix(env::current_dir().unwrap().parent().unwrap())
.unwrap();
let out_dep_file = out_path.join("test.d");

Expand Down
10 changes: 5 additions & 5 deletions bindgen-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ include!(concat!(env!("OUT_DIR"), "/tests.rs"));
#[test]
#[cfg_attr(target_os = "windows", ignore)]
fn test_clang_env_args() {
std::env::set_var(
env::set_var(
"BINDGEN_EXTRA_CLANG_ARGS",
"-D_ENV_ONE=1 -D_ENV_TWO=\"2 -DNOT_THREE=1\"",
);
Expand Down Expand Up @@ -653,8 +653,8 @@ fn emit_depfile() {
builder.into_builder(check_roundtrip).unwrap();
let _bindings = builder.generate().unwrap();

let observed = std::fs::read_to_string(observed_depfile).unwrap();
let expected = std::fs::read_to_string(expected_depfile).unwrap();
let observed = fs::read_to_string(observed_depfile).unwrap();
let expected = fs::read_to_string(expected_depfile).unwrap();
assert_eq!(observed.trim(), expected.trim());
}

Expand Down Expand Up @@ -694,7 +694,7 @@ fn dump_preprocessed_input() {
);
}

fn build_flags_output_helper(builder: &bindgen::Builder) {
fn build_flags_output_helper(builder: &Builder) {
let mut command_line_flags = builder.command_line_flags();
command_line_flags.insert(0, "bindgen".to_string());

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

#[test]
fn commandline_multiple_headers() {
let bindings = bindgen::Builder::default()
let bindings = Builder::default()
.header("tests/headers/char.h")
.header("tests/headers/func_ptr.h")
.header("tests/headers/16-byte-alignment.h");
Expand Down
4 changes: 2 additions & 2 deletions bindgen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ fn main() {
println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS");
println!(
"cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}",
std::env::var("TARGET").unwrap()
env::var("TARGET").unwrap()
);
println!(
"cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}",
std::env::var("TARGET").unwrap().replace('-', "_")
env::var("TARGET").unwrap().replace('-', "_")
);
}
6 changes: 2 additions & 4 deletions bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,11 @@ impl Cursor {
///
/// Returns None if the cursor does not include a file, otherwise the file's full name
pub(crate) fn get_included_file_name(&self) -> Option<String> {
let file = unsafe { clang_sys::clang_getIncludedFile(self.x) };
let file = unsafe { clang_getIncludedFile(self.x) };
if file.is_null() {
None
} else {
Some(unsafe {
cxstring_into_string(clang_sys::clang_getFileName(file))
})
Some(unsafe { cxstring_into_string(clang_getFileName(file)) })
}
}

Expand Down
20 changes: 10 additions & 10 deletions bindgen/codegen/dyngen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) struct DynamicItems {
/// ...
/// }
/// ```
struct_members: Vec<proc_macro2::TokenStream>,
struct_members: Vec<TokenStream>,

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

/// Tracks the initialization of the fields inside the `::new` constructor of the library
/// struct, e.g.:
Expand All @@ -45,7 +45,7 @@ pub(crate) struct DynamicItems {
/// ...
/// }
/// ```
constructor_inits: Vec<proc_macro2::TokenStream>,
constructor_inits: Vec<TokenStream>,

/// Tracks the information that is passed to the library struct at the end of the `::new`
/// constructor, e.g.:
Expand All @@ -65,7 +65,7 @@ pub(crate) struct DynamicItems {
/// }
/// }
/// ```
init_fields: Vec<proc_macro2::TokenStream>,
init_fields: Vec<TokenStream>,
}

impl DynamicItems {
Expand All @@ -77,7 +77,7 @@ impl DynamicItems {
&self,
lib_ident: Ident,
ctx: &BindgenContext,
) -> proc_macro2::TokenStream {
) -> TokenStream {
let struct_members = &self.struct_members;
let constructor_inits = &self.constructor_inits;
let init_fields = &self.init_fields;
Expand Down Expand Up @@ -134,11 +134,11 @@ impl DynamicItems {
abi: ClangAbi,
is_variadic: bool,
is_required: bool,
args: Vec<proc_macro2::TokenStream>,
args_identifiers: Vec<proc_macro2::TokenStream>,
ret: proc_macro2::TokenStream,
ret_ty: proc_macro2::TokenStream,
attributes: Vec<proc_macro2::TokenStream>,
args: Vec<TokenStream>,
args_identifiers: Vec<TokenStream>,
ret: TokenStream,
ret_ty: TokenStream,
attributes: Vec<TokenStream>,
ctx: &BindgenContext,
) {
if !is_variadic {
Expand Down
26 changes: 13 additions & 13 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3180,7 +3180,7 @@ impl fmt::Display for EnumVariation {
}
}

impl std::str::FromStr for EnumVariation {
impl FromStr for EnumVariation {
type Err = std::io::Error;

/// Create a `EnumVariation` from a string.
Expand Down Expand Up @@ -3886,7 +3886,7 @@ impl fmt::Display for MacroTypeVariation {
}
}

impl std::str::FromStr for MacroTypeVariation {
impl FromStr for MacroTypeVariation {
type Err = std::io::Error;

/// Create a `MacroTypeVariation` from a string.
Expand Down Expand Up @@ -3929,7 +3929,7 @@ impl fmt::Display for AliasVariation {
}
}

impl std::str::FromStr for AliasVariation {
impl FromStr for AliasVariation {
type Err = std::io::Error;

/// Create an `AliasVariation` from a string.
Expand Down Expand Up @@ -3978,7 +3978,7 @@ impl Default for NonCopyUnionStyle {
}
}

impl std::str::FromStr for NonCopyUnionStyle {
impl FromStr for NonCopyUnionStyle {
type Err = std::io::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand Down Expand Up @@ -4096,7 +4096,7 @@ where
if let Ok(layout) = self.try_get_layout(ctx, extra) {
Ok(helpers::blob(layout))
} else {
Err(error::Error::NoLayoutForOpaqueBlob)
Err(Error::NoLayoutForOpaqueBlob)
}
})
}
Expand Down Expand Up @@ -4207,7 +4207,7 @@ impl TryToOpaque for Type {
ctx: &BindgenContext,
_: &Item,
) -> error::Result<Layout> {
self.layout(ctx).ok_or(error::Error::NoLayoutForOpaqueBlob)
self.layout(ctx).ok_or(Error::NoLayoutForOpaqueBlob)
}
}

Expand Down Expand Up @@ -4365,7 +4365,7 @@ impl TryToOpaque for TemplateInstantiation {
) -> error::Result<Layout> {
item.expect_type()
.layout(ctx)
.ok_or(error::Error::NoLayoutForOpaqueBlob)
.ok_or(Error::NoLayoutForOpaqueBlob)
}
}

Expand All @@ -4378,7 +4378,7 @@ impl TryToRustTy for TemplateInstantiation {
item: &Item,
) -> error::Result<syn::Type> {
if self.is_opaque(ctx, item) {
return Err(error::Error::InstantiationOfOpaqueType);
return Err(Error::InstantiationOfOpaqueType);
}

let def = self
Expand All @@ -4400,7 +4400,7 @@ impl TryToRustTy for TemplateInstantiation {
// template specialization, and we've hit an instantiation of
// that partial specialization.
extra_assert!(def.is_opaque(ctx, &()));
return Err(error::Error::InstantiationOfOpaqueType);
return Err(Error::InstantiationOfOpaqueType);
}

// TODO: If the definition type is a template class/struct
Expand Down Expand Up @@ -4452,7 +4452,7 @@ impl TryToRustTy for FunctionSig {
syn::parse_quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret },
),
Err(err) => {
if matches!(err, error::Error::UnsupportedAbi(_)) {
if matches!(err, Error::UnsupportedAbi(_)) {
unsupported_abi_diagnostic(
self.name(),
self.is_variadic(),
Expand Down Expand Up @@ -4568,7 +4568,7 @@ impl CodeGenerator for Function {

let abi = match signature.abi(ctx, Some(name)) {
Err(err) => {
if matches!(err, error::Error::UnsupportedAbi(_)) {
if matches!(err, Error::UnsupportedAbi(_)) {
unsupported_abi_diagnostic(
name,
signature.is_variadic(),
Expand Down Expand Up @@ -4709,7 +4709,7 @@ fn unsupported_abi_diagnostic(
variadic: bool,
location: Option<&crate::clang::SourceLocation>,
ctx: &BindgenContext,
error: &error::Error,
error: &Error,
) {
warn!(
"Skipping {}function `{fn_name}` because the {error}",
Expand Down Expand Up @@ -5676,7 +5676,7 @@ pub(crate) mod utils {

pub(crate) fn fnsig_arguments_iter<
'a,
I: Iterator<Item = &'a (Option<String>, crate::ir::context::TypeId)>,
I: Iterator<Item = &'a (Option<String>, TypeId)>,
>(
ctx: &BindgenContext,
args_iter: I,
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum Kind {

/// Preprocesses a C/C++ comment so that it is a valid Rust comment.
pub(crate) fn preprocess(comment: &str) -> String {
match self::kind(comment) {
match kind(comment) {
Some(Kind::SingleLines) => preprocess_single_lines(comment),
Some(Kind::MultiLine) => preprocess_multi_line(comment),
None => comment.to_owned(),
Expand Down
3 changes: 1 addition & 2 deletions bindgen/ir/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,8 +1473,7 @@ impl CompInfo {
ty: type_id,
kind,
field_name,
is_pub: cur.access_specifier() ==
clang_sys::CX_CXXPublic,
is_pub: cur.access_specifier() == CX_CXXPublic,
});
}
CXCursor_Constructor | CXCursor_Destructor |
Expand Down
29 changes: 11 additions & 18 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ pub(crate) struct BindgenContext {

/// Maps from a cursor to the item ID of the named template type parameter
/// for that cursor.
type_params: HashMap<clang::Cursor, TypeId>,
type_params: HashMap<Cursor, TypeId>,

/// A cursor to module map. Similar reason than above.
modules: HashMap<Cursor, ModuleId>,
Expand All @@ -336,7 +336,7 @@ pub(crate) struct BindgenContext {
/// This is used to handle the cases where the semantic and the lexical
/// parents of the cursor differ, like when a nested class is defined
/// outside of the parent class.
semantic_parents: HashMap<clang::Cursor, ItemId>,
semantic_parents: HashMap<Cursor, ItemId>,

/// A stack with the current type declarations and types we're parsing. This
/// is needed to avoid infinite recursion when parsing a type like:
Expand Down Expand Up @@ -810,11 +810,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
}

/// Add a new named template type parameter to this context's item set.
pub(crate) fn add_type_param(
&mut self,
item: Item,
definition: clang::Cursor,
) {
pub(crate) fn add_type_param(&mut self, item: Item, definition: Cursor) {
debug!("BindgenContext::add_type_param: item = {item:?}; definition = {definition:?}");

assert!(
Expand Down Expand Up @@ -846,10 +842,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"

/// Get the named type defined at the given cursor location, if we've
/// already added one.
pub(crate) fn get_type_param(
&self,
definition: &clang::Cursor,
) -> Option<TypeId> {
pub(crate) fn get_type_param(&self, definition: &Cursor) -> Option<TypeId> {
assert_eq!(
definition.kind(),
clang_sys::CXCursor_TemplateTypeParameter
Expand Down Expand Up @@ -923,7 +916,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
/// Gather all the unresolved type references.
fn collect_typerefs(
&mut self,
) -> Vec<(ItemId, clang::Type, clang::Cursor, Option<ItemId>)> {
) -> Vec<(ItemId, clang::Type, Cursor, Option<ItemId>)> {
debug_assert!(!self.collected_typerefs);
self.collected_typerefs = true;
let mut typerefs = vec![];
Expand Down Expand Up @@ -1517,7 +1510,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
/// not sure it's worth it.
pub(crate) fn add_semantic_parent(
&mut self,
definition: clang::Cursor,
definition: Cursor,
parent_id: ItemId,
) {
self.semantic_parents.insert(definition, parent_id);
Expand All @@ -1526,7 +1519,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
/// Returns a known semantic parent for a given definition.
pub(crate) fn known_semantic_parent(
&self,
definition: clang::Cursor,
definition: Cursor,
) -> Option<ItemId> {
self.semantic_parents.get(&definition).copied()
}
Expand Down Expand Up @@ -1631,7 +1624,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
with_id: ItemId,
template: TypeId,
ty: &clang::Type,
location: clang::Cursor,
location: Cursor,
) -> Option<TypeId> {
let num_expected_args =
self.resolve_type(template).num_self_template_params(self);
Expand Down Expand Up @@ -1856,7 +1849,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
with_id: ItemId,
parent_id: Option<ItemId>,
ty: &clang::Type,
location: Option<clang::Cursor>,
location: Option<Cursor>,
) -> Option<TypeId> {
use clang_sys::{CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef};
debug!("builtin_or_resolved_ty: {ty:?}, {location:?}, {with_id:?}, {parent_id:?}");
Expand Down Expand Up @@ -2227,7 +2220,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
/// namespace.
fn tokenize_namespace(
&self,
cursor: &clang::Cursor,
cursor: &Cursor,
) -> (Option<String>, ModuleKind) {
assert_eq!(
cursor.kind(),
Expand Down Expand Up @@ -2306,7 +2299,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"

/// Given a CXCursor_Namespace cursor, return the item ID of the
/// corresponding module, or create one on the fly.
pub(crate) fn module(&mut self, cursor: clang::Cursor) -> ModuleId {
pub(crate) fn module(&mut self, cursor: Cursor) -> ModuleId {
use clang_sys::*;
assert_eq!(cursor.kind(), CXCursor_Namespace, "Be a nice person");
let cursor = cursor.canonical();
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) trait DotAttributes {
out: &mut W,
) -> io::Result<()>
where
W: io::Write;
W: Write;
}

/// Write a graphviz dot file containing our IR.
Expand Down
4 changes: 2 additions & 2 deletions bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,8 +1563,8 @@ impl Item {
\tlocation = {location:?}",
);

if ty.kind() == clang_sys::CXType_Unexposed ||
location.cur_type().kind() == clang_sys::CXType_Unexposed
if ty.kind() == CXType_Unexposed ||
location.cur_type().kind() == CXType_Unexposed
{
if ty.is_associated_type() ||
location.cur_type().is_associated_type()
Expand Down
Loading

0 comments on commit 76a1134

Please sign in to comment.