Skip to content

Commit 67c5eb2

Browse files
rzvxaBoshen
authored andcommitted
fix(ast_codegen): detect "complex" type wrappers
1 parent d25dea7 commit 67c5eb2

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

tasks/ast_codegen/src/util.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub trait StrExt: AsRef<str> {
6161

6262
#[derive(Debug)]
6363
pub enum TypeIdentResult<'a> {
64+
/// We bailed on detecting wrapper
65+
Complex(Box<TypeIdentResult<'a>>),
6466
Ident(&'a Ident),
6567
Vec(Box<TypeIdentResult<'a>>),
6668
Box(Box<TypeIdentResult<'a>>),
@@ -81,16 +83,22 @@ impl<'a> TypeIdentResult<'a> {
8183
Self::Option(Box::new(inner))
8284
}
8385

86+
fn complex(inner: Self) -> Self {
87+
Self::Complex(Box::new(inner))
88+
}
89+
8490
fn reference(inner: Self) -> Self {
8591
Self::Reference(Box::new(inner))
8692
}
8793

8894
pub fn inner_ident(&self) -> &'a Ident {
8995
match self {
9096
Self::Ident(it) => it,
91-
Self::Vec(it) | Self::Box(it) | Self::Option(it) | Self::Reference(it) => {
92-
it.inner_ident()
93-
}
97+
Self::Complex(it)
98+
| Self::Vec(it)
99+
| Self::Box(it)
100+
| Self::Option(it)
101+
| Self::Reference(it) => it.inner_ident(),
94102
}
95103
}
96104

@@ -116,6 +124,8 @@ pub enum TypeWrapper {
116124
OptBox,
117125
OptVec,
118126
Ref,
127+
/// We bailed on detecting the type wrapper
128+
Complex,
119129
}
120130

121131
#[derive(Debug)]
@@ -151,7 +161,7 @@ impl TypeExt for Type {
151161
if seg1.ident == "Option" {
152162
TypeIdentResult::option(inner)
153163
} else {
154-
inner
164+
TypeIdentResult::complex(inner)
155165
}
156166
}
157167
Some(GenericArgument::Lifetime(_)) => {
@@ -176,6 +186,11 @@ impl TypeExt for Type {
176186
let mut wrapper = TypeWrapper::None;
177187
let ident = match res {
178188
TypeIdentResult::Ident(inner) => inner,
189+
TypeIdentResult::Complex(inner) => {
190+
wrapper = TypeWrapper::Complex;
191+
let (inner, _) = analyze(inner)?;
192+
inner
193+
}
179194
TypeIdentResult::Box(inner) => {
180195
wrapper = TypeWrapper::Box;
181196
let (inner, inner_kind) = analyze(inner)?;

0 commit comments

Comments
 (0)