Skip to content

Commit c977b87

Browse files
committed
Auto merge of #72437 - ecstatic-morse:stabilize-const-if-match, r=oli-obk
Stabilize `#![feature(const_if_match)]` Quoting from the [stabilization report](#49146 (comment)): > `if` and `match` expressions as well as the short-circuiting logic operators `&&` and `||` will become legal in all [const contexts](https://doc.rust-lang.org/reference/const_eval.html#const-context). A const context is any of the following: > > - The initializer of a `const`, `static`, `static mut` or enum discriminant. > - The body of a `const fn`. > - The value of a const generic (nightly only). > - The length of an array type (`[u8; 3]`) or an array repeat expression (`[0u8; 3]`). > > Furthermore, the short-circuiting logic operators will no longer be lowered to their bitwise equivalents (`&` and `|` respectively) in `const` and `static` initializers (see #57175). As a result, `let` bindings can be used alongside short-circuiting logic in those initializers. Resolves #49146. Ideally, we would resolve 🐳 #66753 before this lands on stable, so it might be worth pushing this back a release. Also, this means we should get the process started for #52000, otherwise people will have no recourse except recursion for iterative `const fn`. r? @oli-obk
2 parents 2f517ce + 8509b69 commit c977b87

File tree

129 files changed

+348
-1757
lines changed

Some content is hidden

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

129 files changed

+348
-1757
lines changed

src/doc/unstable-book/src/language-features/const-if-match.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/liballoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
#![feature(const_generic_impls_guard)]
8888
#![feature(const_generics)]
8989
#![feature(const_in_array_repeat_expressions)]
90-
#![feature(const_if_match)]
90+
#![cfg_attr(bootstrap, feature(const_if_match))]
9191
#![feature(cow_is_borrowed)]
9292
#![feature(dispatch_from_dyn)]
9393
#![feature(core_intrinsics)]

src/libcore/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
#![feature(const_ascii_ctype_on_intrinsics)]
7474
#![feature(const_alloc_layout)]
7575
#![feature(const_discriminant)]
76-
#![feature(const_if_match)]
77-
#![feature(const_loop)]
76+
#![cfg_attr(bootstrap, feature(const_if_match))]
77+
#![cfg_attr(bootstrap, feature(const_loop))]
7878
#![feature(const_checked_int_methods)]
7979
#![feature(const_euclidean_int_methods)]
8080
#![feature(const_overflowing_int_methods)]

src/libcore/num/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ $EndFeature, "
15781578
#[stable(feature = "no_panic_abs", since = "1.13.0")]
15791579
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
15801580
#[allow(unused_attributes)]
1581-
#[allow_internal_unstable(const_if_match)]
1581+
#[cfg_attr(bootstrap, allow_internal_unstable(const_if_match))]
15821582
#[inline]
15831583
pub const fn wrapping_abs(self) -> Self {
15841584
if self.is_negative() {
@@ -1867,7 +1867,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($Self
18671867
#[stable(feature = "wrapping", since = "1.7.0")]
18681868
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
18691869
#[allow(unused_attributes)]
1870-
#[allow_internal_unstable(const_if_match)]
1870+
#[cfg_attr(bootstrap, allow_internal_unstable(const_if_match))]
18711871
pub const fn overflowing_neg(self) -> (Self, bool) {
18721872
if self == Self::MIN {
18731873
(Self::MIN, true)
@@ -2160,7 +2160,7 @@ $EndFeature, "
21602160
#[stable(feature = "rust1", since = "1.0.0")]
21612161
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
21622162
#[allow(unused_attributes)]
2163-
#[allow_internal_unstable(const_if_match)]
2163+
#[cfg_attr(bootstrap, allow_internal_unstable(const_if_match))]
21642164
#[inline]
21652165
#[rustc_inherit_overflow_checks]
21662166
pub const fn abs(self) -> Self {

src/librustc_ast/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))]
88
#![feature(bool_to_option)]
99
#![feature(box_syntax)]
10-
#![feature(const_if_match)]
10+
#![cfg_attr(bootstrap, feature(const_if_match))]
1111
#![feature(const_fn)] // For the `transmute` in `P::new`
1212
#![feature(const_panic)]
1313
#![feature(const_transmute)]

src/librustc_feature/accepted.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ declare_features! (
261261
(accepted, transparent_enums, "1.42.0", Some(60405), None),
262262
/// Allows using subslice patterns, `[a, .., b]` and `[a, xs @ .., b]`.
263263
(accepted, slice_patterns, "1.42.0", Some(62254), None),
264+
/// Allows the use of `if` and `match` in constants.
265+
(accepted, const_if_match, "1.45.0", Some(49146), None),
266+
/// Allows the use of `loop` and `while` in constants.
267+
(accepted, const_loop, "1.45.0", Some(52000), None),
264268

265269
// -------------------------------------------------------------------------
266270
// feature-group-end: accepted features

src/librustc_feature/active.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,6 @@ declare_features! (
518518
/// Allows using the `#[register_tool]` attribute.
519519
(active, register_tool, "1.41.0", Some(66079), None),
520520

521-
/// Allows the use of `if` and `match` in constants.
522-
(active, const_if_match, "1.41.0", Some(49146), None),
523-
524521
/// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used.
525522
(active, cfg_sanitize, "1.41.0", Some(39699), None),
526523

@@ -530,9 +527,6 @@ declare_features! (
530527
/// Allows using `&mut` in constant functions.
531528
(active, const_mut_refs, "1.41.0", Some(57349), None),
532529

533-
/// Allows the use of `loop` and `while` in constants.
534-
(active, const_loop, "1.41.0", Some(52000), None),
535-
536530
/// Allows bindings in the subpattern of a binding pattern.
537531
/// For example, you can write `x @ Some(y)`.
538532
(active, bindings_after_at, "1.41.0", Some(65490), None),

src/librustc_hir/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
44
55
#![feature(crate_visibility_modifier)]
6-
#![feature(const_if_match)]
6+
#![cfg_attr(bootstrap, feature(const_if_match))]
77
#![feature(const_fn)] // For the unsizing cast on `&[]`
88
#![feature(const_panic)]
99
#![feature(in_band_lifetimes)]

src/librustc_index/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(allow_internal_unstable)]
2-
#![feature(const_if_match)]
2+
#![cfg_attr(bootstrap, feature(const_if_match))]
33
#![feature(const_fn)]
44
#![feature(const_panic)]
55
#![feature(extend_one)]

src/librustc_infer/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#![feature(box_patterns)]
1818
#![feature(box_syntax)]
1919
#![feature(const_fn)]
20-
#![feature(const_if_match)]
20+
#![cfg_attr(bootstrap, feature(const_if_match))]
2121
#![feature(const_panic)]
2222
#![feature(extend_one)]
2323
#![feature(never_type)]

0 commit comments

Comments
 (0)