Skip to content

Commit 9f1269f

Browse files
committed
Rename to then_some and then
1 parent 8579fe6 commit 9f1269f

File tree

37 files changed

+57
-57
lines changed

37 files changed

+57
-57
lines changed

src/libcore/bool.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ impl bool {
99
/// ```
1010
/// #![feature(bool_to_option)]
1111
///
12-
/// assert_eq!(false.to_option(0), None);
13-
/// assert_eq!(true.to_option(0), Some(0));
12+
/// assert_eq!(false.then_some(0), None);
13+
/// assert_eq!(true.then_some(0), Some(0));
1414
/// ```
1515
#[unstable(feature = "bool_to_option", issue = "64260")]
1616
#[inline]
17-
pub fn to_option<T>(self, t: T) -> Option<T> {
17+
pub fn then_some<T>(self, t: T) -> Option<T> {
1818
if self {
1919
Some(t)
2020
} else {
@@ -29,12 +29,12 @@ impl bool {
2929
/// ```
3030
/// #![feature(bool_to_option)]
3131
///
32-
/// assert_eq!(false.to_option_with(|| 0), None);
33-
/// assert_eq!(true.to_option_with(|| 0), Some(0));
32+
/// assert_eq!(false.then(|| 0), None);
33+
/// assert_eq!(true.then(|| 0), Some(0));
3434
/// ```
3535
#[unstable(feature = "bool_to_option", issue = "64260")]
3636
#[inline]
37-
pub fn to_option_with<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
37+
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
3838
if self {
3939
Some(f())
4040
} else {

src/libcore/tests/bool.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[test]
22
fn test_bool_to_option() {
3-
assert_eq!(false.to_option(0), None);
4-
assert_eq!(true.to_option(0), Some(0));
5-
assert_eq!(false.to_option_with(|| 0), None);
6-
assert_eq!(true.to_option_with(|| 0), Some(0));
3+
assert_eq!(false.then_some(0), None);
4+
assert_eq!(true.then_some(0), Some(0));
5+
assert_eq!(false.then(|| 0), None);
6+
assert_eq!(true.then(|| 0), Some(0));
77
}

src/libfmt_macros/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl<'a> Parser<'a> {
645645
break;
646646
}
647647
}
648-
found.to_option(cur)
648+
found.then_some(cur)
649649
}
650650
}
651651

src/librustc/hir/map/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a> FnLikeNode<'a> {
147147
map::Node::Expr(e) => e.is_fn_like(),
148148
_ => false
149149
};
150-
fn_like.to_option(FnLikeNode { node })
150+
fn_like.then_some(FnLikeNode { node })
151151
}
152152

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

src/librustc/infer/outlives/verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
211211
(r, p)
212212
);
213213
let p_ty = p.to_ty(tcx);
214-
compare_ty(p_ty).to_option(ty::OutlivesPredicate(p_ty, r))
214+
compare_ty(p_ty).then_some(ty::OutlivesPredicate(p_ty, r))
215215
});
216216

217217
param_bounds

src/librustc/traits/error_reporting.rs

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

366-
tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented).to_option(impl_def_id)
366+
tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented).then_some(impl_def_id)
367367
}
368368

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

src/librustc/ty/mod.rs

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

2787-
is_associated_item.to_option_with(|| self.associated_item(def_id))
2787+
is_associated_item.then(|| self.associated_item(def_id))
27882788
}
27892789

27902790
fn associated_item_from_trait_item_ref(self,
@@ -3249,7 +3249,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ParamEnv<'_> {
32493249
let unnormalized_env = ty::ParamEnv::new(
32503250
tcx.intern_predicates(&predicates),
32513251
traits::Reveal::UserFacing,
3252-
tcx.sess.opts.debugging_opts.chalk.to_option(def_id),
3252+
tcx.sess.opts.debugging_opts.chalk.then_some(def_id),
32533253
);
32543254

32553255
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ fn connected_to_root<'tcx>(
303303
return true;
304304
}
305305

306-
visit_waiters(query, |_, successor| connected_to_root(successor, visited).to_option(None))
306+
visit_waiters(query, |_, successor| connected_to_root(successor, visited).then_some(None))
307307
.is_some()
308308
}
309309

src/librustc_codegen_llvm/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +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-
success.to_option(hi_lo_to_u128(lo, hi))
248+
success.then_some(hi_lo_to_u128(lo, hi))
249249
})
250250
}
251251

src/librustc_codegen_ssa/back/rpath.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn path_relative_from(path: &Path, base: &Path) -> Option<PathBuf> {
119119
use std::path::Component;
120120

121121
if path.is_absolute() != base.is_absolute() {
122-
path.is_absolute().to_option_with(|| PathBuf::from(path))
122+
path.is_absolute().then(|| PathBuf::from(path))
123123
} else {
124124
let mut ita = path.components();
125125
let mut itb = base.components();

0 commit comments

Comments
 (0)