From bcfa2978e7dcf500eb95d9fff5ead168d0ab442e Mon Sep 17 00:00:00 2001 From: rzvxa <3788964+rzvxa@users.noreply.github.com> Date: Sat, 3 Aug 2024 12:11:34 +0000 Subject: [PATCH] fix(ast_codegen): detect "complex" type wrappers (#4617) Detect types such as `Cell>` and mark them as such! We didn't used to use this method for these options but now we have to check all types to calculate their layouts which means we need to process them correctly(instead of falling to their inner value). --- tasks/ast_codegen/src/util.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tasks/ast_codegen/src/util.rs b/tasks/ast_codegen/src/util.rs index af0dc688f2a56..878e280800190 100644 --- a/tasks/ast_codegen/src/util.rs +++ b/tasks/ast_codegen/src/util.rs @@ -61,6 +61,8 @@ pub trait StrExt: AsRef { #[derive(Debug)] pub enum TypeIdentResult<'a> { + /// We bailed on detecting wrapper + Complex(Box>), Ident(&'a Ident), Vec(Box>), Box(Box>), @@ -81,6 +83,10 @@ 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)) } @@ -88,9 +94,11 @@ impl<'a> TypeIdentResult<'a> { 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(), } } @@ -116,6 +124,8 @@ pub enum TypeWrapper { OptBox, OptVec, Ref, + /// We bailed on detecting the type wrapper + Complex, } #[derive(Debug)] @@ -151,7 +161,7 @@ impl TypeExt for Type { if seg1.ident == "Option" { TypeIdentResult::option(inner) } else { - inner + TypeIdentResult::complex(inner) } } Some(GenericArgument::Lifetime(_)) => { @@ -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)?;