Skip to content

Commit

Permalink
librustc: Prefer Option::map/etc 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 727bd7d commit 10d8213
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
9 changes: 4 additions & 5 deletions src/librustc/traits/on_unimplemented.rs
Expand Up @@ -190,11 +190,10 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
for command in self.subcommands.iter().chain(Some(self)).rev() {
if let Some(ref condition) = command.condition {
if !attr::eval_condition(condition, &tcx.sess.parse_sess, &mut |c| {
options.contains(&(c.name().as_str().to_string(),
match c.value_str().map(|s| s.as_str().to_string()) {
Some(s) => Some(s),
None => None
}))
options.contains(&(
c.name().as_str().to_string(),
c.value_str().map(|s| s.as_str().to_string())
))
}) {
debug!("evaluate: skipping {:?} due to condition", command);
continue
Expand Down
13 changes: 5 additions & 8 deletions src/librustc/ty/mod.rs
Expand Up @@ -2697,15 +2697,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.opt_associated_item(def_id)
};

match item {
Some(trait_item) => {
match trait_item.container {
TraitContainer(_) => None,
ImplContainer(def_id) => Some(def_id),
}
item.and_then(|trait_item|
match trait_item.container {
TraitContainer(_) => None,
ImplContainer(def_id) => Some(def_id),
}
None => None
}
)
}

/// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err`
Expand Down
17 changes: 7 additions & 10 deletions src/librustc_metadata/locator.rs
Expand Up @@ -824,17 +824,14 @@ impl<'a> Context<'a> {
if rlib.is_none() && rmeta.is_none() && dylib.is_none() {
return None;
}
match slot {
Some((_, metadata)) => {
Some(Library {
dylib,
rlib,
rmeta,
metadata,
})
slot.map(|(_, metadata)|
Library {
dylib,
rlib,
rmeta,
metadata,
}
None => None,
}
)
}
}

Expand Down

0 comments on commit 10d8213

Please sign in to comment.