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

Fixes clippy warnings #275

Merged
merged 2 commits into from Mar 10, 2021
Merged

Fixes clippy warnings #275

merged 2 commits into from Mar 10, 2021

Conversation

sanpii
Copy link
Contributor

@sanpii sanpii commented Mar 7, 2021

Fixes #239 & #254

This PR is incomplete, there is still 4 warnings:

    Checking relm-derive v0.21.0 (/home/sanpi/sources/relm/relm-derive)                                                                                          [5/74]
warning: large size difference between variants
  --> src/gen/parser.rs:88:5
   |
88 |     Return(Expr, Expr),
   |     ^^^^^^^^^^^^^^^^^^ this variant is 560 bytes
   |
   = note: `#[warn(clippy::large_enum_variant)]` on by default
note: and the second-largest variant is 280 bytes:
  --> src/gen/parser.rs:87:5
   |
87 |     CallReturn(Expr),
   |     ^^^^^^^^^^^^^^^^
help: consider boxing the large fields to reduce the total size of the enum
  --> src/gen/parser.rs:88:5
   |
88 |     Return(Expr, Expr),
   |     ^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant

warning: this function has too many arguments (8/7)
   --> src/gen/parser.rs:137:5
    |
137 | /     fn new_gtk(widget: GtkWidget, typ: Path, init_parameters: Vec<Expr>, children: Vec<Widget>,
138 | |         properties: HashMap<Ident, Expr>, child_properties: ChildProperties, child_events: ChildEvents,
139 | |         nested_views: HashMap<Ident, Widget>) -> Self
    | |_____________________________________________________^
    |
    = note: `#[warn(clippy::too_many_arguments)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments

warning: this function has too many arguments (8/7)
   --> src/gen/parser.rs:160:5
    |
160 | /     fn new_relm(widget: RelmWidget, typ: Path, init_parameters: Vec<Expr>, children: Vec<Widget>,
161 | |         properties: HashMap<Ident, Expr>, child_properties: ChildProperties, child_events: ChildEvents,
162 | |         nested_views: HashMap<Ident, Widget>) -> Self
    | |_____________________________________________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments

warning: very complex type used. Consider factoring parts into `type` definitions
  --> src/gen/generator.rs:65:70
   |
65 | ...driver: &mut Driver) -> (TokenStream, HashMap<Ident, Path>, HashMap<Ident, Path>, HashSet<Ident>, TokenStream) {
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(clippy::type_complexity)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity

warning: 4 warnings emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.50s

I don’t know how fix that.

@antoyo
Copy link
Owner

antoyo commented Mar 8, 2021

For the first warning, I guess it would be safer to Box the Expr in the variant Return to avoid a stack overflow in some cases.

For the functions with too many parameters, I'd just ignore them, as these are initializing structs with many fields anyway, so adding #[allow(clippy::too_many_arguments)] should do.

For the last error (src/gen/generator.rs:65:70), just make the return type be a struct instead of a tuple.

Also, it would be nice to run clippy somewhere in the CI.

Thanks for looking into this!

@sanpii
Copy link
Contributor Author

sanpii commented Mar 9, 2021

For the first warning, I guess it would be safer to Box the Expr in the variant Return to avoid a stack overflow in some cases.

Done, but destructuring Box isn’t easy as a tuple.

For the functions with too many parameters, I'd just ignore them, as these are initializing structs with many fields anyway, so adding #[allow(clippy::too_many_arguments)] should do.

Ok, done.

For the last error (src/gen/generator.rs:65:70), just make the return type be a struct instead of a tuple.

I just created a type to limit API breaking. Why the gen function is public? Public for crate is not enough? If you are ok, I can write another PR to restrict function visibility and change its return struct.

Also, it would be nice to run clippy somewhere in the CI.

Done.

@sanpii sanpii marked this pull request as ready for review March 9, 2021 08:44
@antoyo
Copy link
Owner

antoyo commented Mar 9, 2021

Yep, the visibility can be crate.

where WIDGET: Widget + WidgetTest + 'static,
WIDGET::Msg: DisplayVariant + 'static,
{
gtk::init().map_err(|_| ())?;
gtk::init()?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.github/workflows/CI.yml Outdated Show resolved Hide resolved
Copy link
Owner

@antoyo antoyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed a few things in the first review.

src/core/mod.rs Outdated Show resolved Hide resolved
relm-derive/src/gen/mod.rs Show resolved Hide resolved
Copy link
Owner

@antoyo antoyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I guess we could run clippy on the examples, but that probably requires fixing the code generation, so let's stop here for this PR.

Ready to merge?

@sanpii
Copy link
Contributor Author

sanpii commented Mar 9, 2021

Ready to merge?

Yes, it’s ok for me.

@sanpii
Copy link
Contributor Author

sanpii commented Mar 10, 2021

I just created a type to limit API breaking. Why the gen function is public? Public for crate is not enough? If you are ok, I can write another PR to restrict function visibility and change its return struct.

Actually pub items is not really public (proc-macro lib forbids pub items other than proc macro). So I created a struct type for this return type.

@antoyo antoyo merged commit 90b54ff into antoyo:master Mar 10, 2021
@sanpii sanpii deleted the clippy branch March 10, 2021 21:08
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

Successfully merging this pull request may close these issues.

Fix clippy warnings
2 participants