diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 0a28e8f56b..93375fbcee 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -1,8 +1,8 @@ extern crate bindgen; extern crate cc; -use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks, IntKind}; -use bindgen::Builder; +use bindgen::callbacks::{IntKind, MacroParsingBehavior, ParseCallbacks}; +use bindgen::{Builder, EnumVariation}; use std::collections::HashSet; use std::env; use std::path::PathBuf; @@ -50,9 +50,9 @@ impl ParseCallbacks for MacroCallback { assert_eq!(value, b"string"); *self.seen_hellos.lock().unwrap() += 1; } - "TESTMACRO_STRING_EXPANDED" | - "TESTMACRO_STRING" | - "TESTMACRO_INTEGER" => { + "TESTMACRO_STRING_EXPANDED" + | "TESTMACRO_STRING" + | "TESTMACRO_INTEGER" => { // The integer test macro is, actually, not expected to show up here at all -- but // should produce an error if it does. assert_eq!( @@ -147,7 +147,9 @@ fn main() { let bindings = Builder::default() .rustfmt_bindings(false) .enable_cxx_namespaces() - .rustified_enum(".*") + .default_enum_style(EnumVariation::Rust { + non_exhaustive: false, + }) .raw_line("pub use self::root::*;") .raw_line("extern { fn my_prefixed_function_to_remove(i: i32); }") .module_raw_line("root::testing", "pub type Bar = i32;") @@ -159,6 +161,8 @@ fn main() { seen_funcs: Mutex::new(0), })) .blacklist_function("my_prefixed_function_to_remove") + .constified_enum("my_prefixed_enum_to_be_constified") + .opaque_type("my_prefixed_templated_foo") .generate() .expect("Unable to generate bindings"); diff --git a/bindgen-integration/cpp/Test.cc b/bindgen-integration/cpp/Test.cc index c3d73411a3..240109bbe3 100644 --- a/bindgen-integration/cpp/Test.cc +++ b/bindgen-integration/cpp/Test.cc @@ -134,4 +134,4 @@ Seventh::assert(bool first, int my_prefixed_function_name() { return 4; -} \ No newline at end of file +} diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index f8b2263f6d..a9c5258c44 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -210,4 +210,21 @@ struct my_prefixed_foo { my_prefixed_bar member; }; +enum my_prefixed_enum_to_be_constified { + ONE = 1, + TWO, + THREE, +}; + +struct my_prefixed_baz { + char foo[30]; +}; + +template +struct my_prefixed_templated_foo { + T member; +}; + +my_prefixed_templated_foo TEMPLATED_CONST_VALUE; + void my_prefixed_function_to_remove(); diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 45cf9bca5d..0468f23773 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -245,6 +245,12 @@ fn test_item_rename() { }; } +#[test] +fn test_matching_with_rename() { + assert_eq!(bindings::enum_to_be_constified_THREE, 3); + assert_eq!(unsafe { bindings::TEMPLATED_CONST_VALUE.len() }, 30); +} + #[test] fn test_macro_customintkind_path() { let v: &std::any::Any = &bindings::TESTMACRO_CUSTOMINTKIND_PATH; diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 17996af65b..dde4bb1835 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -6,7 +6,6 @@ use super::item::Item; use super::ty::{Type, TypeKind}; use crate::clang; use crate::ir::annotations::Annotations; -use crate::ir::item::ItemCanonicalPath; use crate::parse::{ClangItemParser, ParseError}; use crate::regex_set::RegexSet; @@ -153,7 +152,7 @@ impl Enum { enums: &RegexSet, item: &Item, ) -> bool { - let path = item.canonical_path(ctx); + let path = item.path_for_whitelisting(ctx); let enum_ty = item.expect_type(); if enums.matches(&path[1..].join("::")) { diff --git a/src/ir/template.rs b/src/ir/template.rs index e2900e9579..8c625d1d92 100644 --- a/src/ir/template.rs +++ b/src/ir/template.rs @@ -28,7 +28,7 @@ //! ``` use super::context::{BindgenContext, ItemId, TypeId}; -use super::item::{IsOpaque, Item, ItemAncestors, ItemCanonicalPath}; +use super::item::{IsOpaque, Item, ItemAncestors}; use super::traversal::{EdgeKind, Trace, Tracer}; use crate::clang; use crate::parse::ClangItemParser; @@ -306,12 +306,13 @@ impl IsOpaque for TemplateInstantiation { // correct fix is to make `canonical_{name,path}` include template // arguments properly. - let mut path = item.canonical_path(ctx); + let mut path = item.path_for_whitelisting(ctx).clone(); let args: Vec<_> = self .template_arguments() .iter() .map(|arg| { - let arg_path = arg.canonical_path(ctx); + let arg_path = + ctx.resolve_item(*arg).path_for_whitelisting(ctx); arg_path[1..].join("::") }) .collect();