Use to_option in various places

This commit is contained in:
varkor 2019-10-08 01:14:42 +01:00
parent 51901eea8c
commit e3a8ea4e18
51 changed files with 81 additions and 236 deletions

View file

@ -147,13 +147,7 @@ impl<'a> FnLikeNode<'a> {
map::Node::Expr(e) => e.is_fn_like(),
_ => false
};
if fn_like {
Some(FnLikeNode {
node,
})
} else {
None
}
fn_like.to_option(FnLikeNode { node })
}
pub fn body(self) -> ast::BodyId {

View file

@ -211,11 +211,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
(r, p)
);
let p_ty = p.to_ty(tcx);
if compare_ty(p_ty) {
Some(ty::OutlivesPredicate(p_ty, r))
} else {
None
}
compare_ty(p_ty).to_option(ty::OutlivesPredicate(p_ty, r))
});
param_bounds

View file

@ -29,6 +29,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(arbitrary_self_types)]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(const_fn)]

View file

@ -242,11 +242,7 @@ impl<'tcx> Body<'tcx> {
pub fn vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index);
if self.local_decls[local].is_user_variable() {
Some(local)
} else {
None
}
self.local_decls[local].is_user_variable().to_option(local)
})
}

View file

@ -363,11 +363,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
return None
};
if tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented) {
Some(impl_def_id)
} else {
None
}
tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented).to_option(impl_def_id)
}
fn describe_generator(&self, body_id: hir::BodyId) -> Option<&'static str> {

View file

@ -2784,11 +2784,7 @@ impl<'tcx> TyCtxt<'tcx> {
}
};
if is_associated_item {
Some(self.associated_item(def_id))
} else {
None
}
is_associated_item.to_option_with(|| self.associated_item(def_id))
}
fn associated_item_from_trait_item_ref(self,
@ -3253,7 +3249,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ParamEnv<'_> {
let unnormalized_env = ty::ParamEnv::new(
tcx.intern_predicates(&predicates),
traits::Reveal::UserFacing,
if tcx.sess.opts.debugging_opts.chalk { Some(def_id) } else { None }
tcx.sess.opts.debugging_opts.chalk.to_option(def_id),
);
let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| {

View file

@ -303,13 +303,8 @@ fn connected_to_root<'tcx>(
return true;
}
visit_waiters(query, |_, successor| {
if connected_to_root(successor, visited) {
Some(None)
} else {
None
}
}).is_some()
visit_waiters(query, |_, successor| connected_to_root(successor, visited).to_option(None))
.is_some()
}
// Deterministically pick an query from a list