1
Fork 0

Add a TyPat in the AST to reuse the generic arg lowering logic

This commit is contained in:
Oli Scherer 2025-02-06 13:48:12 +00:00
parent c182ce9cbc
commit 6d7ce4e893
21 changed files with 241 additions and 264 deletions

View file

@ -2249,7 +2249,7 @@ pub enum TyKind {
CVarArgs,
/// Pattern types like `pattern_type!(u32 is 1..=)`, which is the same as `NonZero<u32>`,
/// just as part of the type system.
Pat(P<Ty>, P<Pat>),
Pat(P<Ty>, P<TyPat>),
/// Sometimes we need a dummy value when no error has occurred.
Dummy,
/// Placeholder for a kind that has failed to be defined.
@ -2277,6 +2277,27 @@ impl TyKind {
}
}
/// A pattern type pattern.
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct TyPat {
pub id: NodeId,
pub kind: TyPatKind,
pub span: Span,
pub tokens: Option<LazyAttrTokenStream>,
}
/// All the different flavors of pattern that Rust recognizes.
//
// Adding a new variant? Please update `test_pat` in `tests/ui/macros/stringify.rs`.
#[derive(Clone, Encodable, Decodable, Debug)]
pub enum TyPatKind {
/// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`).
Range(Option<P<AnonConst>>, Option<P<AnonConst>>, Spanned<RangeEnd>),
/// Placeholder for a pattern that wasn't syntactically well formed in some way.
Err(ErrorGuaranteed),
}
/// Syntax used to declare a trait object.
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
#[repr(u8)]