Skip to content

Commit 5744fe1

Browse files
committed
Revert: Make functional Option fns const
const fns with generic trait bounds aren't allowed yet; from @oli-obk: > please undo all constifications for functions that take generic things > with trait bounds (other than Sized), these require > rust-lang/rfcs#2632 first
1 parent 48c9f1e commit 5744fe1

File tree

2 files changed

+0
-176
lines changed

2 files changed

+0
-176
lines changed

src/libcore/option.rs

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -479,19 +479,6 @@ impl<T> Option<T> {
479479
/// assert_eq!(Some(4).unwrap_or_else(|| 2 * k), 4);
480480
/// assert_eq!(None.unwrap_or_else(|| 2 * k), 20);
481481
/// ```
482-
#[rustc_const_unstable(feature = "const_option_match")]
483-
#[cfg(not(bootstrap))]
484-
#[inline]
485-
#[stable(feature = "rust1", since = "1.0.0")]
486-
pub const fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
487-
match self {
488-
Some(x) => x,
489-
None => f(),
490-
}
491-
}
492-
493-
/// No docs for bootstrap.
494-
#[cfg(bootstrap)]
495482
#[inline]
496483
#[stable(feature = "rust1", since = "1.0.0")]
497484
pub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
@@ -521,19 +508,6 @@ impl<T> Option<T> {
521508
///
522509
/// assert_eq!(maybe_some_len, Some(13));
523510
/// ```
524-
#[rustc_const_unstable(feature = "const_option_match")]
525-
#[cfg(not(bootstrap))]
526-
#[inline]
527-
#[stable(feature = "rust1", since = "1.0.0")]
528-
pub const fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> {
529-
match self {
530-
Some(x) => Some(f(x)),
531-
None => None,
532-
}
533-
}
534-
535-
/// No docs for bootstrap.
536-
#[cfg(bootstrap)]
537511
#[inline]
538512
#[stable(feature = "rust1", since = "1.0.0")]
539513
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> {
@@ -555,19 +529,6 @@ impl<T> Option<T> {
555529
/// let x: Option<&str> = None;
556530
/// assert_eq!(x.map_or(42, |v| v.len()), 42);
557531
/// ```
558-
#[rustc_const_unstable(feature = "const_option_match")]
559-
#[cfg(not(bootstrap))]
560-
#[inline]
561-
#[stable(feature = "rust1", since = "1.0.0")]
562-
pub const fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U {
563-
match self {
564-
Some(t) => f(t),
565-
None => default,
566-
}
567-
}
568-
569-
/// No docs for bootstrap.
570-
#[cfg(bootstrap)]
571532
#[inline]
572533
#[stable(feature = "rust1", since = "1.0.0")]
573534
pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U {
@@ -591,19 +552,6 @@ impl<T> Option<T> {
591552
/// let x: Option<&str> = None;
592553
/// assert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 42);
593554
/// ```
594-
#[rustc_const_unstable(feature = "const_option_match")]
595-
#[cfg(not(bootstrap))]
596-
#[inline]
597-
#[stable(feature = "rust1", since = "1.0.0")]
598-
pub const fn map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>(self, default: D, f: F) -> U {
599-
match self {
600-
Some(t) => f(t),
601-
None => default(),
602-
}
603-
}
604-
605-
/// No docs for bootstrap.
606-
#[cfg(bootstrap)]
607555
#[inline]
608556
#[stable(feature = "rust1", since = "1.0.0")]
609557
pub fn map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>(self, default: D, f: F) -> U {
@@ -676,19 +624,6 @@ impl<T> Option<T> {
676624
/// let x: Option<&str> = None;
677625
/// assert_eq!(x.ok_or_else(|| 0), Err(0));
678626
/// ```
679-
#[rustc_const_unstable(feature = "const_option_match")]
680-
#[cfg(not(bootstrap))]
681-
#[inline]
682-
#[stable(feature = "rust1", since = "1.0.0")]
683-
pub const fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E> {
684-
match self {
685-
Some(v) => Ok(v),
686-
None => Err(err()),
687-
}
688-
}
689-
690-
/// No docs for bootstrap.
691-
#[cfg(bootstrap)]
692627
#[inline]
693628
#[stable(feature = "rust1", since = "1.0.0")]
694629
pub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E> {
@@ -807,19 +742,6 @@ impl<T> Option<T> {
807742
/// assert_eq!(Some(2).and_then(nope).and_then(sq), None);
808743
/// assert_eq!(None.and_then(sq).and_then(sq), None);
809744
/// ```
810-
#[rustc_const_unstable(feature = "const_option_match")]
811-
#[cfg(not(bootstrap))]
812-
#[inline]
813-
#[stable(feature = "rust1", since = "1.0.0")]
814-
pub const fn and_then<U, F: FnOnce(T) -> Option<U>>(self, f: F) -> Option<U> {
815-
match self {
816-
Some(x) => f(x),
817-
None => None,
818-
}
819-
}
820-
821-
/// No docs for bootstrap.
822-
#[cfg(bootstrap)]
823745
#[inline]
824746
#[stable(feature = "rust1", since = "1.0.0")]
825747
pub fn and_then<U, F: FnOnce(T) -> Option<U>>(self, f: F) -> Option<U> {
@@ -855,21 +777,6 @@ impl<T> Option<T> {
855777
/// [`None`]: #variant.None
856778
/// [`Some(t)`]: #variant.Some
857779
/// [`Iterator::filter()`]: ../../std/iter/trait.Iterator.html#method.filter
858-
#[rustc_const_unstable(feature = "const_option_match")]
859-
#[cfg(not(bootstrap))]
860-
#[inline]
861-
#[stable(feature = "option_filter", since = "1.27.0")]
862-
pub const fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
863-
if let Some(x) = self {
864-
if predicate(&x) {
865-
return Some(x);
866-
}
867-
}
868-
None
869-
}
870-
871-
/// No docs for bootstrap.
872-
#[cfg(bootstrap)]
873780
#[inline]
874781
#[stable(feature = "option_filter", since = "1.27.0")]
875782
pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
@@ -943,19 +850,6 @@ impl<T> Option<T> {
943850
/// assert_eq!(None.or_else(vikings), Some("vikings"));
944851
/// assert_eq!(None.or_else(nobody), None);
945852
/// ```
946-
#[rustc_const_unstable(feature = "const_option_match")]
947-
#[cfg(not(bootstrap))]
948-
#[inline]
949-
#[stable(feature = "rust1", since = "1.0.0")]
950-
pub const fn or_else<F: FnOnce() -> Option<T>>(self, f: F) -> Option<T> {
951-
match self {
952-
Some(_) => self,
953-
None => f(),
954-
}
955-
}
956-
957-
/// No docs for bootstrap.
958-
#[cfg(bootstrap)]
959853
#[inline]
960854
#[stable(feature = "rust1", since = "1.0.0")]
961855
pub fn or_else<F: FnOnce() -> Option<T>>(self, f: F) -> Option<T> {

src/test/ui/consts/const-option.rs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,6 @@ macro_rules! assert_same_const {
1212
}
1313
}
1414

15-
// These functions let us use the functional interfaces of Option (like unwrap_or_else, map_or,
16-
// map, etc.) without using closures, which aren't implemented in const contexts yet; see
17-
// https://github.com/rust-lang/rust/issues/63997
18-
19-
const fn is_zero(i: i32) -> bool {
20-
i == 0i32
21-
}
22-
23-
const fn get_zero() -> i32 {
24-
0
25-
}
26-
27-
const fn get_false() -> bool {
28-
false
29-
}
30-
31-
const fn get_some() -> Option<i32> {
32-
Some(2)
33-
}
34-
35-
const fn get_none() -> Option<i32> {
36-
None
37-
}
38-
39-
const fn is_pos(i: &i32) -> bool {
40-
i.is_positive()
41-
}
42-
43-
const fn is_neg(i: &i32) -> bool {
44-
i.is_negative()
45-
}
46-
47-
const fn i32_to_some(i: i32) -> Option<i32> {
48-
Some(i * 2)
49-
}
50-
51-
const fn i32_to_none(_i: i32) -> Option<i32> {
52-
None
53-
}
54-
5515
assert_same_const! {
5616
const SOME: Option<i32> = Some(3);
5717
const NONE: Option<i32> = None;
@@ -70,49 +30,19 @@ assert_same_const! {
7030
const UNWRAP_OR_A: i32 = SOME.unwrap_or(0);
7131
const UNWRAP_OR_B: i32 = NONE.unwrap_or(0);
7232

73-
const UNWRAP_OR_ELSE_A: i32 = SOME.unwrap_or_else(get_zero);
74-
const UNWRAP_OR_ELSE_B: i32 = NONE.unwrap_or_else(get_zero);
75-
76-
const MAP_A: Option<bool> = SOME.map(is_zero);
77-
const MAP_B: Option<bool> = NONE.map(is_zero);
78-
79-
const MAP_OR_A: bool = SOME.map_or(false, is_zero);
80-
const MAP_OR_B: bool = NONE.map_or(false, is_zero);
81-
82-
const MAP_OR_ELSE_A: bool = SOME.map_or_else(get_false, is_zero);
83-
const MAP_OR_ELSE_B: bool = NONE.map_or_else(get_false, is_zero);
84-
8533
const OK_OR_A: Result<i32, bool> = SOME.ok_or(false);
8634
const OK_OR_B: Result<i32, bool> = NONE.ok_or(false);
8735

88-
const OK_OR_ELSE_A: Result<i32, bool> = SOME.ok_or_else(get_false);
89-
const OK_OR_ELSE_B: Result<i32, bool> = NONE.ok_or_else(get_false);
90-
9136
const AND_A: Option<bool> = SOME.and(Some(true));
9237
const AND_B: Option<bool> = SOME.and(None);
9338
const AND_C: Option<bool> = NONE.and(Some(true));
9439
const AND_D: Option<bool> = NONE.and(None);
9540

96-
const AND_THEN_A: Option<i32> = SOME.and_then(i32_to_some);
97-
const AND_THEN_B: Option<i32> = SOME.and_then(i32_to_none);
98-
const AND_THEN_C: Option<i32> = NONE.and_then(i32_to_some);
99-
const AND_THEN_D: Option<i32> = NONE.and_then(i32_to_none);
100-
101-
const FILTER_A: Option<i32> = SOME.filter(is_pos);
102-
const FILTER_B: Option<i32> = SOME.filter(is_neg);
103-
const FILTER_C: Option<i32> = NONE.filter(is_pos);
104-
const FILTER_D: Option<i32> = NONE.filter(is_neg);
105-
10641
const OR_A: Option<i32> = SOME.or(Some(1));
10742
const OR_B: Option<i32> = SOME.or(None);
10843
const OR_C: Option<i32> = NONE.or(Some(1));
10944
const OR_D: Option<i32> = NONE.or(None);
11045

111-
const OR_ELSE_A: Option<i32> = SOME.or_else(get_some);
112-
const OR_ELSE_B: Option<i32> = SOME.or_else(get_none);
113-
const OR_ELSE_C: Option<i32> = NONE.or_else(get_some);
114-
const OR_ELSE_D: Option<i32> = NONE.or_else(get_none);
115-
11646
const XOR_A: Option<i32> = SOME.xor(Some(1));
11747
const XOR_B: Option<i32> = SOME.xor(None);
11848
const XOR_C: Option<i32> = NONE.xor(Some(1));

0 commit comments

Comments
 (0)