-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 let_underscore_lock
lint
#5101
Conversation
be11c3d
to
7b1e678
Compare
I think it'd be nice to separate test files. |
Oh, and I forgot to ask your input about this: is there a good reason to not lint |
I cannot come up with one. When a guard is produced in any way, dropping it immediately is probably a mistake. This can be nicely checked with // Pseudocode ahead
expr_ty(init_expr).walk().any(|ty| GUARD_TYPES.any(|gty| match_ty(gty, ty))); |
I just thought, someone might use |
3bba1ad
to
103c74a
Compare
In that case, I think |
85a46b3
to
66f698c
Compare
@flip1995 from the documentation it seems like |
66f698c
to
9b88a2b
Compare
|
Oh, that's what you mean, gotcha |
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.
LGTM, only formatting left to do.
clippy_lints/src/let_underscore.rs
Outdated
span_lint_and_help( | ||
cx, | ||
LET_UNDERSCORE_LOCK, | ||
stmt.span, | ||
"non-binding let on a synchronization lock", | ||
"consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`" | ||
) |
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.
double indentation
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.
Why doesn't fmt do that?
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.
rustfmt currently only formats in some macros. The if_chain
macro is too complex, for rustfmt to format the code in it reliably.
f15b9aa
to
63ab7a5
Compare
@bors r+ Travis has currently problems, so I marked it as |
📌 Commit 63ab7a5 has been approved by |
add `let_underscore_lock` lint closes #1574 changelog: add `let_underscore_lock` lint I am not entirely sure about my docs/messages wording here, improvements are welcome
💥 Test timed out |
@bors retry |
add `let_underscore_lock` lint closes #1574 changelog: add `let_underscore_lock` lint I am not entirely sure about my docs/messages wording here, improvements are welcome
☀️ Test successful - checks-travis, status-appveyor |
I see this in my code now. Is that wrong ? |
This comment has been minimized.
This comment has been minimized.
Hm thinking more about this: With your let _ = SHARED_OBJECT.lock().map(|content: MutexGuard<impl Iterator<Item = _>>| { ... }); From the
So SHARED_OBJECT.lock().expect("..").map(|content: <Iterator>::Item>| { ... }) |
I had to check, I didn't write the code, it was just pointed to me by clippy (that's totally the point of clippy, eh! Thanks by the way). It seems the error case is actually ignored, like I wrote above. This is probably a bug in itself (or maybe not, I'll have to check the intent with the original authors, I guess). |
If it should be a bug of this lint, feel free to open an issue about it 👍 |
I don't think I'm qualified enough to decide if there is a bug or not :D I also found some So I think some of the |
Add `let_underscore_drop` This line generalizes `let_underscore_lock` (#5101) to warn about any initializer expression that implements `Drop`. So, for example, the following would generate a warning: ```rust struct Droppable; impl Drop for Droppable { fn drop(&mut self) {} } let _ = Droppable; ``` I tried to preserve the original `let_underscore_lock` functionality in the sense that the warning generated for ```rust let _ = mutex.lock(); ``` should be unchanged. *Please keep the line below* changelog: Add lint [`let_underscore_drop`]
closes #1574
changelog: add
let_underscore_lock
lintI am not entirely sure about my docs/messages wording here, improvements are welcome