forked from rust-lang/rust-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use original name when checking allowlist for anonymous enum variants
- Loading branch information
Showing
5 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
|
||
pub const RENAMED_MyVal: ::std::os::raw::c_uint = 0; | ||
pub type _bindgen_ty_1 = ::std::os::raw::c_uint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// bindgen-flags: --allowlist-var ^MyVal$ | ||
// bindgen-parse-callbacks: enum-variant-rename | ||
|
||
enum { | ||
MyVal = 0, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
use bindgen::callbacks::ParseCallbacks; | ||
|
||
#[derive(Debug)] | ||
struct EnumVariantRename; | ||
|
||
impl ParseCallbacks for EnumVariantRename { | ||
fn enum_variant_name( | ||
&self, | ||
_enum_name: Option<&str>, | ||
original_variant_name: &str, | ||
_variant_value: bindgen::callbacks::EnumVariantValue, | ||
) -> Option<String> { | ||
Some(format!("RENAMED_{}", original_variant_name)) | ||
} | ||
} | ||
|
||
pub fn lookup(cb: &str) -> Box<dyn ParseCallbacks> { | ||
match cb { | ||
"enum-variant-rename" => Box::new(EnumVariantRename), | ||
_ => panic!("Couldn't find name ParseCallbacks: {}", cb), | ||
} | ||
} |