Conversation
|
Lintcheck changes for 3a164cc
This comment will be updated if you push new changes |
This comment has been minimized.
This comment has been minimized.
| /// ``` | ||
| #[clippy::version = "1.95.0"] | ||
| pub MUST_USE_WITHOUT_NOTE, | ||
| style, |
There was a problem hiding this comment.
Note that restriction would probably be a better choice for such a lint.
There was a problem hiding this comment.
Thanks for the suggestion. Can you elaborate on why do you think so?
I am doubting it should be restriction, looking at the docs, they state "lints which prevent the use of Cargo features", while #[must_use] attribute could be used anywhere.
There was a problem hiding this comment.
Hm, but now I found another doc, which says different about this group. However, I am not sure this is applicable either
The
clippy::restrictiongroup contains lints that will restrict you from using certain parts of the Rust language. It is not recommended to enable the whole group, but rather cherry-pick lints that are useful for your code base and your use case.
Lints from this group will restrict you in some way. If you enable a restriction lint for your crate it is recommended to also fix code that this lint triggers on. However, those lints are really strict by design, and you might want to #[allow] them in some special cases, with a comment justifying that.
There was a problem hiding this comment.
This lint is restricting the use of #[must_use] unless it is accompanied with a message. This is an opiniated lint which, I think, belongs to restriction.
9dc4ba7 to
dd76a0b
Compare
dd76a0b to
3a164cc
Compare
|
r? @dswij rustbot has assigned @dswij. Use Why was this reviewer chosen?The reviewer was selected based on:
|
PR addresses proposal for adding a lint that warns about
#[must_use]attribute that lacks a note.Request for a help
I feel I need some opinions here. I stuck on dogfood tests after running
cargo test --test dogfood.The issue is that I received a lot of lint warnings regarding the
#[must_use]attribute without a note (which was what we wanted). However, the more I looked into them, the more I realized that most of the attributes do not make much sense. For example, they are set on getters and formatters. As I started deleting this attribute from these functions, I immediately received a "must_use_candidate" lint warning. One could argue that this is correct because if you call a "pure" function and don't use its result, you've done something wrong, so they're perfect candidates formust_use. On the other hand, setting this attribute on almost every function bloats the code and devalues lint. Adding a note "just because the function is pure" onmust_useworsens the situation even more.I ended up in a situation where I couldn't remove the "must_use" attribute without turning off the "must_use_candidate" lint. On the other hand, I feel it should be up to the developer to decide whether to mark a function as
#[must_use]or not, and it shouldn't be so formal. A computational-heavy function or the necessity to handle important state could be good reasons, but they shouldn't be the only formal reasons for function purity. As far as I can tell, the only situation prevented by "must_use_candidate" is calling a function without the "let = must_use_func()" assignment:must_use_func(). Other cases, such as assigning to a variable and not using it, are covered by other lints.I also found a standard library developers guide: when to add
#[must_use], which suggests "The #[must_use] attribute can be applied to types or functions when failing to explicitly consider them or their output is almost certainly a bug."So what do you think, should I fix all
must_useattributes adding some formal note, or should we reconsidermust_use_candidatelint?changelog: [
must_use_without_note]: add a lint that warns on#[must_use]attributes without a note