Skip to content

Commit e5a1ef0

Browse files
committed
Auto merge of #13290 - Jarcho:interior_mut_quick, r=Alexendoo
`declare_interior_mutable_const`: Ignore pointer types. fixes #12951 fixes #13233 changelog: `declare_interior_mutable_const`: Ignore pointer types.
2 parents 70650de + 687d4e3 commit e5a1ef0

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

clippy_lints/src/non_copy_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl_lint_pass!(NonCopyConst<'_> => [DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTE
184184
impl<'tcx> NonCopyConst<'tcx> {
185185
pub fn new(tcx: TyCtxt<'tcx>, conf: &'static Conf) -> Self {
186186
Self {
187-
interior_mut: InteriorMut::new(tcx, &conf.ignore_interior_mutability),
187+
interior_mut: InteriorMut::without_pointers(tcx, &conf.ignore_interior_mutability),
188188
}
189189
}
190190

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() {}

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)