Skip to content

Commit

Permalink
libsyntax_ext: Prefer Option::map over match where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
Wallacoloo committed Jul 24, 2018
1 parent 10d8213 commit cbe5f1c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/libsyntax_ext/deriving/generic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,13 @@ pub fn nil_ty<'r>() -> Ty<'r> {
}

fn mk_lifetime(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
match *lt {
Some(s) => Some(cx.lifetime(span, Ident::from_str(s))),
None => None,
}
lt.map(|s|
cx.lifetime(span, Ident::from_str(s))
)
}

fn mk_lifetimes(cx: &ExtCtxt, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> {
match *lt {
Some(s) => vec![cx.lifetime(span, Ident::from_str(s))],
None => vec![],
}
mk_lifetime(cx, span, lt).into_iter().collect()
}

impl<'a> Ty<'a> {
Expand Down

0 comments on commit cbe5f1c

Please sign in to comment.