Skip to content

Commit ceea8b2

Browse files
borsMabezDev
authored andcommitted
Auto merge of rust-lang#13290 - Jarcho:interior_mut_quick, r=Alexendoo
`declare_interior_mutable_const`: Ignore pointer types. fixes rust-lang#12951 fixes rust-lang#13233 changelog: `declare_interior_mutable_const`: Ignore pointer types.
1 parent 82131c9 commit ceea8b2

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/tools/clippy/clippy_lints/src/non_copy_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl<'tcx> NonCopyConst<'tcx> {
309309

310310
impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> {
311311
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
312-
self.interior_mut = InteriorMut::new(cx, &self.ignore_interior_mutability);
312+
self.interior_mut = InteriorMut::without_pointers(cx, &self.ignore_interior_mutability);
313313
}
314314

315315
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx Item<'_>) {

src/tools/clippy/tests/ui/declare_interior_mutable_const/others.rs

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::borrow::Cow;
44
use std::cell::Cell;
55
use std::fmt::Display;
6+
use std::ptr;
67
use std::sync::atomic::AtomicUsize;
78
use std::sync::Once;
89

@@ -53,4 +54,20 @@ mod issue_8493 {
5354
issue_8493!();
5455
}
5556

57+
#[repr(C, align(8))]
58+
struct NoAtomic(usize);
59+
#[repr(C, align(8))]
60+
struct WithAtomic(AtomicUsize);
61+
62+
const fn with_non_null() -> *const WithAtomic {
63+
const NO_ATOMIC: NoAtomic = NoAtomic(0);
64+
(&NO_ATOMIC as *const NoAtomic).cast()
65+
}
66+
const WITH_ATOMIC: *const WithAtomic = with_non_null();
67+
68+
struct Generic<T>(T);
69+
impl<T> Generic<T> {
70+
const RAW_POINTER: *const Cell<T> = ptr::null();
71+
}
72+
5673
fn main() {}

src/tools/clippy/tests/ui/declare_interior_mutable_const/others.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: a `const` item should not be interior mutable
2-
--> tests/ui/declare_interior_mutable_const/others.rs:9:1
2+
--> tests/ui/declare_interior_mutable_const/others.rs:10:1
33
|
44
LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -9,23 +9,23 @@ LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5);
99
= help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]`
1010

1111
error: a `const` item should not be interior mutable
12-
--> tests/ui/declare_interior_mutable_const/others.rs:10:1
12+
--> tests/ui/declare_interior_mutable_const/others.rs:11:1
1313
|
1414
LL | const CELL: Cell<usize> = Cell::new(6);
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616
|
1717
= help: consider making this `Sync` so that it can go in a static item or using a `thread_local`
1818

1919
error: a `const` item should not be interior mutable
20-
--> tests/ui/declare_interior_mutable_const/others.rs:11:1
20+
--> tests/ui/declare_interior_mutable_const/others.rs:12:1
2121
|
2222
LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424
|
2525
= help: consider making this a static item
2626

2727
error: a `const` item should not be interior mutable
28-
--> tests/ui/declare_interior_mutable_const/others.rs:16:9
28+
--> tests/ui/declare_interior_mutable_const/others.rs:17:9
2929
|
3030
LL | const $name: $ty = $e;
3131
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +36,7 @@ LL | declare_const!(_ONCE: Once = Once::new());
3636
= note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info)
3737

3838
error: a `const` item should not be interior mutable
39-
--> tests/ui/declare_interior_mutable_const/others.rs:44:13
39+
--> tests/ui/declare_interior_mutable_const/others.rs:45:13
4040
|
4141
LL | const _BAZ: Cell<usize> = Cell::new(0);
4242
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)