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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use crate::priv_prelude::*;
#[derive(Clone, Debug)]
pub struct PathExpr {
pub root_opt: Option<(Option<AngleBrackets<QualifiedPathRoot>>, DoubleColonToken)>,
pub prefix: PathExprSegment,
pub suffix: Vec<(DoubleColonToken, PathExprSegment)>,
}
#[derive(Clone, Debug)]
pub struct PathExprSegment {
pub fully_qualified: Option<TildeToken>,
pub name: Ident,
pub generics_opt: Option<(DoubleColonToken, GenericArgs)>,
}
impl Spanned for PathExpr {
fn span(&self) -> Span {
let start = match &self.root_opt {
Some((qualified_path_root_opt, double_colon_token)) => match qualified_path_root_opt {
Some(qualified_path_root) => qualified_path_root.span(),
None => double_colon_token.span(),
},
None => self.prefix.span(),
};
let end = match self.suffix.last() {
Some((_double_colon_token, path_expr_segment)) => path_expr_segment.span(),
None => self.prefix.span(),
};
Span::join(start, end)
}
}
impl PathExpr {
pub fn try_into_ident(self) -> Result<Ident, PathExpr> {
if self.root_opt.is_none()
&& self.suffix.is_empty()
&& self.prefix.fully_qualified.is_none()
&& self.prefix.generics_opt.is_none()
{
return Ok(self.prefix.name);
}
Err(self)
}
}
impl Spanned for PathExprSegment {
fn span(&self) -> Span {
let start = match &self.fully_qualified {
Some(tilde_token) => tilde_token.span(),
None => self.name.span(),
};
let end = match &self.generics_opt {
Some((_double_colon_token, generic_args)) => generic_args.span(),
None => self.name.span(),
};
Span::join(start, end)
}
}
#[derive(Clone, Debug)]
pub struct PathType {
pub root_opt: Option<(Option<AngleBrackets<QualifiedPathRoot>>, DoubleColonToken)>,
pub prefix: PathTypeSegment,
pub suffix: Vec<(DoubleColonToken, PathTypeSegment)>,
}
impl Spanned for PathType {
fn span(&self) -> Span {
let start = match &self.root_opt {
Some((qualified_path_root_opt, double_colon_token)) => match qualified_path_root_opt {
Some(qualified_path_root) => qualified_path_root.span(),
None => double_colon_token.span(),
},
None => self.prefix.span(),
};
let end = match self.suffix.last() {
Some((_double_colon_token, path_type_segment)) => path_type_segment.span(),
None => self.prefix.span(),
};
Span::join(start, end)
}
}
#[derive(Clone, Debug)]
pub struct PathTypeSegment {
pub fully_qualified: Option<TildeToken>,
pub name: Ident,
pub generics_opt: Option<(Option<DoubleColonToken>, GenericArgs)>,
}
impl Spanned for PathTypeSegment {
fn span(&self) -> Span {
let start = match &self.fully_qualified {
Some(tilde_token) => tilde_token.span(),
None => self.name.span(),
};
let end = match &self.generics_opt {
Some((_double_colon_token, generic_args)) => generic_args.span(),
None => self.name.span(),
};
Span::join(start, end)
}
}
#[derive(Clone, Debug)]
pub struct QualifiedPathRoot {
pub ty: Box<Ty>,
pub as_trait: Option<(AsToken, Box<PathType>)>,
}