diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2018-07-24 16:43:49 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-24 16:43:49 -0600 |
| commit | c7a178ea5f84620508efbee96fb1da287c1a779d (patch) | |
| tree | aecd1021fb355e9f2d638b04712a308b3954a298 /src/libsyntax_ext | |
| parent | 28f8cb585aa4953864f64fdc58da9d4a2a34d6c0 (diff) | |
| parent | cbe5f1c4207673b9059e832ef2f134b4f87b380d (diff) | |
| download | rust-c7a178ea5f84620508efbee96fb1da287c1a779d.tar.gz rust-c7a178ea5f84620508efbee96fb1da287c1a779d.zip | |
Rollup merge of #52658 - Wallacoloo:topics/use-option-methods, r=cramertj
Prefer `Option::map`/etc over `match` wherever it improves clarity
This isn't intended to change behavior anywhere. A lot of times statements like `match x { None => None, Some(y) => [...] }` can be rewritten using `Option::map` or `Option::and_then` in a way that preserves or improves clarity, so that's what I've done here.
I think it's particularly valuable to keep things in `libcore` and `libstd` pretty/idiomatic since it's not uncommon to follow the `[src]` links when browsing the rust-lang.org docs for std/core. If there's any concern about pushing style-based changes though, I'll happily back out the non-std/core commits here.
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/ty.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index dcccb187bef..a0845e0982d 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -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> { |
