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

gtk! macro produces code flagged by clippy::field_reassign_with_default #75

Open
meteficha opened this issue Jan 13, 2021 · 1 comment

Comments

@meteficha
Copy link
Contributor

The test case is already committed, clippy will complain about examples/todomvc/src/app.rs:

error: field assignment outside of initializer for an instance created with Default::default()
Error:    --> examples/todomvc/src/app.rs:66:9
    |
66  | /         gtk! {
67  | |             <Box spacing=10 orientation=Orientation::Vertical>
68  | |                 <Box spacing=10 orientation=Orientation::Horizontal Box::expand=false>
69  | |                     <Button image="edit-select-all" relief=ReliefStyle::Half
...   |
99  | |             </Box>
100 | |         }
    | |_________^
    |
    = note: `-D clippy::field-reassign-with-default` implied by `-D warnings`
note: consider initializing the variable with `radio::Radio<app::Filter> { active: #[proc_macro_hack(support_nested)]
pub use vgtk_macros::gtk, ..Default::default() }` and removing relevant reassignments
   --> examples/todomvc/src/app.rs:66:9
    |
66  | /         gtk! {
67  | |             <Box spacing=10 orientation=Orientation::Vertical>
68  | |                 <Box spacing=10 orientation=Orientation::Horizontal Box::expand=false>
69  | |                     <Button image="edit-select-all" relief=ReliefStyle::Half
...   |
99  | |             </Box>
100 | |         }
    | |_________^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

This was found by an unrelated PR (#73). One can silence the warning at the call site (3054df9), but that's not great. @meteficha couldn't find how to make the macro generate a silencing pragma that clippy would respect.

@meteficha
Copy link
Contributor Author

The problem lies in macros/src/gtk.rs, function expand_component. It's written as:

pub fn expand_component(gtk: &GtkComponent) -> TokenStream {
    let name = to_stream(&gtk.name);
    let mut out = quote!(
        use vgtk::{Component, vnode::VComponent, vnode::PropTransform};
        let mut vcomp = VComponent::new::<#name>();
        let mut props = <#name as Component>::Properties::default();
    );

    ...
    // Add lines modifying `props` to `out`. 
    ...

    quote!({
        #out
        vcomp.set_props::<#name>(props);
        VNode::Component(vcomp)
    })
}

Clippy doesn't like that we have a mut props set to default then changed. It's a silly complaint because it's much harder to generate code that doesn't use default here. I've tried adding #![allow(clippy::field_reassign_with_default)] to the generated code in a few ways, but clippy seemed to always ignore it.

meteficha added a commit to meteficha/vgtk that referenced this issue Jan 13, 2021
This reverts commit 3054df9,
as requested by @pepijndevos [1].  A new issue has been opened
to keep track of it, instead.

[1] bodil#73 (comment)
[2] bodil#75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant