From e8fe2f0bc0adb24bc6e43d6877fdf56610dd647a Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Mon, 13 Nov 2023 08:57:02 +0100 Subject: [PATCH] Remove check for #[function_component] --- src/autoprops.rs | 43 +++++------------ .../function_component_attr/autoprops-fail.rs | 7 --- .../autoprops-fail.stderr | 46 ++++++++----------- 3 files changed, 32 insertions(+), 64 deletions(-) diff --git a/src/autoprops.rs b/src/autoprops.rs index 5126a7b..d62ba7b 100644 --- a/src/autoprops.rs +++ b/src/autoprops.rs @@ -26,42 +26,23 @@ impl syn::parse::Parse for Autoprops { let mut component_name = item_fn.sig.ident.clone(); - attrs - .iter() - .find(|attr| { - match &attr.meta { - syn::Meta::Path(path) => { - if let Some(last_segment) = path.segments.last() { - if last_segment.ident == "function_component" { - return true; - } - } - } - syn::Meta::List(syn::MetaList { path, tokens, .. }) => { - if let Some(last_segment) = path.segments.last() { - if last_segment.ident == "function_component" { - if let Ok(attr) = - syn::parse2::(tokens.clone()) - { - if let Some(name) = attr.component_name { - component_name = name; - } + for attr in attrs { + match &attr.meta { + syn::Meta::List(syn::MetaList { path, tokens, .. }) => { + if let Some(last_segment) = path.segments.last() { + if last_segment.ident == "function_component" { + if let Ok(attr) = syn::parse2::(tokens.clone()) { + if let Some(name) = attr.component_name { + component_name = name; } - return true; } + break; } } - _ => {} } - false - }) - .ok_or_else(|| { - syn::Error::new_spanned( - sig, - "could not find #[function_component] attribute in function declaration \ - (#[autoprops] must be placed *before* #[function_component])", - ) - })?; + _ => {} + } + } for input in &sig.inputs { if let syn::FnArg::Typed(syn::PatType { pat, .. }) = input { diff --git a/tests/function_component_attr/autoprops-fail.rs b/tests/function_component_attr/autoprops-fail.rs index f8d98ad..f426292 100644 --- a/tests/function_component_attr/autoprops-fail.rs +++ b/tests/function_component_attr/autoprops-fail.rs @@ -10,13 +10,6 @@ fn CantAcceptReceiver(&self, b: bool) -> Html { } } -#[autoprops] -fn not_a_function_component(b: bool) -> Html { - html! { -

{b}

- } -} - #[function_component(WrongAttrsOrder)] #[autoprops] fn wrong_attrs_order(b: bool) -> Html { diff --git a/tests/function_component_attr/autoprops-fail.stderr b/tests/function_component_attr/autoprops-fail.stderr index e8394c1..1d23b88 100644 --- a/tests/function_component_attr/autoprops-fail.stderr +++ b/tests/function_component_attr/autoprops-fail.stderr @@ -4,69 +4,63 @@ error: function components can't accept a receiver 7 | fn CantAcceptReceiver(&self, b: bool) -> Html { | ^^^^^ -error: could not find #[function_component] attribute in function declaration (#[autoprops] must be placed *before* #[function_component]) - --> tests/function_component_attr/autoprops-fail.rs:14:1 - | -14 | fn not_a_function_component(b: bool) -> Html { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error: expected a reference to a `Properties` type (try: `&bool`) - --> tests/function_component_attr/autoprops-fail.rs:22:25 + --> tests/function_component_attr/autoprops-fail.rs:15:25 | -22 | fn wrong_attrs_order(b: bool) -> Html { +15 | fn wrong_attrs_order(b: bool) -> Html { | ^^^^ error: expected identifier, found keyword `let` - --> tests/function_component_attr/autoprops-fail.rs:29:22 + --> tests/function_component_attr/autoprops-fail.rs:22:22 | -29 | #[function_component(let)] +22 | #[function_component(let)] | ^^^ error: cannot use `_` as field name - --> tests/function_component_attr/autoprops-fail.rs:64:21 + --> tests/function_component_attr/autoprops-fail.rs:57:21 | -64 | fn InvalidFieldName(_: u32) -> Html { +57 | fn InvalidFieldName(_: u32) -> Html { | ^ error[E0412]: cannot find type `CompPrivateTest` in this scope - --> tests/function_component_attr/autoprops-fail.rs:86:22 + --> tests/function_component_attr/autoprops-fail.rs:79:22 | -86 | let _ = html! { }; +79 | let _ = html! { }; | ^^^^^^^^^^^^^^^ not found in this scope | note: struct `crate::private_module::CompPrivateTest` exists but is inaccessible - --> tests/function_component_attr/autoprops-fail.rs:72:5 + --> tests/function_component_attr/autoprops-fail.rs:65:5 | -72 | #[::yew::function_component(CompPrivateTest)] +65 | #[::yew::function_component(CompPrivateTest)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible = note: this error originates in the attribute macro `::yew::function_component` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `NotClonable: ImplicitClone` is not satisfied - --> tests/function_component_attr/autoprops-fail.rs:41:19 + --> tests/function_component_attr/autoprops-fail.rs:34:19 | -39 | #[autoprops] +32 | #[autoprops] | ------------ required by a bound introduced by this call -40 | #[function_component] -41 | fn TypeIsNotClone(stuff: NotClonable) -> Html { +33 | #[function_component] +34 | fn TypeIsNotClone(stuff: NotClonable) -> Html { | ^^^^^ expected an implementor of trait `ImplicitClone` | help: consider borrowing here | -41 | fn TypeIsNotClone(&stuff: NotClonable) -> Html { +34 | fn TypeIsNotClone(&stuff: NotClonable) -> Html { | + error[E0369]: binary operation `==` cannot be applied to type `NotPartialEq` - --> tests/function_component_attr/autoprops-fail.rs:55:30 + --> tests/function_component_attr/autoprops-fail.rs:48:30 | -55 | fn TypeIsNotPartialEq(stuff: NotPartialEq) -> Html { +48 | fn TypeIsNotPartialEq(stuff: NotPartialEq) -> Html { | ^^^^^^^^^^^^ | note: an implementation of `PartialEq<_>` might be missing for `NotPartialEq` - --> tests/function_component_attr/autoprops-fail.rs:49:1 + --> tests/function_component_attr/autoprops-fail.rs:42:1 | -49 | struct NotPartialEq(u32); +42 | struct NotPartialEq(u32); | ^^^^^^^^^^^^^^^^^^^ must implement `PartialEq<_>` help: consider annotating `NotPartialEq` with `#[derive(PartialEq)]` | -49 | #[derive(PartialEq)] +42 | #[derive(PartialEq)] |