-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #6305 - smoelius:master, r=flip1995
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`]
- Loading branch information
Showing
14 changed files
with
139 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![warn(clippy::let_underscore_drop)] | ||
|
||
struct Droppable; | ||
|
||
impl Drop for Droppable { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
fn main() { | ||
let unit = (); | ||
let boxed = Box::new(()); | ||
let droppable = Droppable; | ||
let optional = Some(Droppable); | ||
|
||
let _ = (); | ||
let _ = Box::new(()); | ||
let _ = Droppable; | ||
let _ = Some(Droppable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error: non-binding `let` on a type that implements `Drop` | ||
--> $DIR/let_underscore_drop.rs:16:5 | ||
| | ||
LL | let _ = Box::new(()); | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::let-underscore-drop` implied by `-D warnings` | ||
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` | ||
|
||
error: non-binding `let` on a type that implements `Drop` | ||
--> $DIR/let_underscore_drop.rs:17:5 | ||
| | ||
LL | let _ = Droppable; | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` | ||
|
||
error: non-binding `let` on a type that implements `Drop` | ||
--> $DIR/let_underscore_drop.rs:18:5 | ||
| | ||
LL | let _ = Some(Droppable); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters