Skip to content

Commit a38f0cd

Browse files
committed
Use TypeWithGenerics in EvaluatedCheckEntry
1 parent d7bb675 commit a38f0cd

3 files changed

Lines changed: 34 additions & 24 deletions

File tree

crates/macros/cgp-macro-core/src/types/check_components/entry.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use syn::parse::{Parse, ParseStream};
22
use syn::spanned::Spanned;
33
use syn::token::Colon;
44

5-
use crate::types::check_components::{CheckKey, CheckValue, EvaluatedCheckEntry};
6-
use crate::types::generics::ImplGenerics;
5+
use crate::types::check_components::{CheckKey, CheckValue, EvaluatedCheckEntry, TypeWithGenerics};
76

87
pub struct CheckEntry {
98
pub key: CheckKey,
@@ -24,10 +23,9 @@ impl CheckEntry {
2423

2524
if values.is_empty() {
2625
entries.push(EvaluatedCheckEntry {
27-
component_type: component_type.clone(),
28-
component_params: None,
26+
key: component_type.clone(),
27+
value: None,
2928
span: component_type.span(),
30-
generics: ImplGenerics::default(),
3129
})
3230
} else {
3331
let component_params_count = values.len();
@@ -43,19 +41,20 @@ impl CheckEntry {
4341
};
4442

4543
entries.push(EvaluatedCheckEntry {
46-
component_type: component_type.clone(),
47-
component_params: Some(component_param_type.clone()),
44+
key: component_type.clone(),
45+
value: Some(TypeWithGenerics {
46+
ty: component_param_type.clone(),
47+
generics: component_param_generics.clone(),
48+
}),
4849
span,
49-
generics: component_param_generics.clone(),
5050
})
5151
}
5252
}
5353
} else {
5454
entries.push(EvaluatedCheckEntry {
55-
component_type: component_type.clone(),
56-
component_params: None,
55+
key: component_type.clone(),
56+
value: None,
5757
span: component_type.span(),
58-
generics: ImplGenerics::default(),
5958
})
6059
}
6160
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use proc_macro2::Span;
22
use syn::Type;
33

4-
use crate::types::generics::ImplGenerics;
4+
use crate::types::check_components::TypeWithGenerics;
55

66
pub struct EvaluatedCheckEntry {
7-
pub component_type: Type,
8-
pub component_params: Option<Type>,
7+
pub key: Type,
8+
pub value: Option<TypeWithGenerics>,
99
pub span: Span,
10-
pub generics: ImplGenerics,
1110
}

crates/macros/cgp-macro-lib/src/check_components/derive.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use cgp_macro_core::functions::merge_generics;
2-
use cgp_macro_core::types::check_components::{CheckComponentsTable, EvaluatedCheckEntry};
2+
use cgp_macro_core::types::check_components::{
3+
CheckComponentsTable, EvaluatedCheckEntry, TypeWithGenerics,
4+
};
35
use quote::quote;
46
use syn::punctuated::Punctuated;
57
use syn::token::Comma;
@@ -27,22 +29,26 @@ pub fn derive_check_components(
2729
})?;
2830

2931
for EvaluatedCheckEntry {
30-
component_type,
31-
component_params,
32+
key: component_type,
33+
value: component_params,
3234
span,
33-
generics: check_generics,
3435
} in spec.check_entries.eval()
3536
{
3637
// Override the span of the context type so that any unsatisfied constraint
3738
// error is highlighted on the component type instead
3839
let context_type = override_span(&span, context_type)?;
3940

40-
let component_param = component_params.as_ref().unwrap_or(&unit);
41+
let TypeWithGenerics {
42+
ty: component_param,
43+
generics: check_generics,
44+
} = component_params.unwrap_or_else(|| unit.clone().into());
4145

4246
let generics = merge_generics(&check_generics.generics, &impl_generics.generics);
4347

48+
let impl_generics = generics.split_for_impl().0;
49+
4450
let item_impl: ItemImpl = parse2(quote! {
45-
impl #generics
51+
impl #impl_generics
4652
#trait_name < #component_type, #component_param >
4753
for #context_type
4854
#where_clause
@@ -72,12 +78,18 @@ pub fn derive_check_provider(
7278
})?;
7379

7480
for EvaluatedCheckEntry {
75-
component_type,
76-
component_params,
81+
key: component_type,
82+
value: component_params,
7783
..
7884
} in spec.check_entries.eval()
7985
{
80-
let component_param = component_params.as_ref().unwrap_or(&unit);
86+
let TypeWithGenerics {
87+
ty: component_param,
88+
generics: check_generics,
89+
} = component_params.unwrap_or_else(|| unit.clone().into());
90+
91+
let generics = merge_generics(&check_generics.generics, &impl_generics.generics);
92+
let impl_generics = generics.split_for_impl().0;
8193

8294
for provider in providers {
8395
let item_impl: ItemImpl = parse2(quote! {

0 commit comments

Comments
 (0)