Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ast_codegen): detect "complex" type wrappers #4617

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions tasks/ast_codegen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub trait StrExt: AsRef<str> {

#[derive(Debug)]
pub enum TypeIdentResult<'a> {
/// We bailed on detecting wrapper
Complex(Box<TypeIdentResult<'a>>),
Ident(&'a Ident),
Vec(Box<TypeIdentResult<'a>>),
Box(Box<TypeIdentResult<'a>>),
Expand All @@ -81,16 +83,22 @@ impl<'a> TypeIdentResult<'a> {
Self::Option(Box::new(inner))
}

fn complex(inner: Self) -> Self {
Self::Complex(Box::new(inner))
}

fn reference(inner: Self) -> Self {
Self::Reference(Box::new(inner))
}

pub fn inner_ident(&self) -> &'a Ident {
match self {
Self::Ident(it) => it,
Self::Vec(it) | Self::Box(it) | Self::Option(it) | Self::Reference(it) => {
it.inner_ident()
}
Self::Complex(it)
| Self::Vec(it)
| Self::Box(it)
| Self::Option(it)
| Self::Reference(it) => it.inner_ident(),
}
}

Expand All @@ -116,6 +124,8 @@ pub enum TypeWrapper {
OptBox,
OptVec,
Ref,
/// We bailed on detecting the type wrapper
Complex,
}

#[derive(Debug)]
Expand Down Expand Up @@ -151,7 +161,7 @@ impl TypeExt for Type {
if seg1.ident == "Option" {
TypeIdentResult::option(inner)
} else {
inner
TypeIdentResult::complex(inner)
}
}
Some(GenericArgument::Lifetime(_)) => {
Expand All @@ -176,6 +186,11 @@ impl TypeExt for Type {
let mut wrapper = TypeWrapper::None;
let ident = match res {
TypeIdentResult::Ident(inner) => inner,
TypeIdentResult::Complex(inner) => {
wrapper = TypeWrapper::Complex;
let (inner, _) = analyze(inner)?;
inner
}
TypeIdentResult::Box(inner) => {
wrapper = TypeWrapper::Box;
let (inner, inner_kind) = analyze(inner)?;
Expand Down