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

Add #[allow(clippy::*)] to the top-level items in codegen.rs #1207

Merged
merged 8 commits into from
Feb 10, 2019

Conversation

T5uku5hi
Copy link
Contributor

This PR it to fix issue #1200.

I added #[allow(clippy::*)] to the top-level items in codegen.rs, but I have a problem 😣
Running clippy after fixing, warnings remain print out.
I think I misunderstand how to fix.
Please tell me the correct fixing.

@fitzgen
Copy link
Member

fitzgen commented Jan 25, 2019

Hi @T5uku5hi, it looks like you've introduced some syntax errors in the macro-expanded code somewhere: https://travis-ci.com/rustwasm/wasm-bindgen/jobs/172934004#L585

Unfortunately, there isn't a super great way to debug syntax errors within macro-expanded code right now. The two best ways to debug this that I know of is to comment out half of your changes, test to see if the syntax error is there or not. Keep doing this and use a binary search to try and find the code that introduced the syntax errors.

Running clippy after fixing, warnings remain print out.

You're still seeing clippy warnings with this patch, and not the syntax errors that CI has? If so, can you share the output?

@T5uku5hi
Copy link
Contributor Author

@fitzgen
Thank you for your comment.
I fixed the code too much at once. I'm really sorry 😣

You're still seeing clippy warnings with this patch, and not the syntax errors that CI has? If so, can you share the output?

I got the same syntax error as the CI output result.
Here is the output.
errors_commit_e19306c.txt


I would like to consult you about next steps.
Here is the output result before my fixing.
errors_before_add_[#[allow(clippy)]].txt

At first, I'll focus on fixing to remove this warning according to your advice.

warning: this function has too many arguments (8/7)
    --> crates/js-sys/src/lib.rs:3832:15
     |
3832 | #[wasm_bindgen]
     |               ^
     |
     = 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

Is this next step correct?

@fitzgen
Copy link
Member

fitzgen commented Jan 28, 2019

If you want to try and pinpoint a single lint warning, https://github.com/dtolnay/cargo-expand might help. But I'm not 100% sure, since debugging proc-macro output is a bit suboptimal currently.

I suggest adding one #[allow(clippy::*)] at a time, and verifying that the example project builds after each one. Eventually all the #[allow(...)]s will be in place and you can push the code to this PR :)

@T5uku5hi
Copy link
Contributor Author

@fitzgen thank you so much for your advice.
I'll try it 😊

@T5uku5hi
Copy link
Contributor Author

T5uku5hi commented Feb 3, 2019

@fitzgen
I tried to add #[allow(clippy::*)] to lines as much as possible.
And then, I found error messages changed when I added #[allow(clippy::*)] to 902 line.
 
Before
errors_before_add_allow_clippy.txt
After
errors_after_add_allow_clippy.txt
 
I thought it seems a big step in fixing this issue, but I don't know what to do next 😣
Please advice me.

@fitzgen
Copy link
Member

fitzgen commented Feb 6, 2019

Are these errors from when you run cargo clippy in the example project?

@limira
Copy link
Contributor

limira commented Feb 6, 2019

Are these errors from when you run cargo clippy in the example project?

I think the answer is 'yes'. Here is an excerpt from errors_after_add_allow_clippy.txt

request-animation-frame $ cargo clippy
   Compiling wasm-bindgen-backend v0.2.33 (/Users/misakimakino/Works/clones/fork-wasm-bindgen/wasm-bindgen/crates/backend)
   Compiling wasm-bindgen-macro-support v0.2.33 (/Users/misakimakino/Works/clones/fork-wasm-bindgen/wasm-bindgen/crates/macro-support)
   Compiling wasm-bindgen-webidl v0.2.27 (/Users/misakimakino/Works/clones/fork-wasm-bindgen/wasm-bindgen/crates/webidl)
   Compiling wasm-bindgen-macro v0.2.33 (/Users/misakimakino/Works/clones/fork-wasm-bindgen/wasm-bindgen/crates/macro)
   Compiling web-sys v0.3.10 (/Users/misakimakino/Works/clones/fork-wasm-bindgen/wasm-bindgen/crates/web-sys)
    Checking wasm-bindgen v0.2.33 (/Users/misakimakino/Works/clones/fork-wasm-bindgen/wasm-bindgen)

@T5uku5hi
Copy link
Contributor Author

T5uku5hi commented Feb 6, 2019

@fitzgen
Yes.
When I run cargo clippy in request-animation-frame dir, these errors occurred.

@@ -899,6 +899,7 @@ impl TryToTokens for ast::ImportFunction {
abi_arguments.push(quote! { #exn_data_ptr: *mut u32 });
convert_ret = quote! { Ok(#convert_ret) };
exceptional_ret = quote! {
#[allow(clippy::*)]
Copy link
Member

Choose a reason for hiding this comment

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

Ah I see -- we should only add #[allow(clippy::*)] to things that are top-level items in the expanded code, not anything that is at the top of a quote! macro invocation, since it might take multiple quotes to build up a top-level item that we are emitting.

A good rule of thumb is that we should add it on each fn we define.

Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes!! I understand you said.
I tried to add #[allow(clippy::*)] to things that are top-level items at first,
but this code occurred another error like this.

error: expected one of `(`, `)`, `,`, or `=`, found `::`
  --> crates/backend/src/codegen.rs:15:15
   |
15 | #[allow(clippy::*)]
   |               ^^ expected one of `(`, `)`, `,`, or `=` here

error: unexpected token: `)`
  --> crates/backend/src/codegen.rs:15:18
   |
15 | #[allow(clippy::*)]
   |                  ^ unexpected token after this

error: aborting due to 2 previous errors

 
I found that I should use #[allow(clippy::drop_ref)] instead of #[allow(clippy::*)] when I read codes written by others 🧐💡
Finally, I fixed it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@T5uku5hi, did you try #![allow(clippy::all)]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@limira
Oh! I didn't try all instead of *.
I tried it just now and I well did it!

I'll add #[allow(clippy::all)] in all the top-level items.
Thank you for your kindness 😊

Copy link
Member

Choose a reason for hiding this comment

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

This is my bad, sorry!

For some reason I thought the syntax was allow(clippy::*) and it is actually allow(clippy::all) as @limira points out. Sorry about that!

@T5uku5hi
Copy link
Contributor Author

@fitzgen
I added #[allow(clippy::all)] to the top-level items in codegen.rs.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Wonderful! Thanks for sticking with this, and sorry again for the mixup!

@fitzgen fitzgen merged commit 499ae12 into rustwasm:master Feb 10, 2019
@fitzgen fitzgen added the TWiRaWA Nominate this PR for inclusion in the next issue of This Week in Rust and WebAssembly label Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TWiRaWA Nominate this PR for inclusion in the next issue of This Week in Rust and WebAssembly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants