From 07310e21d42fdbed374d0e76924fdbce1644bae7 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 8 Apr 2024 20:53:05 +0000 Subject: [PATCH 1/2] Set the correct tracking issue for pattern types --- compiler/rustc_feature/src/unstable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 129ce1d3109..e6b19817de3 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -216,7 +216,7 @@ pub fn internal(&self, feature: Symbol) -> bool { /// Set the maximum pattern complexity allowed (not limited by default). (internal, pattern_complexity, "1.78.0", None), /// Allows using pattern types. - (internal, pattern_types, "CURRENT_RUSTC_VERSION", Some(54882)), + (internal, pattern_types, "CURRENT_RUSTC_VERSION", Some(123646)), /// Allows using `#[prelude_import]` on glob `use` items. (internal, prelude_import, "1.2.0", None), /// Used to identify crates that contain the profiler runtime. From 24ee9b9423465ea4b1cc482e5aaf3a38758b2167 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 8 Apr 2024 21:02:13 +0000 Subject: [PATCH 2/2] Avoid ICEing without the `pattern_types` feature gate --- .../src/hir_ty_lowering/mod.rs | 6 ++++- .../type/pattern_types/unimplemented_pat.rs | 15 ++++++++++++ .../pattern_types/unimplemented_pat.stderr | 23 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/ui/type/pattern_types/unimplemented_pat.rs create mode 100644 tests/ui/type/pattern_types/unimplemented_pat.stderr diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index ebfccd27d17..59f0fac5aa7 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2249,7 +2249,11 @@ fn lower_ty_common(&self, hir_ty: &hir::Ty<'tcx>, borrowed: bool, in_path: bool) Ty::new_pat(tcx, ty, pat) } hir::PatKind::Err(e) => Ty::new_error(tcx, e), - _ => span_bug!(pat.span, "unsupported pattern for pattern type: {pat:#?}"), + _ => Ty::new_error_with_message( + tcx, + pat.span, + format!("unsupported pattern for pattern type: {pat:#?}"), + ), }; self.record_ty(pat.hir_id, ty, pat.span); pat_ty diff --git a/tests/ui/type/pattern_types/unimplemented_pat.rs b/tests/ui/type/pattern_types/unimplemented_pat.rs new file mode 100644 index 00000000000..c02160ff58a --- /dev/null +++ b/tests/ui/type/pattern_types/unimplemented_pat.rs @@ -0,0 +1,15 @@ +//! This test ensures we do not ICE for unimplemented +//! patterns unless the feature gate is enabled. + +#![feature(core_pattern_type)] +#![feature(core_pattern_types)] + +use std::pat::pattern_type; + +type Always = pattern_type!(Option is Some(_)); +//~^ ERROR: pattern types are unstable + +type Binding = pattern_type!(Option is x); +//~^ ERROR: pattern types are unstable + +fn main() {} diff --git a/tests/ui/type/pattern_types/unimplemented_pat.stderr b/tests/ui/type/pattern_types/unimplemented_pat.stderr new file mode 100644 index 00000000000..481c6017dcc --- /dev/null +++ b/tests/ui/type/pattern_types/unimplemented_pat.stderr @@ -0,0 +1,23 @@ +error[E0658]: pattern types are unstable + --> $DIR/unimplemented_pat.rs:9:15 + | +LL | type Always = pattern_type!(Option is Some(_)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #123646 for more information + = help: add `#![feature(pattern_types)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: pattern types are unstable + --> $DIR/unimplemented_pat.rs:12:16 + | +LL | type Binding = pattern_type!(Option is x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #123646 for more information + = help: add `#![feature(pattern_types)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`.