use rustc_session::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! {
- /// **What it does:** Checks for `let _ = <expr>`
- /// where expr is #[must_use]
+ /// ### What it does
+ /// Checks for `let _ = <expr>` where expr is `#[must_use]`
///
- /// **Why is this bad?** It's better to explicitly
- /// handle the value of a #[must_use] expr
+ /// ### Why is this bad?
+ /// It's better to explicitly handle the value of a `#[must_use]`
+ /// expr
///
- /// **Known problems:** None.
- ///
- /// **Example:**
+ /// ### Example
/// ```rust
/// fn f() -> Result<u32, u32> {
/// Ok(0)
/// // is_ok() is marked #[must_use]
/// let _ = f().is_ok();
/// ```
+ #[clippy::version = "1.42.0"]
pub LET_UNDERSCORE_MUST_USE,
restriction,
"non-binding let on a `#[must_use]` expression"
}
declare_clippy_lint! {
- /// **What it does:** Checks for `let _ = sync_lock`
+ /// ### What it does
+ /// Checks for `let _ = sync_lock`.
+ /// This supports `mutex` and `rwlock` in `std::sync` and `parking_lot`.
///
- /// **Why is this bad?** This statement immediately drops the lock instead of
+ /// ### Why is this bad?
+ /// This statement immediately drops the lock instead of
/// extending its lifetime to the end of the scope, which is often not intended.
/// To extend lock lifetime to the end of the scope, use an underscore-prefixed
/// name instead (i.e. _lock). If you want to explicitly drop the lock,
/// `std::mem::drop` conveys your intention better and is less error-prone.
///
- /// **Known problems:** None.
- ///
- /// **Example:**
- ///
- /// Bad:
+ /// ### Example
/// ```rust,ignore
/// let _ = mutex.lock();
/// ```
///
- /// Good:
+ /// Use instead:
/// ```rust,ignore
/// let _lock = mutex.lock();
/// ```
+ #[clippy::version = "1.43.0"]
pub LET_UNDERSCORE_LOCK,
correctness,
"non-binding let on a synchronization lock"
}
declare_clippy_lint! {
- /// **What it does:** Checks for `let _ = <expr>`
+ /// ### What it does
+ /// Checks for `let _ = <expr>`
/// where expr has a type that implements `Drop`
///
- /// **Why is this bad?** This statement immediately drops the initializer
+ /// ### Why is this bad?
+ /// This statement immediately drops the initializer
/// expression instead of extending its lifetime to the end of the scope, which
/// is often not intended. To extend the expression's lifetime to the end of the
/// scope, use an underscore-prefixed name instead (i.e. _var). If you want to
/// explicitly drop the expression, `std::mem::drop` conveys your intention
/// better and is less error-prone.
///
- /// **Known problems:** None.
- ///
- /// **Example:**
- ///
- /// Bad:
- /// ```rust,ignore
- /// struct Droppable;
- /// impl Drop for Droppable {
- /// fn drop(&mut self) {}
- /// }
+ /// ### Example
+ /// ```rust
+ /// # struct DroppableItem;
/// {
- /// let _ = Droppable;
- /// // ^ dropped here
+ /// let _ = DroppableItem;
+ /// // ^ dropped here
/// /* more code */
/// }
/// ```
///
- /// Good:
- /// ```rust,ignore
+ /// Use instead:
+ /// ```rust
+ /// # struct DroppableItem;
/// {
- /// let _droppable = Droppable;
+ /// let _droppable = DroppableItem;
/// /* more code */
/// // dropped at end of scope
/// }
/// ```
+ #[clippy::version = "1.50.0"]
pub LET_UNDERSCORE_DROP,
pedantic,
"non-binding let on a type that implements `Drop`"
declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE, LET_UNDERSCORE_LOCK, LET_UNDERSCORE_DROP]);
-const SYNC_GUARD_PATHS: [&[&str]; 3] = [
+const SYNC_GUARD_PATHS: [&[&str]; 6] = [
&paths::MUTEX_GUARD,
&paths::RWLOCK_READ_GUARD,
&paths::RWLOCK_WRITE_GUARD,
+ &paths::PARKING_LOT_MUTEX_GUARD,
+ &paths::PARKING_LOT_RWLOCK_READ_GUARD,
+ &paths::PARKING_LOT_RWLOCK_WRITE_GUARD,
];
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {