Skip to content

Commit be81608

Browse files
committed
split interior_mutable_const tests and clean it
* remove a 'ERROR' comment from `borrow` `Vec<AtomicUsize>` itself is `Freeze` as it holds the atomic in heap * remove `ONCE_INIT` from `declare` it seems like an artifact from previous spliting
1 parent 9408c68 commit be81608

File tree

8 files changed

+430
-144
lines changed

8 files changed

+430
-144
lines changed

tests/ui/borrow_interior_mutable_const.rs renamed to tests/ui/borrow_interior_mutable_const/others.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,7 @@ const NO_ANN: &dyn Display = &70;
1919
static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
2020
const ONCE_INIT: Once = Once::new();
2121

22-
trait Trait<T> {
23-
type AssocType;
24-
25-
const ATOMIC: AtomicUsize;
26-
const INPUT: T;
27-
const ASSOC: Self::AssocType;
28-
29-
fn function() {
30-
let _ = &Self::INPUT;
31-
let _ = &Self::ASSOC;
32-
}
33-
}
34-
35-
impl Trait<u32> for u64 {
36-
type AssocType = AtomicUsize;
37-
38-
const ATOMIC: AtomicUsize = AtomicUsize::new(9);
39-
const INPUT: u32 = 10;
40-
const ASSOC: Self::AssocType = AtomicUsize::new(11);
41-
42-
fn function() {
43-
let _ = &Self::INPUT;
44-
let _ = &Self::ASSOC; //~ ERROR interior mutability
45-
}
46-
}
47-
48-
// This is just a pointer that can be safely dereferended,
22+
// This is just a pointer that can be safely dereferenced,
4923
// it's semantically the same as `&'static T`;
5024
// but it isn't allowed to make a static reference from an arbitrary integer value at the moment.
5125
// For more information, please see the issue #5918.
@@ -100,7 +74,7 @@ fn main() {
10074
let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
10175
let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
10276
let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
103-
let _ = &*ATOMIC_TUPLE.1; //~ ERROR interior mutability
77+
let _ = &*ATOMIC_TUPLE.1;
10478
let _ = &ATOMIC_TUPLE.2;
10579
let _ = (&&&&ATOMIC_TUPLE).0;
10680
let _ = (&&&&ATOMIC_TUPLE).2;
@@ -124,9 +98,6 @@ fn main() {
12498
assert_eq!(STATIC_TUPLE.0.load(Ordering::SeqCst), 3);
12599
assert!(STATIC_TUPLE.1.is_empty());
126100

127-
u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
128-
assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
129-
130101
assert_eq!(NO_ANN.to_string(), "70"); // should never lint this.
131102

132103
let _ = &CELL_REF.0;
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,115 @@
11
error: a `const` item with interior mutability should not be borrowed
2-
--> $DIR/borrow_interior_mutable_const.rs:44:18
3-
|
4-
LL | let _ = &Self::ASSOC; //~ ERROR interior mutability
5-
| ^^^^^^^^^^^
6-
|
7-
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
8-
= help: assign this const to a local or static variable, and use the variable here
9-
10-
error: a `const` item with interior mutability should not be borrowed
11-
--> $DIR/borrow_interior_mutable_const.rs:80:5
2+
--> $DIR/others.rs:54:5
123
|
134
LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
145
| ^^^^^^
156
|
7+
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
168
= help: assign this const to a local or static variable, and use the variable here
179

1810
error: a `const` item with interior mutability should not be borrowed
19-
--> $DIR/borrow_interior_mutable_const.rs:81:16
11+
--> $DIR/others.rs:55:16
2012
|
2113
LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
2214
| ^^^^^^
2315
|
2416
= help: assign this const to a local or static variable, and use the variable here
2517

2618
error: a `const` item with interior mutability should not be borrowed
27-
--> $DIR/borrow_interior_mutable_const.rs:84:22
19+
--> $DIR/others.rs:58:22
2820
|
2921
LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
3022
| ^^^^^^^^^
3123
|
3224
= help: assign this const to a local or static variable, and use the variable here
3325

3426
error: a `const` item with interior mutability should not be borrowed
35-
--> $DIR/borrow_interior_mutable_const.rs:85:25
27+
--> $DIR/others.rs:59:25
3628
|
3729
LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
3830
| ^^^^^^^^^
3931
|
4032
= help: assign this const to a local or static variable, and use the variable here
4133

4234
error: a `const` item with interior mutability should not be borrowed
43-
--> $DIR/borrow_interior_mutable_const.rs:86:27
35+
--> $DIR/others.rs:60:27
4436
|
4537
LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
4638
| ^^^^^^^^^
4739
|
4840
= help: assign this const to a local or static variable, and use the variable here
4941

5042
error: a `const` item with interior mutability should not be borrowed
51-
--> $DIR/borrow_interior_mutable_const.rs:87:26
43+
--> $DIR/others.rs:61:26
5244
|
5345
LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
5446
| ^^^^^^^^^
5547
|
5648
= help: assign this const to a local or static variable, and use the variable here
5749

5850
error: a `const` item with interior mutability should not be borrowed
59-
--> $DIR/borrow_interior_mutable_const.rs:98:14
51+
--> $DIR/others.rs:72:14
6052
|
6153
LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
6254
| ^^^^^^^^^^^^
6355
|
6456
= help: assign this const to a local or static variable, and use the variable here
6557

6658
error: a `const` item with interior mutability should not be borrowed
67-
--> $DIR/borrow_interior_mutable_const.rs:99:14
59+
--> $DIR/others.rs:73:14
6860
|
6961
LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
7062
| ^^^^^^^^^^^^
7163
|
7264
= help: assign this const to a local or static variable, and use the variable here
7365

7466
error: a `const` item with interior mutability should not be borrowed
75-
--> $DIR/borrow_interior_mutable_const.rs:100:19
67+
--> $DIR/others.rs:74:19
7668
|
7769
LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
7870
| ^^^^^^^^^^^^
7971
|
8072
= help: assign this const to a local or static variable, and use the variable here
8173

8274
error: a `const` item with interior mutability should not be borrowed
83-
--> $DIR/borrow_interior_mutable_const.rs:101:14
75+
--> $DIR/others.rs:75:14
8476
|
8577
LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
8678
| ^^^^^^^^^^^^
8779
|
8880
= help: assign this const to a local or static variable, and use the variable here
8981

9082
error: a `const` item with interior mutability should not be borrowed
91-
--> $DIR/borrow_interior_mutable_const.rs:102:13
83+
--> $DIR/others.rs:76:13
9284
|
9385
LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
9486
| ^^^^^^^^^^^^
9587
|
9688
= help: assign this const to a local or static variable, and use the variable here
9789

9890
error: a `const` item with interior mutability should not be borrowed
99-
--> $DIR/borrow_interior_mutable_const.rs:108:13
91+
--> $DIR/others.rs:82:13
10092
|
10193
LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
10294
| ^^^^^^^^^^^^
10395
|
10496
= help: assign this const to a local or static variable, and use the variable here
10597

10698
error: a `const` item with interior mutability should not be borrowed
107-
--> $DIR/borrow_interior_mutable_const.rs:113:5
99+
--> $DIR/others.rs:87:5
108100
|
109101
LL | CELL.set(2); //~ ERROR interior mutability
110102
| ^^^^
111103
|
112104
= help: assign this const to a local or static variable, and use the variable here
113105

114106
error: a `const` item with interior mutability should not be borrowed
115-
--> $DIR/borrow_interior_mutable_const.rs:114:16
107+
--> $DIR/others.rs:88:16
116108
|
117109
LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
118110
| ^^^^
119111
|
120112
= help: assign this const to a local or static variable, and use the variable here
121113

122-
error: a `const` item with interior mutability should not be borrowed
123-
--> $DIR/borrow_interior_mutable_const.rs:127:5
124-
|
125-
LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
126-
| ^^^^^^^^^^^
127-
|
128-
= help: assign this const to a local or static variable, and use the variable here
129-
130-
error: a `const` item with interior mutability should not be borrowed
131-
--> $DIR/borrow_interior_mutable_const.rs:128:16
132-
|
133-
LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
134-
| ^^^^^^^^^^^
135-
|
136-
= help: assign this const to a local or static variable, and use the variable here
137-
138-
error: aborting due to 17 previous errors
114+
error: aborting due to 14 previous errors
139115

0 commit comments

Comments
 (0)