summary refs log tree commit diff
path: root/src/libsyntax/ast.rs
diff options
context:
space:
mode:
authorMarvin Löbel <loebel.marvin@gmail.com>2015-11-15 17:17:50 +0100
committerMarvin Löbel <loebel.marvin@gmail.com>2015-11-26 21:46:12 +0100
commitf0beba0217ad4ac748e93f7ea8d16c3b1fc4db1d (patch)
tree2a4fd2d32a7e5c6a3943ca3fae4c967fe58b5e4c /src/libsyntax/ast.rs
parent2a8f358de7ee71934b8129dff5d908730454d7b1 (diff)
downloadrust-f0beba0217ad4ac748e93f7ea8d16c3b1fc4db1d.tar.gz
rust-f0beba0217ad4ac748e93f7ea8d16c3b1fc4db1d.zip
Moved and refactored ThinAttributes
Diffstat (limited to 'src/libsyntax/ast.rs')
-rw-r--r--src/libsyntax/ast.rs93
1 files changed, 1 insertions, 92 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 48c5be8e07e..f11291fc0f7 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -45,6 +45,7 @@ pub use self::ViewPath_::*;
 pub use self::Visibility::*;
 pub use self::PathParameters::*;
 
+use attr::ThinAttributes;
 use codemap::{Span, Spanned, DUMMY_SP, ExpnId};
 use abi::Abi;
 use ast_util;
@@ -1952,98 +1953,6 @@ pub struct MacroDef {
     pub body: Vec<TokenTree>,
 }
 
-/// A list of attributes, behind a optional box as
-/// a space optimization.
-pub type ThinAttributes = Option<Box<Vec<Attribute>>>;
-
-pub trait ThinAttributesExt {
-    fn map_opt_attrs<F>(self, f: F) -> Self
-        where F: FnOnce(Vec<Attribute>) -> Vec<Attribute>;
-    fn prepend_outer(mut self, attrs: Self) -> Self;
-    fn append_inner(mut self, attrs: Self) -> Self;
-    fn update<F>(&mut self, f: F)
-        where Self: Sized,
-              F: FnOnce(Self) -> Self;
-    fn as_attrs(&self) -> &[Attribute];
-    fn into_attrs(self) -> Vec<Attribute>;
-}
-
-// FIXME: Rename inner/outer
-// FIXME: Rename opt_attrs
-
-impl ThinAttributesExt for ThinAttributes {
-    fn map_opt_attrs<F>(self, f: F) -> Self
-        where F: FnOnce(Vec<Attribute>) -> Vec<Attribute> {
-
-        // This is kinda complicated... Ensure the function is
-        // always called, and that None inputs or results are
-        // correctly handled.
-        if let Some(mut b) = self {
-            use std::mem::replace;
-
-            let vec = replace(&mut *b, Vec::new());
-            let vec = f(vec);
-            if vec.len() == 0 {
-                None
-            } else {
-                replace(&mut*b, vec);
-                Some(b)
-            }
-        } else {
-            f(Vec::new()).into_opt_attrs()
-        }
-    }
-
-    fn prepend_outer(self, attrs: ThinAttributes) -> Self {
-        attrs.map_opt_attrs(|mut attrs| {
-            attrs.extend(self.into_attrs());
-            attrs
-        })
-    }
-
-    fn append_inner(self, attrs: ThinAttributes) -> Self {
-        self.map_opt_attrs(|mut self_| {
-            self_.extend(attrs.into_attrs());
-            self_
-        })
-    }
-
-    fn update<F>(&mut self, f: F)
-        where Self: Sized,
-              F: FnOnce(ThinAttributes) -> ThinAttributes
-    {
-        let self_ = f(self.take());
-        *self = self_;
-    }
-
-    fn as_attrs(&self) -> &[Attribute] {
-        match *self {
-            Some(ref b) => b,
-            None => &[],
-        }
-    }
-
-    fn into_attrs(self) -> Vec<Attribute> {
-        match self {
-            Some(b) => *b,
-            None => Vec::new(),
-        }
-    }
-}
-
-pub trait AttributesExt {
-    fn into_opt_attrs(self) -> ThinAttributes;
-}
-impl AttributesExt for Vec<Attribute> {
-    fn into_opt_attrs(self) -> ThinAttributes {
-        if self.len() == 0 {
-            None
-        } else {
-            Some(Box::new(self))
-        }
-    }
-}
-
 #[cfg(test)]
 mod tests {
     use serialize;