@@ -38,6 +38,7 @@ declare_lint_pass! {
38
38
DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME ,
39
39
DEPRECATED_IN_FUTURE ,
40
40
DEPRECATED_WHERE_CLAUSE_LOCATION ,
41
+ DEREFERENCING_MUT_BINDING ,
41
42
DUPLICATE_MACRO_ATTRIBUTES ,
42
43
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT ,
43
44
ELIDED_LIFETIMES_IN_PATHS ,
@@ -1627,6 +1628,41 @@ declare_lint! {
1627
1628
"detect mut variables which don't need to be mutable"
1628
1629
}
1629
1630
1631
+ declare_lint ! {
1632
+ /// The `dereferencing_mut_binding` lint detects a `mut x` pattern that resets the binding mode,
1633
+ /// as this behavior will change in rust 2024.
1634
+ ///
1635
+ /// ### Example
1636
+ ///
1637
+ /// ```rust
1638
+ /// # #![warn(dereferencing_mut_binding)]
1639
+ /// let x = Some(123u32);
1640
+ /// let _y = match &x {
1641
+ /// Some(mut x) => {
1642
+ /// x += 1;
1643
+ /// x
1644
+ /// }
1645
+ /// None => 0,
1646
+ /// };
1647
+ /// ```
1648
+ ///
1649
+ /// {{produces}}
1650
+ ///
1651
+ /// ### Explanation
1652
+ ///
1653
+ /// Without the `mut`, `x` would have type `&u32`. Pre-2024, adding `mut` makes `x` have type
1654
+ /// `u32`, which was deeped surprising. After edition 2024, adding `mut` will not change the
1655
+ /// type of `x`. This lint warns users of editions before 2024 to update their code.
1656
+ pub DEREFERENCING_MUT_BINDING ,
1657
+ Allow ,
1658
+ "detects `mut x` bindings that change the type of `x`" ,
1659
+ @feature_gate = sym:: mut_dont_reset_binding_mode_2024;
1660
+ @future_incompatible = FutureIncompatibleInfo {
1661
+ reason: FutureIncompatibilityReason :: EditionSemanticsChange ( Edition :: Edition2024 ) ,
1662
+ reference: "123076" ,
1663
+ } ;
1664
+ }
1665
+
1630
1666
declare_lint ! {
1631
1667
/// The `unconditional_recursion` lint detects functions that cannot
1632
1668
/// return without calling themselves.
0 commit comments