Skip to content

Commit f8c08a3

Browse files
committed
Start handling pattern types at the HIR -> Ty conversion boundary
1 parent d220902 commit f8c08a3

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,6 @@ hir_analysis_linkage_type =
124124
hir_analysis_auto_deref_reached_recursion_limit = reached the recursion limit while auto-dereferencing `{$ty}`
125125
.label = deref recursion limit reached
126126
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
127+
128+
hir_analysis_pattern_type_wild_pat = "wildcard patterns are not permitted for pattern types"
129+
.label = "this type is the same as the inner type without a pattern"

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::bounds::Bounds;
1212
use crate::collect::HirPlaceholderCollector;
1313
use crate::errors::{
1414
AmbiguousLifetimeBound, MultipleRelaxedDefaultBounds, TraitObjectDeclaredWithNoTraits,
15-
TypeofReservedKeywordUsed, ValueOfAssociatedStructAlreadySpecified,
15+
TypeofReservedKeywordUsed, ValueOfAssociatedStructAlreadySpecified, WildPatTy,
1616
};
1717
use crate::middle::resolve_lifetime as rl;
1818
use crate::require_c_abi_if_c_variadic;
@@ -2961,7 +2961,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29612961
// handled specially and will not descend into this routine.
29622962
self.ty_infer(None, ast_ty.span)
29632963
}
2964-
hir::TyKind::Pat(..) => span_bug!(ast_ty.span, "{ast_ty:#?}"),
2964+
hir::TyKind::Pat(_ty, pat) => match pat.kind {
2965+
hir::PatKind::Wild => {
2966+
let err = tcx.sess.emit_err(WildPatTy { span: pat.span });
2967+
tcx.ty_error_with_guaranteed(err)
2968+
}
2969+
hir::PatKind::Binding(_, _, _, _) => todo!(),
2970+
hir::PatKind::Struct(_, _, _) => todo!(),
2971+
hir::PatKind::TupleStruct(_, _, _) => todo!(),
2972+
hir::PatKind::Or(_) => todo!(),
2973+
hir::PatKind::Path(_) => todo!(),
2974+
hir::PatKind::Tuple(_, _) => todo!(),
2975+
hir::PatKind::Box(_) => todo!(),
2976+
hir::PatKind::Ref(_, _) => todo!(),
2977+
hir::PatKind::Lit(_) => todo!(),
2978+
hir::PatKind::Range(_, _, _) => tcx.ty_error(),
2979+
hir::PatKind::Slice(_, _, _) => todo!(),
2980+
},
29652981
hir::TyKind::Err => tcx.ty_error(),
29662982
};
29672983

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use rustc_macros::{Diagnostic, LintDiagnostic};
66
use rustc_middle::ty::Ty;
77
use rustc_span::{symbol::Ident, Span, Symbol};
88

9+
mod pattern_types;
10+
11+
pub use pattern_types::*;
12+
913
#[derive(Diagnostic)]
1014
#[diag(hir_analysis_unrecognized_atomic_operation, code = "E0092")]
1115
pub struct UnrecognizedAtomicOperation<'a> {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use rustc_macros::Diagnostic;
2+
use rustc_span::Span;
3+
4+
#[derive(Diagnostic)]
5+
#[diag(hir_analysis_pattern_type_wild_pat)]
6+
pub struct WildPatTy {
7+
#[primary_span]
8+
pub span: Span,
9+
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// compile-flags: -Zno-analysis
2-
31
#![feature(pattern_types)]
42

53
type NonNullU32_2 = u32 is 1..=;
64
//~^ ERROR: inclusive range with no end
75
type Positive2 = i32 is 0..=;
86
//~^ ERROR: inclusive range with no end
7+
type Wild = () is _;
8+
//~^ ERROR: wildcard patterns are not permitted for pattern types
9+
10+
fn main() {}
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
error[E0586]: inclusive range with no end
2-
--> $DIR/bad_pat.rs:5:29
2+
--> $DIR/bad_pat.rs:3:29
33
|
44
LL | type NonNullU32_2 = u32 is 1..=;
55
| ^^^ help: use `..` instead
66
|
77
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
88

99
error[E0586]: inclusive range with no end
10-
--> $DIR/bad_pat.rs:7:26
10+
--> $DIR/bad_pat.rs:5:26
1111
|
1212
LL | type Positive2 = i32 is 0..=;
1313
| ^^^ help: use `..` instead
1414
|
1515
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
1616

17-
error: aborting due to 2 previous errors
17+
error: "wildcard patterns are not permitted for pattern types"
18+
--> $DIR/bad_pat.rs:7:19
19+
|
20+
LL | type Wild = () is _;
21+
| ^
22+
23+
error: aborting due to 3 previous errors
1824

1925
For more information about this error, try `rustc --explain E0586`.

0 commit comments

Comments
 (0)