Skip to content

Commit 6d61d87

Browse files
committed
Split inline const to two feature gates
1 parent cebd2dd commit 6d61d87

21 files changed

+67
-31
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
719719
gate_all!(const_trait_impl, "const trait impls are experimental");
720720
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
721721
gate_all!(inline_const, "inline-const is experimental");
722+
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
722723
gate_all!(
723724
const_generics_defaults,
724725
"default values for const generic parameters are experimental"

compiler/rustc_feature/src/active.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ declare_features! (
410410
(incomplete, inherent_associated_types, "1.52.0", Some(8995), None),
411411
/// Allow anonymous constants from an inline `const` block
412412
(incomplete, inline_const, "1.49.0", Some(76001), None),
413+
/// Allow anonymous constants from an inline `const` block in pattern position
414+
(incomplete, inline_const_pat, "1.58.0", Some(76001), None),
413415
/// Allows using `pointer` and `reference` in intra-doc links
414416
(active, intra_doc_pointers, "1.51.0", Some(80896), None),
415417
/// Allows `#[instruction_set(_)]` attribute

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ impl<'a> Parser<'a> {
12431243
} else if self.eat_keyword(kw::Unsafe) {
12441244
self.parse_block_expr(None, lo, BlockCheckMode::Unsafe(ast::UserProvided), attrs)
12451245
} else if self.check_inline_const(0) {
1246-
self.parse_const_block(lo.to(self.token.span))
1246+
self.parse_const_block(lo.to(self.token.span), false)
12471247
} else if self.is_do_catch_block() {
12481248
self.recover_do_catch(attrs)
12491249
} else if self.is_try_block() {

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,12 @@ impl<'a> Parser<'a> {
10951095
}
10961096

10971097
/// Parses inline const expressions.
1098-
fn parse_const_block(&mut self, span: Span) -> PResult<'a, P<Expr>> {
1099-
self.sess.gated_spans.gate(sym::inline_const, span);
1098+
fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>> {
1099+
if pat {
1100+
self.sess.gated_spans.gate(sym::inline_const_pat, span);
1101+
} else {
1102+
self.sess.gated_spans.gate(sym::inline_const, span);
1103+
}
11001104
self.eat_keyword(kw::Const);
11011105
let blk = self.parse_block()?;
11021106
let anon_const = AnonConst {

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<'a> Parser<'a> {
437437
PatKind::Box(pat)
438438
} else if self.check_inline_const(0) {
439439
// Parse `const pat`
440-
let const_expr = self.parse_const_block(lo.to(self.token.span))?;
440+
let const_expr = self.parse_const_block(lo.to(self.token.span), true)?;
441441

442442
if let Some(re) = self.parse_range_end() {
443443
self.parse_pat_range_begin_with(const_expr, re)?
@@ -884,7 +884,7 @@ impl<'a> Parser<'a> {
884884

885885
fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> {
886886
if self.check_inline_const(0) {
887-
self.parse_const_block(self.token.span)
887+
self.parse_const_block(self.token.span, true)
888888
} else if self.check_path() {
889889
let lo = self.token.span;
890890
let (qself, path) = if self.eat_lt() {

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ symbols! {
731731
inlateout,
732732
inline,
733733
inline_const,
734+
inline_const_pat,
734735
inout,
735736
instruction_set,
736737
intel,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# `inline_const_pat`
2+
3+
The tracking issue for this feature is: [#76001]
4+
5+
See also [`inline_const`](inline-const.md)
6+
7+
------
8+
9+
This feature allows you to use inline constant expressions in pattern position:
10+
11+
```rust
12+
#![feature(inline_const_pat)]
13+
14+
const fn one() -> i32 { 1 }
15+
16+
let some_int = 3;
17+
match some_int {
18+
const { 1 + 2 } => println!("Matched 1 + 2"),
19+
const { one() } => println!("Matched const fn returning 1"),
20+
_ => println!("Didn't match anything :("),
21+
}
22+
```
23+
24+
[#76001]: https://github.com/rust-lang/rust/issues/76001

src/doc/unstable-book/src/language-features/inline-const.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The tracking issue for this feature is: [#76001]
44

5+
See also [`inline_const_pat`](inline-const-pat.md)
6+
57
------
68

79
This feature allows you to use inline constant expressions. For example, you can
@@ -27,19 +29,4 @@ fn main() {
2729
}
2830
```
2931

30-
You can also use inline constant expressions in patterns:
31-
32-
```rust
33-
#![feature(inline_const)]
34-
35-
const fn one() -> i32 { 1 }
36-
37-
let some_int = 3;
38-
match some_int {
39-
const { 1 + 2 } => println!("Matched 1 + 2"),
40-
const { one() } => println!("Matched const fn returning 1"),
41-
_ => println!("Didn't match anything :("),
42-
}
43-
```
44-
4532
[#76001]: https://github.com/rust-lang/rust/issues/76001
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let const { () } = ();
3+
//~^ ERROR inline-const in pattern position is experimental [E0658]
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: inline-const in pattern position is experimental
2+
--> $DIR/feature-gate-inline_const_pat.rs:2:9
3+
|
4+
LL | let const { () } = ();
5+
| ^^^^^
6+
|
7+
= note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information
8+
= help: add `#![feature(inline_const_pat)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/half-open-range-patterns/range_pat_interactions0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(incomplete_features)]
33
#![feature(exclusive_range_pattern)]
44
#![feature(half_open_range_patterns)]
5-
#![feature(inline_const)]
5+
#![feature(inline_const_pat)]
66

77
fn main() {
88
let mut if_lettable = vec![];

src/test/ui/half-open-range-patterns/range_pat_interactions3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
y @ (0..5 | 6) => or_two.push(y),
1313
//~^ exclusive range pattern syntax is experimental
1414
y @ 0..const { 5 + 1 } => assert_eq!(y, 5),
15-
//~^ inline-const is experimental
15+
//~^ inline-const in pattern position is experimental
1616
//~| exclusive range pattern syntax is experimental
1717
y @ -5.. => range_from.push(y),
1818
y @ ..-7 => assert_eq!(y, -8),

src/test/ui/half-open-range-patterns/range_pat_interactions3.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ LL | y @ ..-7 => assert_eq!(y, -8),
77
= note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
88
= help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable
99

10-
error[E0658]: inline-const is experimental
10+
error[E0658]: inline-const in pattern position is experimental
1111
--> $DIR/range_pat_interactions3.rs:14:20
1212
|
1313
LL | y @ 0..const { 5 + 1 } => assert_eq!(y, 5),
1414
| ^^^^^
1515
|
1616
= note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information
17-
= help: add `#![feature(inline_const)]` to the crate attributes to enable
17+
= help: add `#![feature(inline_const_pat)]` to the crate attributes to enable
1818

1919
error[E0658]: exclusive range pattern syntax is experimental
2020
--> $DIR/range_pat_interactions3.rs:10:17

src/test/ui/inline-const/const-match-pat-generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(incomplete_features)]
2-
#![feature(inline_const)]
2+
#![feature(inline_const_pat)]
33

44
// rust-lang/rust#82518: ICE with inline-const in match referencing const-generic parameter
55

src/test/ui/inline-const/const-match-pat-inference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// check-pass
22

3-
#![feature(inline_const)]
3+
#![feature(inline_const_pat)]
44
#![allow(incomplete_features)]
55

66
fn main() {

src/test/ui/inline-const/const-match-pat-lifetime-err.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![allow(incomplete_features)]
44
#![feature(const_mut_refs)]
5-
#![feature(inline_const)]
5+
#![feature(inline_const_pat)]
66

77
use std::marker::PhantomData;
88

src/test/ui/inline-const/const-match-pat-lifetime.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![allow(incomplete_features)]
44
#![feature(const_mut_refs)]
55
#![feature(inline_const)]
6+
#![feature(inline_const_pat)]
67

78
use std::marker::PhantomData;
89

src/test/ui/inline-const/const-match-pat-range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// build-pass
22

33
#![allow(incomplete_features)]
4-
#![feature(inline_const, half_open_range_patterns, exclusive_range_pattern)]
4+
#![feature(inline_const_pat, half_open_range_patterns, exclusive_range_pattern)]
55
fn main() {
66
const N: u32 = 10;
77
let x: u32 = 3;

src/test/ui/inline-const/const-match-pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// run-pass
22

33
#![allow(incomplete_features)]
4-
#![feature(inline_const)]
4+
#![feature(inline_const_pat)]
55
const MMIO_BIT1: u8 = 4;
66
const MMIO_BIT2: u8 = 5;
77

src/test/ui/lint/dead-code/anon-const-in-pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
#![feature(inline_const)]
2+
#![feature(inline_const_pat)]
33
#![allow(incomplete_features)]
44
#![deny(dead_code)]
55

src/test/ui/pattern/non-structural-match-types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(incomplete_features)]
33
#![allow(unreachable_code)]
44
#![feature(const_async_blocks)]
5-
#![feature(inline_const)]
5+
#![feature(inline_const_pat)]
66

77
fn main() {
88
match loop {} {

0 commit comments

Comments
 (0)