Skip to content

Commit 788b0cf

Browse files
committed
Use to_option in various places
1 parent 7131e80 commit 788b0cf

File tree

53 files changed

+82
-246
lines changed

Some content is hidden

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

53 files changed

+82
-246
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::*;
@@ -633,11 +634,7 @@ impl<'a> Parser<'a> {
633634
break;
634635
}
635636
}
636-
if found {
637-
Some(cur)
638-
} else {
639-
None
640-
}
637+
found.to_option(cur)
641638
}
642639
}
643640

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
@@ -305,11 +305,7 @@ impl<'tcx> Body<'tcx> {
305305
pub fn vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
306306
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
307307
let local = Local::new(index);
308-
if self.local_decls[local].is_user_variable.is_some() {
309-
Some(local)
310-
} else {
311-
None
312-
}
308+
self.local_decls[local].is_user_variable.is_some().to_option(local)
313309
})
314310
}
315311

src/librustc/session/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -825,11 +825,7 @@ impl Session {
825825
}
826826

827827
pub fn incr_comp_session_dir_opt(&self) -> Option<cell::Ref<'_, PathBuf>> {
828-
if self.opts.incremental.is_some() {
829-
Some(self.incr_comp_session_dir())
830-
} else {
831-
None
832-
}
828+
self.opts.incremental.is_some().to_option(self.incr_comp_session_dir())
833829
}
834830

835831
pub fn print_perf_stats(&self) {
@@ -1148,8 +1144,9 @@ fn build_session_(
11481144
None
11491145
}
11501146
}
1151-
}
1152-
else { None };
1147+
} else {
1148+
None
1149+
};
11531150

11541151
let host_triple = TargetTriple::from_triple(config::host_triple());
11551152
let host = Target::search(&host_triple).unwrap_or_else(|e|

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
340340
return None
341341
};
342342

343-
if tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented) {
344-
Some(impl_def_id)
345-
} else {
346-
None
347-
}
343+
tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented).to_option(impl_def_id)
348344
}
349345

350346
fn on_unimplemented_note(

src/librustc/ty/context.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,11 +1572,7 @@ impl<'tcx> TyCtxt<'tcx> {
15721572
ty::FnDef(_, _) => {
15731573
let sig = ret_ty.fn_sig(*self);
15741574
let output = self.erase_late_bound_regions(&sig.output());
1575-
if output.is_impl_trait() {
1576-
Some(output)
1577-
} else {
1578-
None
1579-
}
1575+
output.is_impl_trait().to_option(output)
15801576
}
15811577
_ => None
15821578
}

src/librustc/ty/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,11 +2824,7 @@ impl<'tcx> TyCtxt<'tcx> {
28242824
}
28252825
};
28262826

2827-
if is_associated_item {
2828-
Some(self.associated_item(def_id))
2829-
} else {
2830-
None
2831-
}
2827+
is_associated_item.to_option_with(|| self.associated_item(def_id))
28322828
}
28332829

28342830
fn associated_item_from_trait_item_ref(self,
@@ -3292,7 +3288,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ParamEnv<'_> {
32923288
let unnormalized_env = ty::ParamEnv::new(
32933289
tcx.intern_predicates(&predicates),
32943290
traits::Reveal::UserFacing,
3295-
if tcx.sess.opts.debugging_opts.chalk { Some(def_id) } else { None }
3291+
tcx.sess.opts.debugging_opts.chalk.to_option(def_id),
32963292
);
32973293

32983294
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
@@ -313,13 +313,8 @@ fn connected_to_root<'tcx>(
313313
return true;
314314
}
315315

316-
visit_waiters(query, |_, successor| {
317-
if connected_to_root(successor, visited) {
318-
Some(None)
319-
} else {
320-
None
321-
}
322-
}).is_some()
316+
visit_waiters(query, |_, successor| connected_to_root(successor, visited).to_option(None))
317+
.is_some()
323318
}
324319

325320
// Deterministically pick an query from a list

0 commit comments

Comments
 (0)