Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3f2a1c9
Use `OutputFilenames` to generate output file for `-Zllvm-time-trace`
tmiasko Dec 13, 2021
7f2f9c6
Iterator::cycle() — document empty iterator special case
xkr47 Dec 13, 2021
715c562
[ReviewFix] Linguistics
xkr47 Dec 13, 2021
0c594f8
Remove in_band_lifetimes from borrowck
bugadani Dec 13, 2021
ae21dd0
Remove in_band_lifetimes
Patrick-Poitras Dec 14, 2021
4e38807
core: minor `Option` doc correction
euclio Dec 14, 2021
7175980
awdawdawd
BoxyUwU Dec 13, 2021
0a0f014
test
BoxyUwU Dec 13, 2021
b682dec
Remove `in_band_lifetimes` from `rustc_symbol_mangling`
Dec 14, 2021
1ea756b
Remove `in_band_lifetimes` from `rustc_trait_selection`
Dec 14, 2021
90aa8fb
made compiler happy
lameferret Dec 14, 2021
a586e7d
Make suggestions from @jackh726; run fmt
Patrick-Poitras Dec 14, 2021
f0c0732
Add another regression test for unnormalized fn args with Self
jackh726 Dec 14, 2021
a957cef
Fix a bunch of typos
steffahn Dec 14, 2021
4f4b2c7
Constify `bool::then{,_some}`
fee1-dead Dec 14, 2021
4d1d66b
Use `tcx.def_path_hash` in `ExistentialPredicate.stable_cmp`
Aaron1011 Dec 14, 2021
f194c9b
Recover on invalid operators <> and <=>
Dec 6, 2021
462bb57
Remove `in_band_lifetimes` from `rustc_codegen_llvm`
LegionMammal978 Dec 14, 2021
49a339b
Rollup merge of #91597 - r00ster91:lessthangreaterthan, r=oli-obk
matthiaskrgr Dec 14, 2021
0cb5076
Rollup merge of #91859 - xkr47:patch-2, r=yaahc
matthiaskrgr Dec 14, 2021
dfc8576
Rollup merge of #91868 - tmiasko:llvm-time-trace-out, r=oli-obk
matthiaskrgr Dec 14, 2021
cee897c
Rollup merge of #91879 - bugadani:in_band_borrowck, r=wesleywiser
matthiaskrgr Dec 14, 2021
8564939
Rollup merge of #91882 - Patrick-Poitras:remove-in-band-lifetimes-fro…
matthiaskrgr Dec 14, 2021
fc43d98
Rollup merge of #91886 - euclio:option-doc, r=dtolnay
matthiaskrgr Dec 14, 2021
50ab166
Rollup merge of #91888 - BoxyUwU:generic_arg_infer_aaaa, r=lcnr
matthiaskrgr Dec 14, 2021
2e3b295
Rollup merge of #91901 - SylvanB:remove_in_band_lifetimes_rustc_symbo…
matthiaskrgr Dec 14, 2021
5256e65
Rollup merge of #91904 - SylvanB:remove_in_band_lifetimes_rustc_trait…
matthiaskrgr Dec 14, 2021
719eb55
Rollup merge of #91906 - anuvratsingh:remove_in_band_lifetimes_librar…
matthiaskrgr Dec 14, 2021
9a08578
Rollup merge of #91915 - jackh726:issue-91899, r=Mark-Simulacrum
matthiaskrgr Dec 14, 2021
4a69329
Rollup merge of #91916 - steffahn:fix-typos, r=dtolnay
matthiaskrgr Dec 14, 2021
4ce965f
Rollup merge of #91918 - fee1-dead:constification0-the-great-constifi…
matthiaskrgr Dec 14, 2021
68c5cd2
Rollup merge of #91920 - Aaron1011:pred-stable-cmp, r=oli-obk
matthiaskrgr Dec 14, 2021
71b2c82
Rollup merge of #91931 - LegionMammal978:less-inband-codegen_llvm, r=…
matthiaskrgr Dec 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Constify bool::then{,_some}
  • Loading branch information
fee1-dead committed Dec 14, 2021
commit 4f4b2c7271d3090b6b63bf1ce8373a47b5b30d86
13 changes: 11 additions & 2 deletions library/core/src/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ impl bool {
/// assert_eq!(true.then_some(0), Some(0));
/// ```
#[unstable(feature = "bool_to_option", issue = "80967")]
#[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
#[inline]
pub fn then_some<T>(self, t: T) -> Option<T> {
pub const fn then_some<T>(self, t: T) -> Option<T>
where
T: ~const Drop,
{
if self { Some(t) } else { None }
}

Expand All @@ -29,8 +33,13 @@ impl bool {
/// assert_eq!(true.then(|| 0), Some(0));
/// ```
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
#[rustc_const_unstable(feature = "const_bool_to_option", issue = "91917")]
#[inline]
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
pub const fn then<T, F>(self, f: F) -> Option<T>
where
F: ~const FnOnce() -> T,
F: ~const Drop,
{
if self { Some(f()) } else { None }
}
}
14 changes: 14 additions & 0 deletions library/core/tests/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,18 @@ fn test_bool_to_option() {
assert_eq!(true.then_some(0), Some(0));
assert_eq!(false.then(|| 0), None);
assert_eq!(true.then(|| 0), Some(0));

const fn zero() -> i32 {
0
}

const A: Option<i32> = false.then_some(0);
const B: Option<i32> = true.then_some(0);
const C: Option<i32> = false.then(zero);
const D: Option<i32> = true.then(zero);

assert_eq!(A, None);
assert_eq!(B, Some(0));
assert_eq!(C, None);
assert_eq!(D, Some(0));
}
1 change: 1 addition & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![feature(cfg_panic)]
#![feature(cfg_target_has_atomic)]
#![feature(const_assume)]
#![feature(const_bool_to_option)]
#![feature(const_cell_into_inner)]
#![feature(const_convert)]
#![feature(const_maybe_uninit_as_mut_ptr)]
Expand Down