about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorMarvin Löbel <loebel.marvin@gmail.com>2015-11-30 21:12:26 +0100
committerMarvin Löbel <loebel.marvin@gmail.com>2015-11-30 21:12:26 +0100
commit5eaf31b7b2a1ffe892ac9fc14f49777cf64bb334 (patch)
treeeb52f4c4e692fe0915c285f09acd3fa5808b307f /src/libsyntax
parent8f3bc2c24e7ceb9a3b58b374e60c873127521c8d (diff)
downloadrust-5eaf31b7b2a1ffe892ac9fc14f49777cf64bb334.tar.gz
rust-5eaf31b7b2a1ffe892ac9fc14f49777cf64bb334.zip
Simplyfied map_thin_attrs()
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/attr.rs22
1 files changed, 3 insertions, 19 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index c2b2d00689f..e828d8ae248 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -751,25 +751,9 @@ pub trait ThinAttributesExt {
 
 impl ThinAttributesExt for ThinAttributes {
     fn map_thin_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_thin_attrs()
-        }
+        where F: FnOnce(Vec<Attribute>) -> Vec<Attribute>
+    {
+        f(self.map(|b| *b).unwrap_or(Vec::new())).into_thin_attrs()
     }
 
     fn prepend(self, attrs: ThinAttributes) -> Self {