-
-
Notifications
You must be signed in to change notification settings - Fork 75
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 lint: Inherent method #[must_use]
added
#283
New lint: Inherent method #[must_use]
added
#283
Conversation
I think this implementation has an interesting bug. The PR description describes this lint as Except, the baseline: pub struct Foo {};
impl Foo {
pub fn bar() {}
} current: pub enum Foo {
A,
}
impl Foo {
#[must_use]
pub fn bar() {}
} I predict that the current code will flag It would be great to add "true-positive" test cases for enum and union methods just like the existing ones for structs, even though the union ones won't be caught (opne an issue about this and link it in a comment, so we remember that it's okay to for that test output to change when we implement unions in the adapter). It would also be good to have "true-negative" test cases where structs/enums/unions get each other's names like this. With respect to fixing the lint query, there are two options:
|
That's a very interesting bug, I wasn't aware of the
The only "advantage" I can point out for now is that this would result in multiple smaller test crates, one per lint, instead of one big test crate handling all of the cases for one, common lint. But if the test crate turns out too large, we will be able to easily split it into smaller test cases and leave the common lint unchanged (I will keep it in mind to write the tests as easily splittable because of this). |
The best option was to use the hybrid approach mentioned here #282 (comment), so I already split the tests into relevant-named files. I also added a "test file pair" against the changed type false-positive scenario which was shown above. This is currently blocked on #149 & #292. If the lint was split into more specialized ones for @obi1kenobi considering the above, despite it requiring a bit more work with splitting the lint, I think it could in return make the workflow a lot smoother and faster (with #149 being rated as the hardest addition in #241, I am not sure if this is a good idea to block this PR on that issue). If you have nothing against it, I would proceed with this approach to thin out the #[must_use] issue as much as possible. |
I don't think I see why this is blocked on #149. That issue is required for representing the type of fields, function arguments, generics, etc. I'm confused why those are involved here. Are we not able to use the |
It is indeed not blocked, my reading has just fooled me on this bit
I applied the "when implemented" part to the whole sentence, that is |
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I'll apply my two tiny suggestions and merge.
After some testing it turned out it is not possible to have a single lint for both
Struct
andTrait
methods. Here is the reason:#[must_use]
and Trait method becomes#[must_use]
at the same time. The former method haspublic
visibility, the latter hasdefault
, while both Struct and Trait must havepublic
visibility.baseline
andcurrent
parts of the query. So we opt for method visibility to be eitherpublic
ordefault
, because otherwise we will miss some Struct or Trait methods.pub Struct Foo
and onepub Trait Bar
, that both have a method that becomes#[must_use]
. If we run the query that looks forpublic
ordefault
methods in bothbaseline
andcurrent
crates, the query will find matches for all 4 possible pairings, despite there being only 2 of them sensible to the user. To avoid this, the query would have to "on Struct look for a matching Struct, then for the matching method, on Trait look for a matching Trait, then for the matching method", which even if was possible would be begging to get split into 2 separate queries (at least I see it this way).baseline
orcurrent
version.And since we decided in #268 that there is no need for a lint that detects addition of
#[must_use]
for a method that is also moved to Trait, we eliminated the only cross-type case from the 3 possibilities I introduced in that PR and are left with:Struct method -> Struct #[must_use] method
, with the lintinherent_method_must_use_added
implemented in this PR,Trait method -> Trait #[must_use] method
, with the linttrait_method_must_use_added
, on which I am still working in New lint: Trait method#[must_use]
added #284.