Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ICEing without the pattern_types feature gate #123648

Merged
merged 2 commits into from Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/unstable.rs
Expand Up @@ -216,7 +216,7 @@ declare_features! (
/// 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.
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Expand Up @@ -2249,7 +2249,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
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
Expand Down
15 changes: 15 additions & 0 deletions 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<u32> is Some(_));
//~^ ERROR: pattern types are unstable

type Binding = pattern_type!(Option<u32> is x);
//~^ ERROR: pattern types are unstable

fn main() {}
23 changes: 23 additions & 0 deletions 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<u32> is Some(_));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #123646 <https://github.com/rust-lang/rust/issues/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<u32> is x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #123646 <https://github.com/rust-lang/rust/issues/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`.