Skip to content

Commit e3a8ea4

Browse files
committed
Use to_option in various places
1 parent 51901ee commit e3a8ea4

File tree

51 files changed

+81
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+81
-236
lines changed

src/libfmt_macros/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![feature(nll)]
1212
#![feature(rustc_private)]
1313
#![feature(unicode_internals)]
14+
#![feature(bool_to_option)]
1415

1516
pub use Piece::*;
1617
pub use Position::*;
@@ -644,11 +645,7 @@ impl<'a> Parser<'a> {
644645
break;
645646
}
646647
}
647-
if found {
648-
Some(cur)
649-
} else {
650-
None
651-
}
648+
found.to_option(cur)
652649
}
653650
}
654651

src/librustc/hir/map/blocks.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,7 @@ impl<'a> FnLikeNode<'a> {
147147
map::Node::Expr(e) => e.is_fn_like(),
148148
_ => false
149149
};
150-
if fn_like {
151-
Some(FnLikeNode {
152-
node,
153-
})
154-
} else {
155-
None
156-
}
150+
fn_like.to_option(FnLikeNode { node })
157151
}
158152

159153
pub fn body(self) -> ast::BodyId {

src/librustc/infer/outlives/verify.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
211211
(r, p)
212212
);
213213
let p_ty = p.to_ty(tcx);
214-
if compare_ty(p_ty) {
215-
Some(ty::OutlivesPredicate(p_ty, r))
216-
} else {
217-
None
218-
}
214+
compare_ty(p_ty).to_option(ty::OutlivesPredicate(p_ty, r))
219215
});
220216

221217
param_bounds

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
3030

3131
#![feature(arbitrary_self_types)]
32+
#![feature(bool_to_option)]
3233
#![feature(box_patterns)]
3334
#![feature(box_syntax)]
3435
#![feature(const_fn)]

src/librustc/mir/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,7 @@ impl<'tcx> Body<'tcx> {
242242
pub fn vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
243243
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
244244
let local = Local::new(index);
245-
if self.local_decls[local].is_user_variable() {
246-
Some(local)
247-
} else {
248-
None
249-
}
245+
self.local_decls[local].is_user_variable().to_option(local)
250246
})
251247
}
252248

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
363363
return None
364364
};
365365

366-
if tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented) {
367-
Some(impl_def_id)
368-
} else {
369-
None
370-
}
366+
tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented).to_option(impl_def_id)
371367
}
372368

373369
fn describe_generator(&self, body_id: hir::BodyId) -> Option<&'static str> {

src/librustc/ty/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,11 +2784,7 @@ impl<'tcx> TyCtxt<'tcx> {
27842784
}
27852785
};
27862786

2787-
if is_associated_item {
2788-
Some(self.associated_item(def_id))
2789-
} else {
2790-
None
2791-
}
2787+
is_associated_item.to_option_with(|| self.associated_item(def_id))
27922788
}
27932789

27942790
fn associated_item_from_trait_item_ref(self,
@@ -3253,7 +3249,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ParamEnv<'_> {
32533249
let unnormalized_env = ty::ParamEnv::new(
32543250
tcx.intern_predicates(&predicates),
32553251
traits::Reveal::UserFacing,
3256-
if tcx.sess.opts.debugging_opts.chalk { Some(def_id) } else { None }
3252+
tcx.sess.opts.debugging_opts.chalk.to_option(def_id),
32573253
);
32583254

32593255
let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| {

src/librustc/ty/query/job.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,8 @@ fn connected_to_root<'tcx>(
303303
return true;
304304
}
305305

306-
visit_waiters(query, |_, successor| {
307-
if connected_to_root(successor, visited) {
308-
Some(None)
309-
} else {
310-
None
311-
}
312-
}).is_some()
306+
visit_waiters(query, |_, successor| connected_to_root(successor, visited).to_option(None))
307+
.is_some()
313308
}
314309

315310
// Deterministically pick an query from a list

src/librustc_codegen_llvm/attributes.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,7 @@ pub fn provide_extern(providers: &mut Providers<'_>) {
375375
let native_libs = tcx.native_libraries(cnum);
376376

377377
let def_id_to_native_lib = native_libs.iter().filter_map(|lib|
378-
if let Some(id) = lib.foreign_module {
379-
Some((id, lib))
380-
} else {
381-
None
382-
}
378+
lib.foreign_module.map(|id| (id, lib))
383379
).collect::<FxHashMap<_, _>>();
384380

385381
let mut ret = FxHashMap::default();

src/librustc_codegen_llvm/common.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
245245
let (mut lo, mut hi) = (0u64, 0u64);
246246
let success = llvm::LLVMRustConstInt128Get(v, sign_ext,
247247
&mut hi, &mut lo);
248-
if success {
249-
Some(hi_lo_to_u128(lo, hi))
250-
} else {
251-
None
252-
}
248+
success.to_option(hi_lo_to_u128(lo, hi))
253249
})
254250
}
255251

0 commit comments

Comments
 (0)