Skip to content

Commit 0b4a81a

Browse files
committed
Auto merge of rust-lang#138492 - lcnr:rm-inline_const_pat, r=oli-obk
remove `feature(inline_const_pat)` Summarizing https://rust-lang.zulipchat.com/#narrow/channel/144729-t-types/topic/remove.20feature.28inline_const_pat.29.20and.20shared.20borrowck. With rust-lang/types-team#129 we will start to borrowck items together with their typeck parent. This is necessary to correctly support opaque types, blocking the new solver and TAIT/ATPIT stabilization with the old one. This means that we cannot really support `inline_const_pat` as they are implemented right now: - we want to typeck inline consts together with their parent body to allow inference to flow both ways and to allow the const to refer to local regions of its parent.This means we also need to borrowck the inline const together with its parent as that's necessary to properly support opaque types - we want the inline const pattern to participate in exhaustiveness checking - to participate in exhaustiveness checking we need to evaluate it, which requires borrowck, which now relies on borrowck of the typeck root, which ends up checking exhaustiveness again. **This is a query cycle**. There are 4 possible ways to handle this: - stop typechecking inline const patterns together with their parent - causes inline const patterns to be different than inline const exprs - prevents bidirectional inference, we need to either fail to compile `if let const { 1 } = 1u32` or `if let const { 1u32 } = 1` - region inference for inline consts will be harder, it feels non-trivial to support inline consts referencing local regions from the parent fn - inline consts no longer participate in exhaustiveness checking. Treat them like `pat if pat == const { .. }` instead. We then only evaluate them after borrowck - difference between `const { 1 }` and `const FOO: usize = 1; match x { FOO => () }`. This is confusing - do they carry their weight if they are now just equivalent to using an if-guard - delay exhaustiveness checking until after borrowck - should be possible in theory, but is a quite involved change and may have some unexpected challenges - remove this feature for now I believe we should either delay exhaustiveness checking or remove the feature entirely. As moving exhaustiveness checking to after borrow checking is quite complex I think the right course of action is to fully remove the feature for now and to add it again once/if we've got that implementation figured out. `const { .. }`-expressions remain stable. These seem to have been the main motivation for rust-lang/rfcs#2920. r? types cc `@rust-lang/types` `@rust-lang/lang` rust-lang#76001
2 parents 8c35f4a + a3b7990 commit 0b4a81a

File tree

59 files changed

+721
-1493
lines changed

Some content is hidden

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

59 files changed

+721
-1493
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
490490
half_open_range_patterns_in_slices,
491491
"half-open range patterns in slices are unstable"
492492
);
493-
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
494493
gate_all!(associated_const_equality, "associated const equality is incomplete");
495494
gate_all!(yeet_expr, "`do yeet` expression is experimental");
496495
gate_all!(dyn_star, "`dyn*` trait objects are experimental");

compiler/rustc_feature/src/removed.rs

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ declare_features! (
142142
/// Allows inferring `'static` outlives requirements (RFC 2093).
143143
(removed, infer_static_outlives_requirements, "1.63.0", Some(54185),
144144
Some("removed as it caused some confusion and discussion was inactive for years")),
145+
/// Allow anonymous constants from an inline `const` block in pattern position
146+
(removed, inline_const_pat, "CURRENT_RUSTC_VERSION", Some(76001),
147+
Some("removed due to implementation concerns as it requires significant refactorings")),
145148
/// Lazily evaluate constants. This allows constants to depend on type parameters.
146149
(removed, lazy_normalization_consts, "1.46.0", Some(72219), Some("superseded by `generic_const_exprs`")),
147150
/// Changes `impl Trait` to capture all lifetimes in scope.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,6 @@ declare_features! (
531531
(unstable, import_trait_associated_functions, "1.86.0", Some(134691)),
532532
/// Allows associated types in inherent impls.
533533
(incomplete, inherent_associated_types, "1.52.0", Some(8995)),
534-
/// Allow anonymous constants from an inline `const` block in pattern position
535-
(unstable, inline_const_pat, "1.58.0", Some(76001)),
536534
/// Allows using `pointer` and `reference` in intra-doc links
537535
(unstable, intra_doc_pointers, "1.51.0", Some(80896)),
538536
// Allows using the `kl` and `widekl` target features and the associated intrinsics

compiler/rustc_parse/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,6 @@ parse_unexpected_expr_in_pat_const_sugg = consider extracting the expression int
838838
839839
parse_unexpected_expr_in_pat_create_guard_sugg = consider moving the expression to a match arm guard
840840
841-
parse_unexpected_expr_in_pat_inline_const_sugg = consider wrapping the expression in an inline `const` (requires `{"#"}![feature(inline_const_pat)]`)
842-
843841
parse_unexpected_expr_in_pat_update_guard_sugg = consider moving the expression to the match arm guard
844842
845843
parse_unexpected_if_with_if = unexpected `if` in the condition expression

compiler/rustc_parse/src/errors.rs

-11
Original file line numberDiff line numberDiff line change
@@ -2769,17 +2769,6 @@ pub(crate) enum UnexpectedExpressionInPatternSugg {
27692769
/// The statement's block's indentation.
27702770
indentation: String,
27712771
},
2772-
2773-
#[multipart_suggestion(
2774-
parse_unexpected_expr_in_pat_inline_const_sugg,
2775-
applicability = "maybe-incorrect"
2776-
)]
2777-
InlineConst {
2778-
#[suggestion_part(code = "const {{ ")]
2779-
start_span: Span,
2780-
#[suggestion_part(code = " }}")]
2781-
end_span: Span,
2782-
},
27832772
}
27842773

27852774
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/mod.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1370,17 +1370,24 @@ impl<'a> Parser<'a> {
13701370

13711371
/// Parses inline const expressions.
13721372
fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>> {
1373-
if pat {
1374-
self.psess.gated_spans.gate(sym::inline_const_pat, span);
1375-
}
13761373
self.expect_keyword(exp!(Const))?;
13771374
let (attrs, blk) = self.parse_inner_attrs_and_block(None)?;
13781375
let anon_const = AnonConst {
13791376
id: DUMMY_NODE_ID,
13801377
value: self.mk_expr(blk.span, ExprKind::Block(blk, None)),
13811378
};
13821379
let blk_span = anon_const.value.span;
1383-
Ok(self.mk_expr_with_attrs(span.to(blk_span), ExprKind::ConstBlock(anon_const), attrs))
1380+
let kind = if pat {
1381+
let guar = self
1382+
.dcx()
1383+
.struct_span_err(blk_span, "`inline_const_pat` has been removed")
1384+
.with_help("use a named `const`-item or an `if`-guard instead")
1385+
.emit();
1386+
ExprKind::Err(guar)
1387+
} else {
1388+
ExprKind::ConstBlock(anon_const)
1389+
};
1390+
Ok(self.mk_expr_with_attrs(span.to(blk_span), kind, attrs))
13841391
}
13851392

13861393
/// Parses mutability (`mut` or nothing).

compiler/rustc_parse/src/parser/pat.rs

-9
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,6 @@ impl<'a> Parser<'a> {
631631
ident,
632632
indentation,
633633
});
634-
635-
// help: wrap the expr in a `const { expr }`
636-
// FIXME(inline_const_pat): once stabilized, remove this check and remove the `(requires #[feature(inline_const_pat)])` note from the message
637-
if self.parser.psess.unstable_features.is_nightly_build() {
638-
err.subdiagnostic(UnexpectedExpressionInPatternSugg::InlineConst {
639-
start_span: expr_span.shrink_to_lo(),
640-
end_span: expr_span.shrink_to_hi(),
641-
});
642-
}
643634
},
644635
);
645636
}

library/coretests/tests/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#![feature(generic_assert_internals)]
4040
#![feature(hasher_prefixfree_extras)]
4141
#![feature(hashmap_internals)]
42-
#![feature(inline_const_pat)]
4342
#![feature(int_roundings)]
4443
#![feature(ip)]
4544
#![feature(ip_from)]
@@ -95,16 +94,17 @@
9594

9695
/// Version of `assert_matches` that ignores fancy runtime printing in const context and uses structural equality.
9796
macro_rules! assert_eq_const_safe {
98-
($left:expr, $right:expr) => {
99-
assert_eq_const_safe!($left, $right, concat!(stringify!($left), " == ", stringify!($right)));
97+
($t:ty: $left:expr, $right:expr) => {
98+
assert_eq_const_safe!($t: $left, $right, concat!(stringify!($left), " == ", stringify!($right)));
10099
};
101-
($left:expr, $right:expr$(, $($arg:tt)+)?) => {
100+
($t:ty: $left:expr, $right:expr$(, $($arg:tt)+)?) => {
102101
{
103102
fn runtime() {
104103
assert_eq!($left, $right, $($($arg)*),*);
105104
}
106105
const fn compiletime() {
107-
assert!(matches!($left, const { $right }));
106+
const PAT: $t = $right;
107+
assert!(matches!($left, PAT), $($($arg)*),*);
108108
}
109109
core::intrinsics::const_eval_select((), compiletime, runtime)
110110
}

0 commit comments

Comments
 (0)