Add pattern types to ast
This commit is contained in:
parent
0e5f520788
commit
fc27a91880
@ -2152,6 +2152,9 @@ pub enum TyKind {
|
||||
MacCall(P<MacCall>),
|
||||
/// Placeholder for a `va_list`.
|
||||
CVarArgs,
|
||||
/// Pattern types like `u32 as 1..=`, which is the same as `NonZeroU32`,
|
||||
/// just as part of the type system.
|
||||
Pat(P<Ty>, P<Pat>),
|
||||
/// Sometimes we need a dummy value when no error has occurred.
|
||||
Dummy,
|
||||
/// Placeholder for a kind that has failed to be defined.
|
||||
|
@ -502,6 +502,10 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
|
||||
}
|
||||
TyKind::Tup(tys) => visit_thin_vec(tys, |ty| vis.visit_ty(ty)),
|
||||
TyKind::Paren(ty) => vis.visit_ty(ty),
|
||||
TyKind::Pat(ty, pat) => {
|
||||
vis.visit_ty(ty);
|
||||
vis.visit_pat(pat);
|
||||
}
|
||||
TyKind::Path(qself, path) => {
|
||||
vis.visit_qself(qself);
|
||||
vis.visit_path(path);
|
||||
|
@ -446,6 +446,10 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) -> V::Result {
|
||||
}
|
||||
try_visit!(visitor.visit_path(path, typ.id));
|
||||
}
|
||||
TyKind::Pat(ty, pat) => {
|
||||
try_visit!(visitor.visit_ty(ty));
|
||||
try_visit!(visitor.visit_pat(pat));
|
||||
}
|
||||
TyKind::Array(ty, length) => {
|
||||
try_visit!(visitor.visit_ty(ty));
|
||||
try_visit!(visitor.visit_anon_const(length));
|
||||
|
@ -1463,7 +1463,9 @@ fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir>
|
||||
}
|
||||
}
|
||||
}
|
||||
TyKind::MacCall(_) => panic!("`TyKind::MacCall` should have been expanded by now"),
|
||||
TyKind::MacCall(_) => {
|
||||
span_bug!(t.span, "`TyKind::MacCall` should have been expanded by now")
|
||||
}
|
||||
TyKind::CVarArgs => {
|
||||
let guar = self.dcx().span_delayed_bug(
|
||||
t.span,
|
||||
@ -1471,6 +1473,7 @@ fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir>
|
||||
);
|
||||
hir::TyKind::Err(guar)
|
||||
}
|
||||
TyKind::Pat(..) => span_bug!(t.span, "pattern types are unimplemented"),
|
||||
TyKind::Dummy => panic!("`TyKind::Dummy` should never be lowered"),
|
||||
};
|
||||
|
||||
|
@ -1188,6 +1188,11 @@ pub fn print_type(&mut self, ty: &ast::Ty) {
|
||||
ast::TyKind::CVarArgs => {
|
||||
self.word("...");
|
||||
}
|
||||
ast::TyKind::Pat(ty, pat) => {
|
||||
self.print_type(ty);
|
||||
self.word(" is ");
|
||||
self.print_pat(pat);
|
||||
}
|
||||
}
|
||||
self.end();
|
||||
}
|
||||
|
@ -611,6 +611,7 @@ fn visit_ty(&mut self, t: &'v ast::Ty) {
|
||||
AnonStruct,
|
||||
AnonUnion,
|
||||
Path,
|
||||
Pat,
|
||||
TraitObject,
|
||||
ImplTrait,
|
||||
Paren,
|
||||
|
@ -867,6 +867,11 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>
|
||||
self.span,
|
||||
shape,
|
||||
),
|
||||
ast::TyKind::Pat(ref ty, ref pat) => {
|
||||
let ty = ty.rewrite(context, shape)?;
|
||||
let pat = pat.rewrite(context, shape)?;
|
||||
Some(format!("{ty} is {pat}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user