Skip to content

Commit a1a7f20

Browse files
committed
Auto merge of #6098 - longlb:interior_mut_const, r=ebroto
Downgrade interior_mutable_const lints to warn by default This change updates the two lints in the file non_copy_const.rs to be warn by default rather than deny by default. It also updates the known problems for declare_interior_mutable_const to mention some issues that are affected by the lints. This is a repeat pull request since I botched the first one (#6012). Apart from my messing up the commits of that one, I also had a problem where the stderr of the tests didn't change despite me changing both lints to warn by default. Is this normal behaviour for some lints or do I need to adjust the tests to accommodate the change? fixes #5863 changelog: none
2 parents f0eac45 + 8b8c63f commit a1a7f20

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16041604
LintId::of(&mut_reference::UNNECESSARY_MUT_PASSED),
16051605
LintId::of(&neg_multiply::NEG_MULTIPLY),
16061606
LintId::of(&new_without_default::NEW_WITHOUT_DEFAULT),
1607+
LintId::of(&non_copy_const::BORROW_INTERIOR_MUTABLE_CONST),
1608+
LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST),
16071609
LintId::of(&non_expressive_names::JUST_UNDERSCORES_AND_DIGITS),
16081610
LintId::of(&non_expressive_names::MANY_SINGLE_CHAR_NAMES),
16091611
LintId::of(&panic_unimplemented::PANIC_PARAMS),
@@ -1760,8 +1762,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17601762
LintId::of(&misc::FLOAT_CMP),
17611763
LintId::of(&misc::MODULO_ONE),
17621764
LintId::of(&mut_key::MUTABLE_KEY_TYPE),
1763-
LintId::of(&non_copy_const::BORROW_INTERIOR_MUTABLE_CONST),
1764-
LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST),
17651765
LintId::of(&open_options::NONSENSICAL_OPEN_OPTIONS),
17661766
LintId::of(&option_env_unwrap::OPTION_ENV_UNWRAP),
17671767
LintId::of(&ptr::MUT_FROM_REF),

clippy_lints/src/non_copy_const.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
55
use std::ptr;
66

@@ -17,6 +17,8 @@ use rustc_typeck::hir_ty_to_ty;
1717
use crate::utils::{in_constant, qpath_res, span_lint_and_then};
1818
use if_chain::if_chain;
1919

20+
// FIXME: this is a correctness problem but there's no suitable
21+
// warn-by-default category.
2022
declare_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.
5669
declare_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

src/lintlist/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
110110
},
111111
Lint {
112112
name: "borrow_interior_mutable_const",
113-
group: "correctness",
113+
group: "style",
114114
desc: "referencing `const` with interior mutability",
115115
deprecation: None,
116116
module: "non_copy_const",
@@ -334,7 +334,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
334334
},
335335
Lint {
336336
name: "declare_interior_mutable_const",
337-
group: "correctness",
337+
group: "style",
338338
desc: "declaring `const` with interior mutability",
339339
deprecation: None,
340340
module: "non_copy_const",

0 commit comments

Comments
 (0)