1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::priv_prelude::*;
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug)]
pub enum Ty {
Path(PathType),
Tuple(Parens<TyTupleDescriptor>),
Array(SquareBrackets<TyArrayDescriptor>),
Str {
str_token: StrToken,
length: SquareBrackets<Box<Expr>>,
},
Infer {
underscore_token: UnderscoreToken,
},
}
impl Spanned for Ty {
fn span(&self) -> Span {
match self {
Ty::Path(path_type) => path_type.span(),
Ty::Tuple(tuple_type) => tuple_type.span(),
Ty::Array(array_type) => array_type.span(),
Ty::Str { str_token, length } => Span::join(str_token.span(), length.span()),
Ty::Infer { underscore_token } => underscore_token.span(),
}
}
}
#[derive(Clone, Debug)]
pub enum TyTupleDescriptor {
Nil,
Cons {
head: Box<Ty>,
comma_token: CommaToken,
tail: Punctuated<Ty, CommaToken>,
},
}
impl TyTupleDescriptor {
pub fn to_tys(self) -> Vec<Ty> {
match self {
TyTupleDescriptor::Nil => vec![],
TyTupleDescriptor::Cons { head, tail, .. } => {
let mut tys = vec![*head];
for ty in tail.into_iter() {
tys.push(ty);
}
tys
}
}
}
}
#[derive(Clone, Debug)]
pub struct TyArrayDescriptor {
pub ty: Box<Ty>,
pub semicolon_token: SemicolonToken,
pub length: Box<Expr>,
}