Skip to content

Commit

Permalink
Remove check for #[function_component]
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton committed Nov 13, 2023
1 parent e323bee commit e8fe2f0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 64 deletions.
43 changes: 12 additions & 31 deletions src/autoprops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FunctionComponentName>(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::<FunctionComponentName>(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 {
Expand Down
7 changes: 0 additions & 7 deletions tests/function_component_attr/autoprops-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ fn CantAcceptReceiver(&self, b: bool) -> Html {
}
}

#[autoprops]
fn not_a_function_component(b: bool) -> Html {
html! {
<p>{b}</p>
}
}

#[function_component(WrongAttrsOrder)]
#[autoprops]
fn wrong_attrs_order(b: bool) -> Html {
Expand Down
46 changes: 20 additions & 26 deletions tests/function_component_attr/autoprops-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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! { <CompPrivateTest /> };
79 | let _ = html! { <CompPrivateTest /> };
| ^^^^^^^^^^^^^^^ 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)]
|

0 comments on commit e8fe2f0

Please sign in to comment.