From e0ca63263c144ef41975c5440812c9c6cde2be91 Mon Sep 17 00:00:00 2001 From: Huxley Date: Tue, 7 Mar 2017 20:00:33 +0800 Subject: [PATCH] automatically allow non rust naming conventions --- src/codegen/helpers.rs | 4 ++++ src/codegen/mod.rs | 14 +++++++++++--- .../tests/duplicated-namespaces-definitions.rs | 1 + tests/expectations/tests/duplicated-namespaces.rs | 1 + .../tests/duplicated_constants_in_ns.rs | 1 + tests/expectations/tests/inline_namespace.rs | 1 + .../tests/inline_namespace_conservative.rs | 1 + .../tests/inline_namespace_whitelist.rs | 1 + tests/expectations/tests/issue-372.rs | 1 + tests/expectations/tests/issue-410.rs | 1 + tests/expectations/tests/issue-447.rs | 1 + tests/expectations/tests/issue_311.rs | 1 + tests/expectations/tests/module-whitelisted.rs | 1 + tests/expectations/tests/namespace.rs | 1 + .../expectations/tests/nested_within_namespace.rs | 1 + tests/expectations/tests/reparented_replacement.rs | 1 + tests/expectations/tests/struct_typedef_ns.rs | 1 + .../expectations/tests/template_alias_namespace.rs | 1 + tests/expectations/tests/union-in-ns.rs | 1 + .../tests/whitelist-namespaces-basic.rs | 1 + tests/expectations/tests/whitelist-namespaces.rs | 1 + 21 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs index 06dadab0c9..811d87c5ad 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -10,6 +10,10 @@ pub mod attributes { use aster; use syntax::ast; + pub fn allow(which_ones: &[&str]) -> ast::Attribute { + aster::AstBuilder::new().attr().list("allow").words(which_ones).build() + } + pub fn repr(which: &str) -> ast::Attribute { aster::AstBuilder::new().attr().list("repr").words(&[which]).build() } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 99324bc6ac..80319ac68d 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -403,10 +403,18 @@ impl CodeGenerator for Module { }); let name = item.canonical_name(ctx); - let item = aster::AstBuilder::new() + let item_builder = aster::AstBuilder::new() .item() - .pub_() - .build_item_kind(name, module); + .pub_(); + let item = if name == "root" { + let attrs = &["non_snake_case", + "non_camel_case_types", + "non_upper_case_globals"]; + item_builder.with_attr(attributes::allow(attrs)) + .build_item_kind(name, module) + } else { + item_builder.build_item_kind(name, module) + }; result.push(item); } diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index 196cfc46d1..faba454d2a 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/duplicated-namespaces.rs b/tests/expectations/tests/duplicated-namespaces.rs index 42976657ad..7416dad9d6 100644 --- a/tests/expectations/tests/duplicated-namespaces.rs +++ b/tests/expectations/tests/duplicated-namespaces.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/duplicated_constants_in_ns.rs b/tests/expectations/tests/duplicated_constants_in_ns.rs index 3721740c46..226765b645 100644 --- a/tests/expectations/tests/duplicated_constants_in_ns.rs +++ b/tests/expectations/tests/duplicated_constants_in_ns.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs index 8f2243ba2c..d62fb862f1 100644 --- a/tests/expectations/tests/inline_namespace.rs +++ b/tests/expectations/tests/inline_namespace.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs index 7cf7c26421..267f28cfa3 100644 --- a/tests/expectations/tests/inline_namespace_conservative.rs +++ b/tests/expectations/tests/inline_namespace_conservative.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/inline_namespace_whitelist.rs b/tests/expectations/tests/inline_namespace_whitelist.rs index d3a9d95855..d4a5aaff51 100644 --- a/tests/expectations/tests/inline_namespace_whitelist.rs +++ b/tests/expectations/tests/inline_namespace_whitelist.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index 1693f46a2d..3f4592f368 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs index 3c6cd2809d..1f624fec7b 100644 --- a/tests/expectations/tests/issue-410.rs +++ b/tests/expectations/tests/issue-410.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/issue-447.rs b/tests/expectations/tests/issue-447.rs index 7ac9d714ab..619a17b812 100644 --- a/tests/expectations/tests/issue-447.rs +++ b/tests/expectations/tests/issue-447.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/issue_311.rs b/tests/expectations/tests/issue_311.rs index 6576b8b5fb..0510f1c1f9 100644 --- a/tests/expectations/tests/issue_311.rs +++ b/tests/expectations/tests/issue_311.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/module-whitelisted.rs b/tests/expectations/tests/module-whitelisted.rs index cb6dd6a6c1..0f4d54b321 100644 --- a/tests/expectations/tests/module-whitelisted.rs +++ b/tests/expectations/tests/module-whitelisted.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index dda4cd2690..21b5a58b7a 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs index cb6eead35c..c51446573e 100644 --- a/tests/expectations/tests/nested_within_namespace.rs +++ b/tests/expectations/tests/nested_within_namespace.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index 6965f767d7..93cd3012c5 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index d7ada7fd1e..0f078e6ffb 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/template_alias_namespace.rs b/tests/expectations/tests/template_alias_namespace.rs index dd4add4083..90740a2d6f 100644 --- a/tests/expectations/tests/template_alias_namespace.rs +++ b/tests/expectations/tests/template_alias_namespace.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index 208b62832a..e5aeb3688b 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); diff --git a/tests/expectations/tests/whitelist-namespaces-basic.rs b/tests/expectations/tests/whitelist-namespaces-basic.rs index ba96895b62..6a1e90291f 100644 --- a/tests/expectations/tests/whitelist-namespaces-basic.rs +++ b/tests/expectations/tests/whitelist-namespaces-basic.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root; diff --git a/tests/expectations/tests/whitelist-namespaces.rs b/tests/expectations/tests/whitelist-namespaces.rs index 5e47c9d6bb..0c6cc4b694 100644 --- a/tests/expectations/tests/whitelist-namespaces.rs +++ b/tests/expectations/tests/whitelist-namespaces.rs @@ -4,6 +4,7 @@ #![allow(non_snake_case)] +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod root { #[allow(unused_imports)] use self::super::root;