From e663f0f8e0423a20c141ab5f1ec89eb2c5db8ec2 Mon Sep 17 00:00:00 2001 From: a30054014 Date: Sat, 19 Apr 2025 09:26:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?rust-bindgen=E7=9B=B8=E5=85=B3=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=85=BC=E5=AE=B9=E6=80=A7=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: a30054014 --- bindgen-cli/options.rs | 11 ---- bindgen/callbacks.rs | 1 - bindgen/codegen/mod.rs | 116 +++-------------------------------------- bindgen/features.rs | 1 - bindgen/ir/comp.rs | 3 -- bindgen/ir/context.rs | 16 +----- bindgen/ir/var.rs | 25 +-------- bindgen/lib.rs | 32 +----------- bindgen/regex_set.rs | 73 ++------------------------ 9 files changed, 16 insertions(+), 262 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index cd5e9bb1..3c5417bc 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -444,7 +444,6 @@ struct BindgenCommand { emit_diagnostics: bool, /// Generates completions for the specified SHELL, sends them to `stdout` and exits. #[arg(long, value_name = "SHELL")] - generate_shell_completions: Option, /// Enables experimental features. #[arg(long)] experimental: bool, @@ -579,22 +578,12 @@ where wrap_static_fns_suffix, default_visibility, emit_diagnostics, - generate_shell_completions, experimental: _, version, clang_args, } = command; - if let Some(shell) = generate_shell_completions { - clap_complete::generate( - shell, - &mut BindgenCommand::command(), - "bindgen", - &mut std::io::stdout(), - ); - exit(0); - } if version { println!( diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 0f16c4c0..1d059e65 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -20,7 +20,6 @@ pub enum MacroParsingBehavior { /// A trait to allow configuring different kinds of types in different /// situations. pub trait ParseCallbacks: fmt::Debug { - #[cfg(feature = "__cli")] #[doc(hidden)] fn cli_args(&self) -> Vec { vec![] diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 741a3fbe..531d9e86 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -128,7 +128,6 @@ fn root_import( } bitflags! { - #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] struct DerivableTraits: u16 { const DEBUG = 1 << 0; const DEFAULT = 1 << 1; @@ -4340,15 +4339,6 @@ impl TryToRustTy for FunctionSig { syn::parse_quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret }, ), Err(err) => { - if matches!(err, error::Error::UnsupportedAbi(_)) { - unsupported_abi_diagnostic( - self.name(), - self.is_variadic(), - item.location(), - ctx, - &err, - ); - } Err(err) } @@ -4391,7 +4381,6 @@ impl CodeGenerator for Function { if signature.is_variadic() { // We cannot generate wrappers for variadic static functions so we avoid // generating any code for them. - variadic_fn_diagnostic(self.name(), item.location(), ctx); return None; } } @@ -4457,13 +4446,6 @@ impl CodeGenerator for Function { let abi = match signature.abi(ctx, Some(name)) { Err(err) => { if matches!(err, error::Error::UnsupportedAbi(_)) { - unsupported_abi_diagnostic( - name, - signature.is_variadic(), - item.location(), - ctx, - &err, - ); } return None; @@ -4592,102 +4574,18 @@ impl CodeGenerator for Function { } } -#[cfg_attr(not(feature = "experimental"), allow(unused_variables))] -fn unsupported_abi_diagnostic( - fn_name: &str, - variadic: bool, - location: Option<&crate::clang::SourceLocation>, - ctx: &BindgenContext, - error: &error::Error, -) { - warn!( - "Skipping {}function `{}` because the {}", - if variadic { "variadic " } else { "" }, - fn_name, - error - ); - - #[cfg(feature = "experimental")] - if ctx.options().emit_diagnostics { - use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; - - let mut diag = Diagnostic::default(); - diag.with_title( - format!( - "Skipping {}function `{}` because the {}", - if variadic { "variadic " } else { "" }, - fn_name, - error - ), - Level::Warn, - ) - .add_annotation( - "No code will be generated for this function.", - Level::Warn, - ) - .add_annotation( - format!( - "The configured Rust version is {}.", - ctx.options().rust_target - ), - Level::Note, - ); - if let Some(loc) = location { - let (file, line, col, _) = loc.location(); - if let Some(filename) = file.name() { - if let Ok(Some(source)) = get_line(&filename, line) { - let mut slice = Slice::default(); - slice - .with_source(source) - .with_location(filename, line, col); - diag.add_slice(slice); - } - } - } - diag.display() - } -} -fn variadic_fn_diagnostic( - fn_name: &str, - _location: Option<&crate::clang::SourceLocation>, - _ctx: &BindgenContext, -) { - warn!( - "Cannot generate wrapper for the static variadic function `{}`.", - fn_name, - ); - - #[cfg(feature = "experimental")] - if _ctx.options().emit_diagnostics { - use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; - - let mut diag = Diagnostic::default(); - - diag.with_title(format!("Cannot generate wrapper for the static function `{}`.", fn_name), Level::Warn) - .add_annotation("The `--wrap-static-fns` feature does not support variadic functions.", Level::Note) - .add_annotation("No code will be generated for this function.", Level::Note); - - if let Some(loc) = _location { - let (file, line, col, _) = loc.location(); - - if let Some(filename) = file.name() { - if let Ok(Some(source)) = get_line(&filename, line) { - let mut slice = Slice::default(); - slice - .with_source(source) - .with_location(filename, line, col); - diag.add_slice(slice); - } - } - } - diag.display() - } -} + + + + + + + fn objc_method_codegen( ctx: &BindgenContext, diff --git a/bindgen/features.rs b/bindgen/features.rs index 990e4513..2cb2aaac 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -56,7 +56,6 @@ macro_rules! define_rust_targets { } } - #[cfg(feature = "__cli")] /// Strings of allowed `RustTarget` values pub const RUST_TARGET_STRINGS: &[&str] = &[$(concat!("1.", stringify!($minor)),)*]; diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 036e7e5c..d08be80d 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1,6 +1,5 @@ //! Compound types (unions and structs) in our intermediate representation. -use itertools::Itertools; use super::analysis::Sizedness; use super::annotations::Annotations; @@ -496,7 +495,6 @@ where { let non_bitfields = raw_fields .by_ref() - .peeking_take_while(|f| f.bitfield_width().is_none()) .map(|f| Field::DataMember(f.0)); fields.extend(non_bitfields); } @@ -506,7 +504,6 @@ where // the Itanium C++ ABI. let mut bitfields = raw_fields .by_ref() - .peeking_take_while(|f| f.bitfield_width().is_some()) .peekable(); if bitfields.peek().is_none() { diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index a1536935..715a835c 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -3137,19 +3137,5 @@ impl TemplateParameters for PartialType { fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) { warn!("unused option: {} {}", name, item); - #[cfg(feature = "experimental")] - if _ctx.options().emit_diagnostics { - use crate::diagnostics::{Diagnostic, Level}; - - Diagnostic::default() - .with_title( - format!("Unused regular expression: `{}`.", item), - Level::Warn, - ) - .add_annotation( - format!("This regular expression was passed to `{}`.", name), - Level::Note, - ) - .display(); - } + } diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 40a061e1..4da14e96 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -486,7 +486,6 @@ fn duplicated_macro_diagnostic( ) { warn!("Duplicated macro definition: {}", macro_name); - #[cfg(feature = "experimental")] // FIXME (pvdrz & amanjeev): This diagnostic message shows way too often to be actually // useful. We have to change the logic where this function is called to be able to emit this // message only when the duplication is an actual issue. @@ -499,28 +498,8 @@ fn duplicated_macro_diagnostic( // ``` // // Will trigger this message even though there's nothing wrong with it. - #[allow(clippy::overly_complex_bool_expr)] - if false && _ctx.options().emit_diagnostics { - use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; - use std::borrow::Cow; - - let mut slice = Slice::default(); - let mut source = Cow::from(macro_name); - - let (file, line, col, _) = _location.location(); - if let Some(filename) = file.name() { - if let Ok(Some(code)) = get_line(&filename, line) { - source = code.into(); - } - slice.with_location(filename, line, col); - } - slice.with_source(source); - Diagnostic::default() - .with_title("Duplicated macro definition.", Level::Warn) - .add_slice(slice) - .add_annotation("This macro had a duplicate.", Level::Note) - .display(); - } + + } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 3bf0bc3c..4e8d3e64 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -41,7 +41,6 @@ pub mod callbacks; mod clang; #[cfg(feature = "experimental")] -mod diagnostics; mod features; mod ir; mod parse; @@ -50,7 +49,6 @@ mod regex_set; pub use codegen::{ AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, }; -#[cfg(feature = "__cli")] pub use features::RUST_TARGET_STRINGS; pub use features::{RustTarget, LATEST_STABLE_RUST}; pub use ir::annotations::FieldVisibilityKind; @@ -110,7 +108,6 @@ fn args_are_cpp(clang_args: &[Box]) -> bool { bitflags! { /// A type used to indicate which kind of items we have to generate. - #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct CodegenConfig: u32 { /// Whether to generate functions. const FUNCTIONS = 1 << 0; @@ -587,24 +584,8 @@ impl BindgenOptions { } fn deprecated_target_diagnostic(target: RustTarget, _options: &BindgenOptions) { - warn!("The {} Rust target is deprecated. If you have a need to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", target); - #[cfg(feature = "experimental")] - if _options.emit_diagnostics { - use crate::diagnostics::{Diagnostic, Level}; - let mut diagnostic = Diagnostic::default(); - diagnostic.with_title( - format!("The {} Rust target is deprecated.", target), - Level::Warn, - ); - diagnostic.add_annotation( - "This Rust target was passed to `--rust-target`", - Level::Info, - ); - diagnostic.add_annotation("If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", Level::Help); - diagnostic.display(); - } } #[cfg(feature = "runtime")] @@ -1052,18 +1033,7 @@ impl Bindings { fn rustfmt_non_fatal_error_diagnostic(msg: &str, _options: &BindgenOptions) { warn!("{}", msg); - #[cfg(feature = "experimental")] - if _options.emit_diagnostics { - use crate::diagnostics::{Diagnostic, Level}; - - Diagnostic::default() - .with_title(msg, Level::Warn) - .add_annotation( - "The bindings will be generated but not formatted.", - Level::Note, - ) - .display(); - } + } impl std::fmt::Display for Bindings { diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index b78424aa..3dcaaf87 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -63,7 +63,6 @@ impl RegexSet { self.build_inner(record_matches, None) } - #[cfg(all(feature = "__cli", feature = "experimental"))] /// Construct a RegexSet from the set of entries we've accumulated and emit diagnostics if the /// name of the regex set is passed to it. /// @@ -78,20 +77,6 @@ impl RegexSet { self.build_inner(record_matches, name) } - #[cfg(all(not(feature = "__cli"), feature = "experimental"))] - /// Construct a RegexSet from the set of entries we've accumulated and emit diagnostics if the - /// name of the regex set is passed to it. - /// - /// Must be called before calling `matches()`, or it will always return - /// false. - #[inline] - pub(crate) fn build_with_diagnostics( - &mut self, - record_matches: bool, - name: Option<&'static str>, - ) { - self.build_inner(record_matches, name) - } fn build_inner( &mut self, @@ -146,59 +131,11 @@ fn invalid_regex_warning( err: regex::Error, name: &'static str, ) { - use crate::diagnostics::{Diagnostic, Level, Slice}; - - let mut diagnostic = Diagnostic::default(); - - match err { - regex::Error::Syntax(string) => { - if string.starts_with("regex parse error:\n") { - let mut source = String::new(); - - let mut parsing_source = true; - - for line in string.lines().skip(1) { - if parsing_source { - if line.starts_with(' ') { - source.push_str(line); - source.push('\n'); - continue; - } - parsing_source = false; - } - let error = "error: "; - if line.starts_with(error) { - let (_, msg) = line.split_at(error.len()); - diagnostic.add_annotation(msg.to_owned(), Level::Error); - } else { - diagnostic.add_annotation(line.to_owned(), Level::Info); - } - } - let mut slice = Slice::default(); - slice.with_source(source); - diagnostic.add_slice(slice); - - diagnostic.with_title( - "Error while parsing a regular expression.", - Level::Warn, - ); - } else { - diagnostic.with_title(string, Level::Warn); - } - } - err => { - let err = err.to_string(); - diagnostic.with_title(err, Level::Warn); - } - } - diagnostic.add_annotation( - format!("This regular expression was passed via `{}`.", name), - Level::Note, - ); - if set.items.iter().any(|item| item.as_ref() == "*") { - diagnostic.add_annotation("Wildcard patterns \"*\" are no longer considered valid. Use \".*\" instead.", Level::Help); - } - diagnostic.display(); + + + + + } -- Gitee From aa2cb63f2a3dd717b7e68d4c0a4704468632cf6e Mon Sep 17 00:00:00 2001 From: a30054014 Date: Sat, 19 Apr 2025 09:54:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?rust-bindgen=E7=9B=B8=E5=85=B3=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=85=BC=E5=AE=B9=E6=80=A7=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: a30054014 --- bindgen/codegen/mod.rs | 13 ------------- bindgen/ir/context.rs | 1 - bindgen/ir/var.rs | 2 -- bindgen/lib.rs | 1 - bindgen/regex_set.rs | 5 ----- 5 files changed, 22 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 531d9e86..03048506 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4574,19 +4574,6 @@ impl CodeGenerator for Function { } } - - - - - - - - - - - - - fn objc_method_codegen( ctx: &BindgenContext, method: &ObjCMethod, diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 715a835c..22bbe8a2 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -3137,5 +3137,4 @@ impl TemplateParameters for PartialType { fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) { warn!("unused option: {} {}", name, item); - } diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 4da14e96..bde630f7 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -500,6 +500,4 @@ fn duplicated_macro_diagnostic( // Will trigger this message even though there's nothing wrong with it. - - } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 4e8d3e64..429ab7e7 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1033,7 +1033,6 @@ impl Bindings { fn rustfmt_non_fatal_error_diagnostic(msg: &str, _options: &BindgenOptions) { warn!("{}", msg); - } impl std::fmt::Display for Bindings { diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 3dcaaf87..d90651b7 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -133,9 +133,4 @@ fn invalid_regex_warning( ) { - - - - - } -- Gitee