Now declare_interior_mutable_const and borrow_interior_mutable_const respect the ignore-interior-mutability configuration entry
changelog: Now `declare_interior_mutable_const` and `borrow_interior_mutable_const` respect the `ignore-interior-mutability` configuration entry Signed-off-by: slinkydeveloper <francescoguard@gmail.com>
This commit is contained in:
parent
c40359d97a
commit
3960bc024c
6 changed files with 270 additions and 133 deletions
1
tests/ui-toml/borrow_interior_mutable_const/clippy.toml
Normal file
1
tests/ui-toml/borrow_interior_mutable_const/clippy.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
ignore-interior-mutability = ["borrow_interior_mutable_const_ignore::Counted"]
|
||||
37
tests/ui-toml/borrow_interior_mutable_const/ignore.rs
Normal file
37
tests/ui-toml/borrow_interior_mutable_const/ignore.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//@compile-flags: --crate-name borrow_interior_mutable_const_ignore
|
||||
|
||||
#![warn(clippy::borrow_interior_mutable_const)]
|
||||
#![allow(clippy::declare_interior_mutable_const)]
|
||||
|
||||
use core::cell::Cell;
|
||||
use std::cmp::{Eq, PartialEq};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::Deref;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
struct Counted<T> {
|
||||
count: AtomicUsize,
|
||||
val: T,
|
||||
}
|
||||
|
||||
impl<T> Counted<T> {
|
||||
const fn new(val: T) -> Self {
|
||||
Self {
|
||||
count: AtomicUsize::new(0),
|
||||
val,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum OptionalCell {
|
||||
Unfrozen(Counted<bool>),
|
||||
Frozen,
|
||||
}
|
||||
|
||||
const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Counted::new(true));
|
||||
const FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
|
||||
|
||||
fn main() {
|
||||
let _ = &UNFROZEN_VARIANT;
|
||||
}
|
||||
1
tests/ui-toml/declare_interior_mutable_const/clippy.toml
Normal file
1
tests/ui-toml/declare_interior_mutable_const/clippy.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
ignore-interior-mutability = ["declare_interior_mutable_const_ignore::Counted"]
|
||||
46
tests/ui-toml/declare_interior_mutable_const/ignore.rs
Normal file
46
tests/ui-toml/declare_interior_mutable_const/ignore.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
//@compile-flags: --crate-name declare_interior_mutable_const_ignore
|
||||
|
||||
#![warn(clippy::declare_interior_mutable_const)]
|
||||
#![allow(clippy::borrow_interior_mutable_const)]
|
||||
|
||||
use core::cell::Cell;
|
||||
use std::cmp::{Eq, PartialEq};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::Deref;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
struct Counted<T> {
|
||||
count: AtomicUsize,
|
||||
val: T,
|
||||
}
|
||||
|
||||
impl<T> Counted<T> {
|
||||
const fn new(val: T) -> Self {
|
||||
Self {
|
||||
count: AtomicUsize::new(0),
|
||||
val,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum OptionalCell {
|
||||
Unfrozen(Counted<bool>),
|
||||
Frozen,
|
||||
}
|
||||
|
||||
const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Counted::new(true));
|
||||
const FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
|
||||
|
||||
const fn unfrozen_variant() -> OptionalCell {
|
||||
OptionalCell::Unfrozen(Counted::new(true))
|
||||
}
|
||||
|
||||
const fn frozen_variant() -> OptionalCell {
|
||||
OptionalCell::Frozen
|
||||
}
|
||||
|
||||
const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant();
|
||||
const FROZEN_VARIANT_FROM_FN: OptionalCell = frozen_variant();
|
||||
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue