1 #![warn(clippy::declare_interior_mutable_const)]
6 use std::sync::atomic::AtomicUsize;
9 const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
10 const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
11 const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
12 //~^ ERROR interior mutable
14 macro_rules! declare_const {
15 ($name:ident: $ty:ty = $e:expr) => {
16 const $name: $ty = $e;
19 declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
21 // const ATOMIC_REF: &AtomicUsize = &AtomicUsize::new(7); // This will simply trigger E0492.
23 const INTEGER: u8 = 8;
24 const STRING: String = String::new();
25 const STR: &str = "012345";
26 const COW: Cow<str> = Cow::Borrowed("abcdef");
27 //^ note: a const item of Cow is used in the `postgres` package.
29 const NO_ANN: &dyn Display = &70;
31 static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
32 //^ there should be no lints on this line
36 static THREAD_LOCAL: Cell<i32> = const { Cell::new(0) };