Skip to content

Commit 6e804b6

Browse files
committed
It's nicer to have the check that the class is there yet earlier as it's state related.
It's still going to need revision later as it depends on state modification to work. The class should only be modified once it is explicitly registered.
1 parent 41eced9 commit 6e804b6

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

crates/macros/src/impl_.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,13 @@ pub enum PropAttrTy {
9696
}
9797

9898
// note: this takes a mutable argument as it mutates a class
99-
fn prepare(
100-
args: AttrArgs,
101-
input: ItemImpl,
102-
classes: &mut HashMap<String, Class>,
103-
) -> Result<TokenStream> {
99+
fn prepare(args: AttrArgs, input: ItemImpl, class: &mut Class) -> Result<TokenStream> {
104100
let ItemImpl { self_ty, items, .. } = input;
105-
let class_name = self_ty.to_token_stream().to_string();
106101

107102
if input.trait_.is_some() {
108103
bail!("This macro cannot be used on trait implementations.");
109104
}
110105

111-
let class = classes.get_mut(&class_name).ok_or_else(|| {
112-
anyhow!(
113-
"You must use `#[php_class]` on the struct before using this attribute on the impl."
114-
)
115-
})?;
116-
117106
let tokens = items
118107
.into_iter()
119108
.map(|item| {
@@ -185,7 +174,15 @@ pub fn parser(args: AttributeArgs, input: ItemImpl) -> Result<TokenStream> {
185174
);
186175
}
187176

188-
prepare(args, input, &mut state.classes)
177+
let class_name = input.self_ty.to_token_stream().to_string();
178+
179+
let class = state.classes.get_mut(&class_name).ok_or_else(|| {
180+
anyhow!(
181+
"You must use `#[php_class]` on the struct before using this attribute on the impl."
182+
)
183+
})?;
184+
185+
prepare(args, input, class)
189186
}
190187

191188
pub fn parse_attribute(attr: &Attribute) -> Result<Option<ParsedAttribute>> {

0 commit comments

Comments
 (0)