diff --git a/crates/cxx-qt-gen/src/parser/inherit.rs b/crates/cxx-qt-gen/src/parser/inherit.rs index 95649dced..d431e9382 100644 --- a/crates/cxx-qt-gen/src/parser/inherit.rs +++ b/crates/cxx-qt-gen/src/parser/inherit.rs @@ -9,7 +9,7 @@ use crate::parser::{ use crate::{ naming::Name, parser::parameter::ParsedFunctionParameter, - syntax::{attribute::attribute_take_path, expr::expr_to_string, safety::Safety}, + syntax::{attribute::attribute_take_path, safety::Safety}, }; use quote::format_ident; use syn::{Attribute, ForeignItemFn, Ident, Result}; @@ -45,25 +45,20 @@ impl ParsedInheritedMethod { let docs = separate_docs(&mut method); let invokable_fields = extract_common_fields(&method, docs)?; - let mut name = - Name::from_rust_ident_and_attrs(&method.sig.ident, &method.attrs, None, None)?; + // This block seems unnecessary but since attrs are passed through on generator/rust/inherit.rs a duplicate attr would occur without it + attribute_take_path(&mut method.attrs, &["cxx_name"]); - // This block seems unnecessary but removing it causes one cxx_name attr in test_outputs to lose the CxxQtInherit suffix - if let Some(attr) = attribute_take_path(&mut method.attrs, &["cxx_name"]) { - name = name.with_cxx_name(expr_to_string(&attr.meta.require_name_value()?.value)?); - } - - Ok(Self::from_invokable_fields(invokable_fields, method, name)) + Ok(Self::from_invokable_fields(invokable_fields, method)) } - fn from_invokable_fields(fields: InvokableFields, method: ForeignItemFn, name: Name) -> Self { + fn from_invokable_fields(fields: InvokableFields, method: ForeignItemFn) -> Self { Self { method, qobject_ident: fields.qobject_ident, mutable: fields.mutable, safe: fields.safe, parameters: fields.parameters, - name, + name: fields.name, docs: fields.docs, } } diff --git a/crates/cxx-qt-gen/src/parser/method.rs b/crates/cxx-qt-gen/src/parser/method.rs index f378240ea..3b346ae4c 100644 --- a/crates/cxx-qt-gen/src/parser/method.rs +++ b/crates/cxx-qt-gen/src/parser/method.rs @@ -70,9 +70,7 @@ impl ParsedMethod { let docs = separate_docs(&mut method); let invokable_fields = extract_common_fields(&method, docs)?; - let name = Name::from_rust_ident_and_attrs(&method.sig.ident, &method.attrs, None, None)?; - - if name.namespace().is_some() { + if invokable_fields.name.namespace().is_some() { return Err(Error::new_spanned( method.sig.ident, "Methods / QInvokables cannot have a namespace attribute", @@ -90,14 +88,13 @@ impl ParsedMethod { ParsedQInvokableSpecifiers::Virtual, ] { if attribute_take_path(&mut method.attrs, specifier.as_str_slice()).is_some() { - specifiers.insert(specifier); + specifiers.insert(specifier); // Should a fn be able to be Override AND Virtual? } } Ok(ParsedMethod::from_invokable_fields( invokable_fields, method, - name, specifiers, is_qinvokable, )) @@ -106,7 +103,6 @@ impl ParsedMethod { fn from_invokable_fields( fields: InvokableFields, method: ForeignItemFn, - name: Name, specifiers: HashSet, is_qinvokable: bool, ) -> Self { @@ -118,7 +114,7 @@ impl ParsedMethod { parameters: fields.parameters, specifiers, is_qinvokable, - name, + name: fields.name, docs: fields.docs, } } diff --git a/crates/cxx-qt-gen/src/parser/mod.rs b/crates/cxx-qt-gen/src/parser/mod.rs index 5730d7e18..4c2ac9a45 100644 --- a/crates/cxx-qt-gen/src/parser/mod.rs +++ b/crates/cxx-qt-gen/src/parser/mod.rs @@ -54,6 +54,7 @@ pub struct InvokableFields { mutable: bool, parameters: Vec, safe: bool, + name: Name, docs: Vec, } @@ -69,11 +70,14 @@ pub fn extract_common_fields( let parameters = ParsedFunctionParameter::parse_all_ignoring_receiver(&method.sig)?; let safe = method.sig.unsafety.is_none(); + let name = Name::from_rust_ident_and_attrs(&method.sig.ident, &method.attrs, None, None)?; + Ok(InvokableFields { qobject_ident, mutable, parameters, safe, + name, docs, }) } diff --git a/crates/cxx-qt-gen/src/parser/signals.rs b/crates/cxx-qt-gen/src/parser/signals.rs index 1a12c2c27..908634e30 100644 --- a/crates/cxx-qt-gen/src/parser/signals.rs +++ b/crates/cxx-qt-gen/src/parser/signals.rs @@ -89,9 +89,7 @@ impl ParsedSignal { let docs = separate_docs(&mut method); let invokable_fields = extract_common_fields(&method, docs)?; - let name = Name::from_rust_ident_and_attrs(&method.sig.ident, &method.attrs, None, None)?; - - if name.namespace().is_some() { + if invokable_fields.name.namespace().is_some() { return Err(Error::new_spanned( method.sig.ident, "Signals cannot have a namespace attribute", @@ -115,7 +113,6 @@ impl ParsedSignal { Ok(Self::from_invokable_fields( invokable_fields, method, - name, inherit, private, )) @@ -124,7 +121,6 @@ impl ParsedSignal { fn from_invokable_fields( fields: InvokableFields, method: ForeignItemFn, - name: Name, inherit: bool, private: bool, ) -> Self { @@ -134,7 +130,7 @@ impl ParsedSignal { mutable: fields.mutable, safe: fields.safe, parameters: fields.parameters, - name, + name: fields.name, inherit, private, docs: fields.docs,