Skip to content

Commit 10d8213

Browse files
committed
librustc: Prefer Option::map/etc over match where applicable
1 parent 727bd7d commit 10d8213

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

src/librustc/traits/on_unimplemented.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,10 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
190190
for command in self.subcommands.iter().chain(Some(self)).rev() {
191191
if let Some(ref condition) = command.condition {
192192
if !attr::eval_condition(condition, &tcx.sess.parse_sess, &mut |c| {
193-
options.contains(&(c.name().as_str().to_string(),
194-
match c.value_str().map(|s| s.as_str().to_string()) {
195-
Some(s) => Some(s),
196-
None => None
197-
}))
193+
options.contains(&(
194+
c.name().as_str().to_string(),
195+
c.value_str().map(|s| s.as_str().to_string())
196+
))
198197
}) {
199198
debug!("evaluate: skipping {:?} due to condition", command);
200199
continue

src/librustc/ty/mod.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -2697,15 +2697,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26972697
self.opt_associated_item(def_id)
26982698
};
26992699

2700-
match item {
2701-
Some(trait_item) => {
2702-
match trait_item.container {
2703-
TraitContainer(_) => None,
2704-
ImplContainer(def_id) => Some(def_id),
2705-
}
2700+
item.and_then(|trait_item|
2701+
match trait_item.container {
2702+
TraitContainer(_) => None,
2703+
ImplContainer(def_id) => Some(def_id),
27062704
}
2707-
None => None
2708-
}
2705+
)
27092706
}
27102707

27112708
/// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err`

src/librustc_metadata/locator.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -824,17 +824,14 @@ impl<'a> Context<'a> {
824824
if rlib.is_none() && rmeta.is_none() && dylib.is_none() {
825825
return None;
826826
}
827-
match slot {
828-
Some((_, metadata)) => {
829-
Some(Library {
830-
dylib,
831-
rlib,
832-
rmeta,
833-
metadata,
834-
})
827+
slot.map(|(_, metadata)|
828+
Library {
829+
dylib,
830+
rlib,
831+
rmeta,
832+
metadata,
835833
}
836-
None => None,
837-
}
834+
)
838835
}
839836
}
840837

0 commit comments

Comments
 (0)