11//! Checks for uses of const which the type is not `Freeze` (`Cell`-free).
22//!
3- //! This lint is **deny ** by default.
3+ //! This lint is **warn ** by default.
44
55use std:: ptr;
66
@@ -17,6 +17,8 @@ use rustc_typeck::hir_ty_to_ty;
1717use crate :: utils:: { in_constant, qpath_res, span_lint_and_then} ;
1818use if_chain:: if_chain;
1919
20+ // FIXME: this is a correctness problem but there's no suitable
21+ // warn-by-default category.
2022declare_clippy_lint ! {
2123 /// **What it does:** Checks for declaration of `const` items which is interior
2224 /// mutable (e.g., contains a `Cell`, `Mutex`, `AtomicXxxx`, etc.).
@@ -34,6 +36,15 @@ declare_clippy_lint! {
3436 /// `std::sync::ONCE_INIT` constant). In this case the use of `const` is legit,
3537 /// and this lint should be suppressed.
3638 ///
39+ /// When an enum has variants with interior mutability, use of its non interior mutable
40+ /// variants can generate false positives. See issue
41+ /// [#3962](https://github.com/rust-lang/rust-clippy/issues/3962)
42+ ///
43+ /// Types that have underlying or potential interior mutability trigger the lint whether
44+ /// the interior mutable field is used or not. See issues
45+ /// [#5812](https://github.com/rust-lang/rust-clippy/issues/5812) and
46+ /// [#3825](https://github.com/rust-lang/rust-clippy/issues/3825)
47+ ///
3748 /// **Example:**
3849 /// ```rust
3950 /// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
@@ -49,10 +60,12 @@ declare_clippy_lint! {
4960 /// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance
5061 /// ```
5162 pub DECLARE_INTERIOR_MUTABLE_CONST ,
52- correctness ,
63+ style ,
5364 "declaring `const` with interior mutability"
5465}
5566
67+ // FIXME: this is a correctness problem but there's no suitable
68+ // warn-by-default category.
5669declare_clippy_lint ! {
5770 /// **What it does:** Checks if `const` items which is interior mutable (e.g.,
5871 /// contains a `Cell`, `Mutex`, `AtomicXxxx`, etc.) has been borrowed directly.
@@ -64,7 +77,14 @@ declare_clippy_lint! {
6477 ///
6578 /// The `const` value should be stored inside a `static` item.
6679 ///
67- /// **Known problems:** None
80+ /// **Known problems:** When an enum has variants with interior mutability, use of its non
81+ /// interior mutable variants can generate false positives. See issue
82+ /// [#3962](https://github.com/rust-lang/rust-clippy/issues/3962)
83+ ///
84+ /// Types that have underlying or potential interior mutability trigger the lint whether
85+ /// the interior mutable field is used or not. See issues
86+ /// [#5812](https://github.com/rust-lang/rust-clippy/issues/5812) and
87+ /// [#3825](https://github.com/rust-lang/rust-clippy/issues/3825)
6888 ///
6989 /// **Example:**
7090 /// ```rust
@@ -81,7 +101,7 @@ declare_clippy_lint! {
81101 /// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance
82102 /// ```
83103 pub BORROW_INTERIOR_MUTABLE_CONST ,
84- correctness ,
104+ style ,
85105 "referencing `const` with interior mutability"
86106}
87107
0 commit comments