this post was submitted on 13 Mar 2024
11 points (100.0% liked)
Rust
5931 readers
15 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I'm not sure if the rules are different with macros, I've never written one but this lint is generally caused because you set a var to a value and then overwrite that value before you use it. e.g.
let mut a = 1; a = 2; println!("{}", a);
This will throw the same warning because 1 is never used, this could've just been:
let a = 2; println!("{}", a);
So first I'd double check that I NEED last at all. Maybe try:
cargo clippy
See if it can tell you how to fix it.
If that doesn't work, it's sometimes necessary to skip certain lints. E.g. if you make a library, most of the code will be flagged as dead code because it isn't used and you can use an #[allow(dead_code)] to stop the linter warning. You might be able to use #[allow(this_linting_rule)].
Hope something here helps.
Clippy didn't tell anything about the macro.
To put #[allow(this_linting_rule)] like this:
I got error[E0658]: attributes on expressions are experimental.
To put it like this:
It doesn't work.
I would expect the following to work
It doesn't work, at least, on rustc 1.75.
I misunderstood the reason the error was showing up. It seems like using a closure fixes it though.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=247730dfc1fbeeb8e2263ea3b95d6c0a
Thank you. This works!