]> git.lizzy.rs Git - rust.git/blob - tests/ui/declare_interior_mutable_const/others.rs
ignore item in thread_local!
[rust.git] / tests / ui / declare_interior_mutable_const / others.rs
1 #![warn(clippy::declare_interior_mutable_const)]
2
3 use std::borrow::Cow;
4 use std::cell::Cell;
5 use std::fmt::Display;
6 use std::sync::atomic::AtomicUsize;
7 use std::sync::Once;
8
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
13
14 macro_rules! declare_const {
15     ($name:ident: $ty:ty = $e:expr) => {
16         const $name: $ty = $e;
17     };
18 }
19 declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
20
21 // const ATOMIC_REF: &AtomicUsize = &AtomicUsize::new(7); // This will simply trigger E0492.
22
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.
28
29 const NO_ANN: &dyn Display = &70;
30
31 static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
32 //^ there should be no lints on this line
33
34 // issue #8493
35 thread_local! {
36     static THREAD_LOCAL: Cell<i32> = const { Cell::new(0) };
37 }
38
39 fn main() {}