Skip to content

Commit

Permalink
use question mark operator in a few places.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskrgr committed Mar 1, 2020
1 parent beac68a commit a0db435
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 18 deletions.
8 changes: 2 additions & 6 deletions src/libcore/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1894,9 +1894,7 @@ where
let to_skip = self.n;
self.n = 0;
// nth(n) skips n+1
if self.iter.nth(to_skip - 1).is_none() {
return None;
}
self.iter.nth(to_skip - 1)?;
}
self.iter.nth(n)
}
Expand All @@ -1916,9 +1914,7 @@ where
fn last(mut self) -> Option<I::Item> {
if self.n > 0 {
// nth(n) skips n+1
if self.iter.nth(self.n - 1).is_none() {
return None;
}
self.iter.nth(self.n - 1)?;
}
self.iter.last()
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ impl<'hir> Map<'hir> {
Node::Variant(_) => DefKind::Variant,
Node::Ctor(variant_data) => {
// FIXME(eddyb) is this even possible, if we have a `Node::Ctor`?
if variant_data.ctor_hir_id().is_none() {
return None;
}
variant_data.ctor_hir_id()?;

let ctor_of = match self.find(self.get_parent_node(hir_id)) {
Some(Node::Item(..)) => def::CtorOf::Struct,
Some(Node::Variant(..)) => def::CtorOf::Variant,
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ impl<'tcx> Instance<'tcx> {
}

// If this a non-generic instance, it cannot be a shared monomorphization.
if self.substs.non_erasable_generics().next().is_none() {
return None;
}
self.substs.non_erasable_generics().next()?;

match self.def {
InstanceDef::Item(def_id) => tcx
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_incremental/persist/work_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
files: &[(WorkProductFileKind, PathBuf)],
) -> Option<(WorkProductId, WorkProduct)> {
debug!("copy_cgu_workproducts_to_incr_comp_cache_dir({:?},{:?})", cgu_name, files);
if sess.opts.incremental.is_none() {
return None;
}
sess.opts.incremental.as_ref()?;

let saved_files = files
.iter()
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_traits/chalk_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ impl context::AggregateOps<ChalkArenas<'tcx>> for ChalkContext<'tcx> {

debug!("make_solution(root_goal = {:?})", root_goal);

if simplified_answers.peek_answer().is_none() {
return None;
}
simplified_answers.peek_answer()?;

let SimplifiedAnswer { subst: constrained_subst, ambiguous } =
simplified_answers.next_answer().unwrap();
Expand Down

0 comments on commit a0db435

Please sign in to comment.