From 5eaf31b7b2a1ffe892ac9fc14f49777cf64bb334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20L=C3=B6bel?= Date: Mon, 30 Nov 2015 21:12:26 +0100 Subject: [PATCH] Simplyfied map_thin_attrs() --- src/libsyntax/attr.rs | 22 +++------------------- 1 file 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(self, f: F) -> Self - where F: FnOnce(Vec) -> Vec { - - // 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) -> Vec + { + f(self.map(|b| *b).unwrap_or(Vec::new())).into_thin_attrs() } fn prepend(self, attrs: ThinAttributes) -> Self {