Skip to content

Commit 5eaf31b

Browse files
committed
Simplyfied map_thin_attrs()
1 parent 8f3bc2c commit 5eaf31b

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

src/libsyntax/attr.rs

+3-19
Original file line numberDiff line numberDiff line change
@@ -751,25 +751,9 @@ pub trait ThinAttributesExt {
751751

752752
impl ThinAttributesExt for ThinAttributes {
753753
fn map_thin_attrs<F>(self, f: F) -> Self
754-
where F: FnOnce(Vec<Attribute>) -> Vec<Attribute> {
755-
756-
// This is kinda complicated... Ensure the function is
757-
// always called, and that None inputs or results are
758-
// correctly handled.
759-
if let Some(mut b) = self {
760-
use std::mem::replace;
761-
762-
let vec = replace(&mut *b, Vec::new());
763-
let vec = f(vec);
764-
if vec.len() == 0 {
765-
None
766-
} else {
767-
replace(&mut*b, vec);
768-
Some(b)
769-
}
770-
} else {
771-
f(Vec::new()).into_thin_attrs()
772-
}
754+
where F: FnOnce(Vec<Attribute>) -> Vec<Attribute>
755+
{
756+
f(self.map(|b| *b).unwrap_or(Vec::new())).into_thin_attrs()
773757
}
774758

775759
fn prepend(self, attrs: ThinAttributes) -> Self {

0 commit comments

Comments
 (0)