Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downgrade interior_mutable_const lints to warn by default #6098

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&mut_reference::UNNECESSARY_MUT_PASSED),
LintId::of(&neg_multiply::NEG_MULTIPLY),
LintId::of(&new_without_default::NEW_WITHOUT_DEFAULT),
LintId::of(&non_copy_const::BORROW_INTERIOR_MUTABLE_CONST),
LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST),
LintId::of(&non_expressive_names::JUST_UNDERSCORES_AND_DIGITS),
LintId::of(&non_expressive_names::MANY_SINGLE_CHAR_NAMES),
LintId::of(&panic_unimplemented::PANIC_PARAMS),
Expand Down Expand Up @@ -1760,8 +1762,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&misc::FLOAT_CMP),
LintId::of(&misc::MODULO_ONE),
LintId::of(&mut_key::MUTABLE_KEY_TYPE),
LintId::of(&non_copy_const::BORROW_INTERIOR_MUTABLE_CONST),
LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST),
LintId::of(&open_options::NONSENSICAL_OPEN_OPTIONS),
LintId::of(&option_env_unwrap::OPTION_ENV_UNWRAP),
LintId::of(&ptr::MUT_FROM_REF),
Expand Down
28 changes: 24 additions & 4 deletions clippy_lints/src/non_copy_const.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Checks for uses of const which the type is not `Freeze` (`Cell`-free).
//!
//! This lint is **deny** by default.
//! This lint is **warn** by default.

use std::ptr;

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

// FIXME: this is a correctness problem but there's no suitable
// warn-by-default category.
declare_clippy_lint! {
/// **What it does:** Checks for declaration of `const` items which is interior
/// mutable (e.g., contains a `Cell`, `Mutex`, `AtomicXxxx`, etc.).
Expand All @@ -34,6 +36,15 @@ declare_clippy_lint! {
/// `std::sync::ONCE_INIT` constant). In this case the use of `const` is legit,
/// and this lint should be suppressed.
///
/// When an enum has variants with interior mutability, use of its non interior mutable
/// variants can generate false positives. See issue
/// [#3962](https://github.com/rust-lang/rust-clippy/issues/3962)
///
/// Types that have underlying or potential interior mutability trigger the lint whether
/// the interior mutable field is used or not. See issues
/// [#5812](https://github.com/rust-lang/rust-clippy/issues/5812) and
/// [#3825](https://github.com/rust-lang/rust-clippy/issues/3825)
///
/// **Example:**
/// ```rust
/// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
Expand All @@ -49,10 +60,12 @@ declare_clippy_lint! {
/// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance
/// ```
pub DECLARE_INTERIOR_MUTABLE_CONST,
correctness,
style,
flip1995 marked this conversation as resolved.
Show resolved Hide resolved
flip1995 marked this conversation as resolved.
Show resolved Hide resolved
"declaring `const` with interior mutability"
}

// FIXME: this is a correctness problem but there's no suitable
// warn-by-default category.
declare_clippy_lint! {
/// **What it does:** Checks if `const` items which is interior mutable (e.g.,
/// contains a `Cell`, `Mutex`, `AtomicXxxx`, etc.) has been borrowed directly.
Expand All @@ -64,7 +77,14 @@ declare_clippy_lint! {
///
/// The `const` value should be stored inside a `static` item.
///
/// **Known problems:** None
/// **Known problems:** When an enum has variants with interior mutability, use of its non
/// interior mutable variants can generate false positives. See issue
/// [#3962](https://github.com/rust-lang/rust-clippy/issues/3962)
///
/// Types that have underlying or potential interior mutability trigger the lint whether
/// the interior mutable field is used or not. See issues
/// [#5812](https://github.com/rust-lang/rust-clippy/issues/5812) and
/// [#3825](https://github.com/rust-lang/rust-clippy/issues/3825)
///
/// **Example:**
/// ```rust
Expand All @@ -81,7 +101,7 @@ declare_clippy_lint! {
/// assert_eq!(STATIC_ATOM.load(SeqCst), 9); // use a `static` item to refer to the same instance
/// ```
pub BORROW_INTERIOR_MUTABLE_CONST,
correctness,
style,
flip1995 marked this conversation as resolved.
Show resolved Hide resolved
flip1995 marked this conversation as resolved.
Show resolved Hide resolved
"referencing `const` with interior mutability"
}

Expand Down
4 changes: 2 additions & 2 deletions src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
},
Lint {
name: "borrow_interior_mutable_const",
group: "correctness",
group: "style",
desc: "referencing `const` with interior mutability",
deprecation: None,
module: "non_copy_const",
Expand Down Expand Up @@ -334,7 +334,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
},
Lint {
name: "declare_interior_mutable_const",
group: "correctness",
group: "style",
desc: "declaring `const` with interior mutability",
deprecation: None,
module: "non_copy_const",
Expand Down