Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

associated function build is private #1676

Closed
1 of 3 tasks
SOF3 opened this issue Jan 3, 2021 · 4 comments
Closed
1 of 3 tasks

associated function build is private #1676

SOF3 opened this issue Jan 3, 2021 · 4 comments
Labels

Comments

@SOF3
Copy link
Contributor

SOF3 commented Jan 3, 2021

Problem

HTML macro fails with the error associated function build is private.

error[E0624]: associated function `build` is private
   --> /home/sofe/.cargo/registry/src/github.com-1ecc6299db9ec823/yew-0.17.4/src/lib.rs:101:1
    |
101 |       #[proc_macro_hack(support_nested)]
    |       ^---------------------------------
    |       |
    |       in this expansion of `html!` (#1)
    |  _____in this macro invocation (#2)
    | |_____|
    | |
102 | |     pub use yew_macro::html;
    | |                           ^
    | |___________________________|
    | |___________________________private associated function
    |                             in this expansion of `proc_macro_call_0!` (#6)
    | 
   ::: /home/sofe/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro-nested-0.1.6/src/lib.rs:47:1
    |
47  |       macro_rules! dispatch {
    |  _____-
    | |_____|
    | |_____|
    | |
48  | |         (() $($bang:tt)*) => {
49  | |             $crate::count!($($bang)*)
    | |             ------------------------- in this macro invocation (#5)
50  | |         };
...   |
67  | |             $crate::dispatch!(($($rest)*) $($bang)*)
    | |             ----------------------------------------
    | |             |
    | |             in this macro invocation (#3)
    | |             in this macro invocation (#4)
68  | |         };
69  | |     }
    | |     -
    | |_____|
    | |_____in this expansion of `$crate::proc_macro_call_html!` (#2)
    | |_____in this expansion of `$crate::dispatch!` (#3)
    |       in this expansion of `$crate::dispatch!` (#4)
    | 
   ::: /home/sofe/proj/traffloat/target/debug/build/proc-macro-nested-54f78155b0ce2171/out/count.rs:3:1
    |
3   |     / macro_rules! count {
4   |     |     () => { proc_macro_call_0!() };
    |     |             -------------------- in this macro invocation (#6)
5   |     |     (!) => { proc_macro_call_1!() };
6   |     |     (!!) => { proc_macro_call_2!() };
...       |
71  |     |     };
72  |     | }
    |     |_- in this expansion of `$crate::count!` (#5)
    | 
   ::: client/src/app/mod.rs:32:28
    |
32  |                   State::Menu => html! {
    |  ________________________________-
33  | |                     <menu::Menu />
34  | |                 }
    | |_________________- in this macro invocation (#1)

Steps To Reproduce

I import use yew::prelude::*; with a submodule mod menu; with the code

            html! {
                <menu::Menu />
            }

with the Properties definition for Menu:

#[derive(Clone, Properties)]
struct Properties {
    #[prop_or("localhost".to_string())]
    address: String,
    #[prop_or(common::DEFAULT_PORT)]
    port: u16,
}

I cannot find this error anywhere, so I suppose I'm running into a corner case.

Environment:

  • Yew version: 0.17.4
  • Rust version: 1.49.0
  • Target, if relevant: cargo check on linux already fails
  • Build tool, if relevant: cargo check already fails
  • Web library: web-sys
  • OS, if relevant: ubuntu 20

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@SOF3 SOF3 added the bug label Jan 3, 2021
@SOF3
Copy link
Contributor Author

SOF3 commented Jan 3, 2021

cargo-expand gives

                    #[allow(dead_code)]
                    enum ProcMacroHack {
                        Nested = ("< menu :: Menu / >", 0).1,
                    }
                    ::yew::virtual_dom::VNode::from({
                        if false {}
                        :: yew :: virtual_dom :: VChild :: < menu :: Menu > :: new (< < menu :: Menu as :: yew :: html :: Component > :: Properties as :: yew :: html :: Properties > :: builder () . build () , :: yew :: html :: NodeRef :: default () , None)
                    })

@SOF3
Copy link
Contributor Author

SOF3 commented Jan 3, 2021

cargo-expand also shows

    impl PropertiesBuilder<PropertiesBuilderStep_build> {
        #[doc(hidden)]
        fn build(self) -> Properties {
            Properties {}
        }
    }
    impl ::yew::html::Properties for Properties {
        type Builder = PropertiesBuilder<PropertiesBuilderStep_build>;
        fn builder() -> Self::Builder {
            PropertiesBuilder {
                wrapped: ::std::boxed::Box::new(::std::default::Default::default()),
                _marker: ::std::marker::PhantomData,
            }
        }
    }

for the properties.
It appears that Properties::Builder::build() is declared as a fn build(self) without public visibility.
This is probably because my struct Properties is private.

But it is actually not necessary to make my struct Properties public, because it is only used as an associated type in the impl Component for Menu in the same module.

Should I send a PR that makes the build() function always pub?

@SOF3
Copy link
Contributor Author

SOF3 commented Jan 3, 2021

Never mind, this actually leads to E0446 even if the builder works.

@SOF3 SOF3 closed this as completed Jan 3, 2021
@jstarry
Copy link
Member

jstarry commented Jan 23, 2021

Ah yeah, appears that the properties magic only works with public properties types? Sorry you bumped into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants