aboutsummaryrefslogtreecommitdiffstats
path: root/components/deny_public_fields/lib.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2017-02-14 17:35:39 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2017-02-15 10:24:01 +0100
commit8bcf36b9a59b4f30fd54fceb85eeb51b1d4dee4f (patch)
tree16f762e408981f2130095470fc4c7b868f9011c2 /components/deny_public_fields/lib.rs
parent19c645ff68f517929308d1f22728d72231e9a543 (diff)
downloadservo-8bcf36b9a59b4f30fd54fceb85eeb51b1d4dee4f.tar.gz
servo-8bcf36b9a59b4f30fd54fceb85eeb51b1d4dee4f.zip
Change #[privatize] into #[derive(DenyPublicFields)]
Diffstat (limited to 'components/deny_public_fields/lib.rs')
-rw-r--r--components/deny_public_fields/lib.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/components/deny_public_fields/lib.rs b/components/deny_public_fields/lib.rs
new file mode 100644
index 00000000000..a43db51e4af
--- /dev/null
+++ b/components/deny_public_fields/lib.rs
@@ -0,0 +1,26 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+extern crate proc_macro;
+extern crate syn;
+extern crate synstructure;
+
+#[proc_macro_derive(DenyPublicFields)]
+pub fn expand_token_stream(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ expand_string(&input.to_string()).parse().unwrap()
+}
+
+fn expand_string(input: &str) -> String {
+ let type_ = syn::parse_macro_input(input).unwrap();
+
+ let style = synstructure::BindStyle::Ref.into();
+ synstructure::each_field(&type_, &style, |binding| {
+ if binding.field.vis != syn::Visibility::Inherited {
+ panic!("Field {} should not be public", binding.ident);
+ }
+ "".to_owned()
+ });
+
+ "".to_owned()
+}