diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index c712569816..583f46ea93 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -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"); diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index bbe7eb2e24..abb5f96953 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -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\"", ); @@ -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()); } @@ -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()); @@ -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"); diff --git a/bindgen/build.rs b/bindgen/build.rs index 8407ceae8f..4fb2d3075e 100644 --- a/bindgen/build.rs +++ b/bindgen/build.rs @@ -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('-', "_") ); } diff --git a/bindgen/clang.rs b/bindgen/clang.rs index bca4a80978..327ec137b0 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -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 { - 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)) }) } } diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index e75e11a297..6bdea51eff 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -14,7 +14,7 @@ pub(crate) struct DynamicItems { /// ... /// } /// ``` - struct_members: Vec, + struct_members: Vec, /// Tracks the tokens that will appear inside the library struct's implementation, e.g.: /// @@ -26,7 +26,7 @@ pub(crate) struct DynamicItems { /// } /// } /// ``` - struct_implementation: Vec, + struct_implementation: Vec, /// Tracks the initialization of the fields inside the `::new` constructor of the library /// struct, e.g.: @@ -45,7 +45,7 @@ pub(crate) struct DynamicItems { /// ... /// } /// ``` - constructor_inits: Vec, + constructor_inits: Vec, /// Tracks the information that is passed to the library struct at the end of the `::new` /// constructor, e.g.: @@ -65,7 +65,7 @@ pub(crate) struct DynamicItems { /// } /// } /// ``` - init_fields: Vec, + init_fields: Vec, } impl DynamicItems { @@ -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; @@ -134,11 +134,11 @@ impl DynamicItems { abi: ClangAbi, is_variadic: bool, is_required: bool, - args: Vec, - args_identifiers: Vec, - ret: proc_macro2::TokenStream, - ret_ty: proc_macro2::TokenStream, - attributes: Vec, + args: Vec, + args_identifiers: Vec, + ret: TokenStream, + ret_ty: TokenStream, + attributes: Vec, ctx: &BindgenContext, ) { if !is_variadic { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c58237c17b..f60a75d23a 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -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. @@ -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. @@ -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. @@ -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 { @@ -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) } }) } @@ -4207,7 +4207,7 @@ impl TryToOpaque for Type { ctx: &BindgenContext, _: &Item, ) -> error::Result { - self.layout(ctx).ok_or(error::Error::NoLayoutForOpaqueBlob) + self.layout(ctx).ok_or(Error::NoLayoutForOpaqueBlob) } } @@ -4365,7 +4365,7 @@ impl TryToOpaque for TemplateInstantiation { ) -> error::Result { item.expect_type() .layout(ctx) - .ok_or(error::Error::NoLayoutForOpaqueBlob) + .ok_or(Error::NoLayoutForOpaqueBlob) } } @@ -4378,7 +4378,7 @@ impl TryToRustTy for TemplateInstantiation { item: &Item, ) -> error::Result { if self.is_opaque(ctx, item) { - return Err(error::Error::InstantiationOfOpaqueType); + return Err(Error::InstantiationOfOpaqueType); } let def = self @@ -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 @@ -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(), @@ -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(), @@ -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}", @@ -5676,7 +5676,7 @@ pub(crate) mod utils { pub(crate) fn fnsig_arguments_iter< 'a, - I: Iterator, crate::ir::context::TypeId)>, + I: Iterator, TypeId)>, >( ctx: &BindgenContext, args_iter: I, diff --git a/bindgen/ir/comment.rs b/bindgen/ir/comment.rs index 03fc76ff98..a4ba320186 100644 --- a/bindgen/ir/comment.rs +++ b/bindgen/ir/comment.rs @@ -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(), diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 68884bd20a..093d553ad0 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -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 | diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index d8bcaba1d4..6cdf8b4af8 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -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, + type_params: HashMap, /// A cursor to module map. Similar reason than above. modules: HashMap, @@ -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, + semantic_parents: HashMap, /// A stack with the current type declarations and types we're parsing. This /// is needed to avoid infinite recursion when parsing a type like: @@ -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!( @@ -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 { + pub(crate) fn get_type_param(&self, definition: &Cursor) -> Option { assert_eq!( definition.kind(), clang_sys::CXCursor_TemplateTypeParameter @@ -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)> { + ) -> Vec<(ItemId, clang::Type, Cursor, Option)> { debug_assert!(!self.collected_typerefs); self.collected_typerefs = true; let mut typerefs = vec![]; @@ -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); @@ -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 { self.semantic_parents.get(&definition).copied() } @@ -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 { let num_expected_args = self.resolve_type(template).num_self_template_params(self); @@ -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, ty: &clang::Type, - location: Option, + location: Option, ) -> Option { use clang_sys::{CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef}; debug!("builtin_or_resolved_ty: {ty:?}, {location:?}, {with_id:?}, {parent_id:?}"); @@ -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, ModuleKind) { assert_eq!( cursor.kind(), @@ -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(); diff --git a/bindgen/ir/dot.rs b/bindgen/ir/dot.rs index 9b81b8749c..0ccee42c0d 100644 --- a/bindgen/ir/dot.rs +++ b/bindgen/ir/dot.rs @@ -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. diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index ee0fdc525b..1157149529 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -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() diff --git a/bindgen/ir/layout.rs b/bindgen/ir/layout.rs index fc248e1dfa..905e47c732 100644 --- a/bindgen/ir/layout.rs +++ b/bindgen/ir/layout.rs @@ -19,9 +19,8 @@ pub(crate) struct Layout { #[test] fn test_layout_for_size() { - use std::mem; - - let ptr_size = mem::size_of::<*mut ()>(); + use std::mem::size_of; + let ptr_size = size_of::<*mut ()>(); assert_eq!( Layout::for_size_internal(ptr_size, ptr_size), Layout::new(ptr_size, ptr_size) diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index fc3bfa6088..5aea619808 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -637,12 +637,7 @@ pub(crate) enum TypeKind { /// already known types, and are converted to ResolvedTypeRef. /// /// see tests/headers/typeref.hpp to see somewhere where this is a problem. - UnresolvedTypeRef( - clang::Type, - clang::Cursor, - /* parent_id */ - Option, - ), + UnresolvedTypeRef(clang::Type, Cursor, /* parent_id */ Option), /// An indirection to another type. /// diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 2aa92f84bd..8f9aa4441c 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -477,7 +477,7 @@ fn get_integer_literal_from_cursor(cursor: &clang::Cursor) -> Option { fn duplicated_macro_diagnostic( macro_name: &str, - _location: crate::clang::SourceLocation, + _location: clang::SourceLocation, _ctx: &BindgenContext, ) { warn!("Duplicated macro definition: {macro_name}"); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index e599f759c7..5bc325ed0d 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -70,6 +70,7 @@ use std::env; use std::ffi::OsStr; use std::fs::{File, OpenOptions}; use std::io::{self, Write}; +use std::mem::size_of; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use std::rc::Rc; @@ -888,7 +889,7 @@ impl Bindings { if is_host_build { debug_assert_eq!( context.target_pointer_size(), - std::mem::size_of::<*mut ()>(), + size_of::<*mut ()>(), "{effective_target:?} {HOST_TARGET:?}" ); } @@ -1184,11 +1185,11 @@ pub fn clang_version() -> ClangVersion { fn env_var + AsRef>( parse_callbacks: &[Rc], key: K, -) -> Result { +) -> Result { for callback in parse_callbacks { callback.read_env_var(key.as_ref()); } - std::env::var(key) + env::var(key) } /// Looks for the env var `var_${TARGET}`, and falls back to just `var` when it is not found. @@ -1281,7 +1282,7 @@ impl callbacks::ParseCallbacks for CargoCallbacks { #[test] fn commandline_flag_unit_test_function() { //Test 1 - let bindings = crate::builder(); + let bindings = builder(); let command_line_flags = bindings.command_line_flags(); let test_cases = [ @@ -1297,7 +1298,7 @@ fn commandline_flag_unit_test_function() { assert!(test_cases.iter().all(|x| command_line_flags.contains(x))); //Test 2 - let bindings = crate::builder() + let bindings = builder() .header("input_header") .allowlist_type("Distinct_Type") .allowlist_function("safe_function"); diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 834c7c7625..0bfb290d35 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -1,3 +1,5 @@ +#![allow(unused_qualifications)] // Clap somehow generates a lot of these + use crate::{ builder, callbacks::{ @@ -810,7 +812,7 @@ where shell, &mut BindgenCommand::command(), "bindgen", - &mut std::io::stdout(), + &mut io::stdout(), ); exit(0)