From 68a58f255ac7b7487769667fdd5fe2536f952c15 Mon Sep 17 00:00:00 2001 From: Ross Smyth Date: Thu, 15 Feb 2024 19:54:35 -0500 Subject: [PATCH 01/22] Add postfix-match experimental feature Co-authored-by: Josh Stone --- compiler/rustc_ast_passes/src/feature_gate.rs | 1 + compiler/rustc_feature/src/unstable.rs | 2 + compiler/rustc_parse/src/parser/expr.rs | 19 +++++- compiler/rustc_span/src/symbol.rs | 1 + .../src/language-features/postfix-match.md | 22 +++++++ .../feature-gate-postfix_match.rs | 17 +++++ .../feature-gate-postfix_match.stderr | 23 +++++++ .../ui/match/postfix-match/pf-match-chain.rs | 16 +++++ .../postfix-match/pf-match-exhaustiveness.rs | 7 +++ .../pf-match-exhaustiveness.stderr | 21 +++++++ .../ui/match/postfix-match/pf-match-types.rs | 15 +++++ .../match/postfix-match/pf-match-types.stderr | 21 +++++++ tests/ui/match/postfix-match/postfix-match.rs | 62 +++++++++++++++++++ 13 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 src/doc/unstable-book/src/language-features/postfix-match.md create mode 100644 tests/ui/feature-gates/feature-gate-postfix_match.rs create mode 100644 tests/ui/feature-gates/feature-gate-postfix_match.stderr create mode 100644 tests/ui/match/postfix-match/pf-match-chain.rs create mode 100644 tests/ui/match/postfix-match/pf-match-exhaustiveness.rs create mode 100644 tests/ui/match/postfix-match/pf-match-exhaustiveness.stderr create mode 100644 tests/ui/match/postfix-match/pf-match-types.rs create mode 100644 tests/ui/match/postfix-match/pf-match-types.stderr create mode 100644 tests/ui/match/postfix-match/postfix-match.rs diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index a28fcb007794..296f237763eb 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -565,6 +565,7 @@ macro_rules! gate_all { gate_all!(generic_const_items, "generic const items are experimental"); gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented"); gate_all!(fn_delegation, "functions delegation is not yet fully implemented"); + gate_all!(postfix_match, "postfix match is experimental"); if !visitor.features.never_patterns { if let Some(spans) = spans.get(&sym::never_patterns) { diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 17c4d81474e2..89f471d21bb0 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -555,6 +555,8 @@ pub fn internal(&self, feature: Symbol) -> bool { (unstable, offset_of_nested, "1.77.0", Some(120140)), /// Allows using `#[optimize(X)]`. (unstable, optimize_attribute, "1.34.0", Some(54882)), + /// Allows postfix match `expr.match { ... }` + (unstable, postfix_match, "CURRENT_RUSTC_VERSION", Some(121618)), /// Allows macro attributes on expressions, statements and non-inline modules. (unstable, proc_macro_hygiene, "1.30.0", Some(54727)), /// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions. diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 6cc358db9fca..02ff452473dd 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1375,6 +1375,12 @@ fn parse_dot_suffix(&mut self, self_arg: P, lo: Span) -> PResult<'a, P Option