@@ -35,6 +35,7 @@ declare_lint_pass! {
35
35
DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME ,
36
36
DEPRECATED_IN_FUTURE ,
37
37
DEPRECATED_WHERE_CLAUSE_LOCATION ,
38
+ DEREFERENCING_MUT_BINDING ,
38
39
DUPLICATE_MACRO_ATTRIBUTES ,
39
40
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT ,
40
41
ELIDED_LIFETIMES_IN_PATHS ,
@@ -1578,6 +1579,35 @@ declare_lint! {
1578
1579
"detect mut variables which don't need to be mutable"
1579
1580
}
1580
1581
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
+
1581
1611
declare_lint ! {
1582
1612
/// The `unconditional_recursion` lint detects functions that cannot
1583
1613
/// return without calling themselves.
0 commit comments