@@ -35,6 +35,7 @@ declare_lint_pass! {
3535 DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME ,
3636 DEPRECATED_IN_FUTURE ,
3737 DEPRECATED_WHERE_CLAUSE_LOCATION ,
38+ DEREFERENCING_MUT_BINDING ,
3839 DUPLICATE_MACRO_ATTRIBUTES ,
3940 ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT ,
4041 ELIDED_LIFETIMES_IN_PATHS ,
@@ -1578,6 +1579,35 @@ declare_lint! {
15781579 "detect mut variables which don't need to be mutable"
15791580}
15801581
1582+ declare_lint ! {
1583+ /// The `dereferencing_mut_binding` lint detects a `mut x` pattern that resets the binding mode,
1584+ /// as this behavior will change in rust 2024.
1585+ ///
1586+ /// ### Example
1587+ ///
1588+ /// ```rust
1589+ /// let x = Some(123u32);
1590+ /// let _y = match &x {
1591+ /// Some(mut x) => {
1592+ /// x += 1;
1593+ /// x
1594+ /// }
1595+ /// None => 0,
1596+ /// };
1597+ /// ```
1598+ ///
1599+ /// {{produces}}
1600+ ///
1601+ /// ### Explanation
1602+ ///
1603+ /// Without the `mut`, `x` would have type `&u32`. Pre-2024, adding `mut` makes `x` have type
1604+ /// `u32`, which was deeped surprising. After edition 2024, adding `mut` will not change the
1605+ /// type of `x`. This lint warns users of editions before 2024 to update their code.
1606+ pub DEREFERENCING_MUT_BINDING ,
1607+ Warn ,
1608+ "detects `mut x` bindings that change the type of `x`"
1609+ }
1610+
15811611declare_lint ! {
15821612 /// The `unconditional_recursion` lint detects functions that cannot
15831613 /// return without calling themselves.
0 commit comments