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

New stack macro implementation triggers clippy::toplevel_ref_arg warning #1422

Open
dsemi opened this issue Jun 28, 2024 · 6 comments
Open

Comments

@dsemi
Copy link

dsemi commented Jun 28, 2024

This line triggers the clippy::toplevel_ref_arg warning for users of stack!.

Example warning:

warning: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead
  --> src/main.rs:35:15
   |
35 |       let rhs = stack![ bp.cross(&bv) - ap.cross(&av);
   |  _______________^
36 | |                       cp.cross(&cv) - ap.cross(&av) ];
   | |_____________________________________________________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#toplevel_ref_arg
   = note: `#[warn(clippy::toplevel_ref_arg)]` on by default
   = note: this warning originates in the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info)
@Andlon
Copy link
Collaborator

Andlon commented Jun 28, 2024

Uhm, does clippy normally give warnings from code generated by macros in external crates? That seems... excessive? Did you enable any particular options?

@dsemi
Copy link
Author

dsemi commented Jun 28, 2024

It seems so: rust-lang/rust-clippy#702. I don't understand why that decision was made.

@Andlon
Copy link
Collaborator

Andlon commented Jun 30, 2024

This comment suggests that it's due to our use of spans in the stack! macro to improve error messages. We should fix this by just plastering #[allow(clippy::all)] in the macro-generated code.

I'm not sure off the top of my head if we can put these attributes on code blocks though (not a function/impl block).

@danieleades
Copy link

We should fix this by just plastering #[allow(clippy::all)] in the macro-generated code.

I would absolutely not do that. That will suppress all future clippy lints, some of which might be useful.

i think the (reasonable) options are:

  1. address the lint
  2. suppress specifically this lint in the smallest possible scope
  3. suppress all lints, but have CI in this repo that would catch new clippy warnings in similar code

I'm not even sure how option 3. would work to be honest.

@Andlon
Copy link
Collaborator

Andlon commented Oct 2, 2024

@danieleades: appreciate your input. However, in my 8 years of working with Rust, I've never seen clippy actually point out a real problem or bug, but I've seen plenty of energy and time spent by maintainers and contributors fixing clippy complaints. I don't consider it likely that clippy will uncover an actual bug in the future inside this generated code. I personally find it a better trade-off to just ignore clippy entirely within the generated code, so we don't land back into the same situation if/when clippy gets a new lint that the generated code may trigger.

@danieleades
Copy link

I've never seen clippy actually point out a real problem or bug

I absolutely have. Though generally related to (ab)use of static items, synchronisation primitives, etc. There's nothing like that in this code so I definitely take your point

I've seen plenty of energy and time spent by maintainers and contributors fixing clippy complaints

yep.

I had a look at the code for stack! and it's not doing anything wild, so while suppressing all lints is an awfully big hammer, it's possibly justifiable here

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

3 participants