Skip to content

Commit 4434e8c

Browse files
committed
Adjust Clippy for CONST_ITEM_MUTATION lint
We no longer lint assignments to const item fields in the `temporary_assignment` lint, since this is now covered by the `CONST_ITEM_MUTATION` lint. Additionally, we `#![allow(const_item_mutation)]` in the `borrow_interior_mutable_const.rs` test. Clippy UI tests are run with `-D warnings`, which seems to cause builtin lints to prevent Clippy lints from running.
1 parent f422ef1 commit 4434e8c

File tree

5 files changed

+24
-48
lines changed

5 files changed

+24
-48
lines changed

src/tools/clippy/clippy_lints/src/temporary_assignment.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::utils::{is_adjusted, span_lint};
2-
use rustc_hir::def::{DefKind, Res};
32
use rustc_hir::{Expr, ExprKind};
43
use rustc_lint::{LateContext, LateLintPass};
54
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -22,10 +21,9 @@ declare_clippy_lint! {
2221
"assignments to temporaries"
2322
}
2423

25-
fn is_temporary(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
24+
fn is_temporary(_cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
2625
match &expr.kind {
2726
ExprKind::Struct(..) | ExprKind::Tup(..) => true,
28-
ExprKind::Path(qpath) => matches!(cx.qpath_res(qpath, expr.hir_id), Res::Def(DefKind::Const, ..)),
2927
_ => false,
3028
}
3129
}

src/tools/clippy/tests/ui/borrow_interior_mutable_const.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(clippy::borrow_interior_mutable_const)]
22
#![allow(clippy::declare_interior_mutable_const, clippy::ref_in_deref)]
3+
#![allow(const_item_mutation)]
34

45
use std::borrow::Cow;
56
use std::cell::{Cell, UnsafeCell};

src/tools/clippy/tests/ui/borrow_interior_mutable_const.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: a `const` item with interior mutability should not be borrowed
2-
--> $DIR/borrow_interior_mutable_const.rs:65:5
2+
--> $DIR/borrow_interior_mutable_const.rs:66:5
33
|
44
LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
55
| ^^^^^^
@@ -8,119 +8,119 @@ LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
88
= help: assign this const to a local or static variable, and use the variable here
99

1010
error: a `const` item with interior mutability should not be borrowed
11-
--> $DIR/borrow_interior_mutable_const.rs:66:16
11+
--> $DIR/borrow_interior_mutable_const.rs:67:16
1212
|
1313
LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
1414
| ^^^^^^
1515
|
1616
= help: assign this const to a local or static variable, and use the variable here
1717

1818
error: a `const` item with interior mutability should not be borrowed
19-
--> $DIR/borrow_interior_mutable_const.rs:69:22
19+
--> $DIR/borrow_interior_mutable_const.rs:70:22
2020
|
2121
LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
2222
| ^^^^^^^^^
2323
|
2424
= help: assign this const to a local or static variable, and use the variable here
2525

2626
error: a `const` item with interior mutability should not be borrowed
27-
--> $DIR/borrow_interior_mutable_const.rs:70:25
27+
--> $DIR/borrow_interior_mutable_const.rs:71:25
2828
|
2929
LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
3030
| ^^^^^^^^^
3131
|
3232
= help: assign this const to a local or static variable, and use the variable here
3333

3434
error: a `const` item with interior mutability should not be borrowed
35-
--> $DIR/borrow_interior_mutable_const.rs:71:27
35+
--> $DIR/borrow_interior_mutable_const.rs:72:27
3636
|
3737
LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
3838
| ^^^^^^^^^
3939
|
4040
= help: assign this const to a local or static variable, and use the variable here
4141

4242
error: a `const` item with interior mutability should not be borrowed
43-
--> $DIR/borrow_interior_mutable_const.rs:72:26
43+
--> $DIR/borrow_interior_mutable_const.rs:73:26
4444
|
4545
LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
4646
| ^^^^^^^^^
4747
|
4848
= help: assign this const to a local or static variable, and use the variable here
4949

5050
error: a `const` item with interior mutability should not be borrowed
51-
--> $DIR/borrow_interior_mutable_const.rs:83:14
51+
--> $DIR/borrow_interior_mutable_const.rs:84:14
5252
|
5353
LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
5454
| ^^^^^^^^^^^^
5555
|
5656
= help: assign this const to a local or static variable, and use the variable here
5757

5858
error: a `const` item with interior mutability should not be borrowed
59-
--> $DIR/borrow_interior_mutable_const.rs:84:14
59+
--> $DIR/borrow_interior_mutable_const.rs:85:14
6060
|
6161
LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
6262
| ^^^^^^^^^^^^
6363
|
6464
= help: assign this const to a local or static variable, and use the variable here
6565

6666
error: a `const` item with interior mutability should not be borrowed
67-
--> $DIR/borrow_interior_mutable_const.rs:85:19
67+
--> $DIR/borrow_interior_mutable_const.rs:86:19
6868
|
6969
LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
7070
| ^^^^^^^^^^^^
7171
|
7272
= help: assign this const to a local or static variable, and use the variable here
7373

7474
error: a `const` item with interior mutability should not be borrowed
75-
--> $DIR/borrow_interior_mutable_const.rs:86:14
75+
--> $DIR/borrow_interior_mutable_const.rs:87:14
7676
|
7777
LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
7878
| ^^^^^^^^^^^^
7979
|
8080
= help: assign this const to a local or static variable, and use the variable here
8181

8282
error: a `const` item with interior mutability should not be borrowed
83-
--> $DIR/borrow_interior_mutable_const.rs:87:13
83+
--> $DIR/borrow_interior_mutable_const.rs:88:13
8484
|
8585
LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
8686
| ^^^^^^^^^^^^
8787
|
8888
= help: assign this const to a local or static variable, and use the variable here
8989

9090
error: a `const` item with interior mutability should not be borrowed
91-
--> $DIR/borrow_interior_mutable_const.rs:93:13
91+
--> $DIR/borrow_interior_mutable_const.rs:94:13
9292
|
9393
LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
9494
| ^^^^^^^^^^^^
9595
|
9696
= help: assign this const to a local or static variable, and use the variable here
9797

9898
error: a `const` item with interior mutability should not be borrowed
99-
--> $DIR/borrow_interior_mutable_const.rs:98:5
99+
--> $DIR/borrow_interior_mutable_const.rs:99:5
100100
|
101101
LL | CELL.set(2); //~ ERROR interior mutability
102102
| ^^^^
103103
|
104104
= help: assign this const to a local or static variable, and use the variable here
105105

106106
error: a `const` item with interior mutability should not be borrowed
107-
--> $DIR/borrow_interior_mutable_const.rs:99:16
107+
--> $DIR/borrow_interior_mutable_const.rs:100:16
108108
|
109109
LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
110110
| ^^^^
111111
|
112112
= help: assign this const to a local or static variable, and use the variable here
113113

114114
error: a `const` item with interior mutability should not be borrowed
115-
--> $DIR/borrow_interior_mutable_const.rs:112:5
115+
--> $DIR/borrow_interior_mutable_const.rs:113:5
116116
|
117117
LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
118118
| ^^^^^^^^^^^
119119
|
120120
= help: assign this const to a local or static variable, and use the variable here
121121

122122
error: a `const` item with interior mutability should not be borrowed
123-
--> $DIR/borrow_interior_mutable_const.rs:113:16
123+
--> $DIR/borrow_interior_mutable_const.rs:114:16
124124
|
125125
LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
126126
| ^^^^^^^^^^^

src/tools/clippy/tests/ui/temporary_assignment.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![warn(clippy::temporary_assignment)]
2+
#![allow(const_item_mutation)]
23

34
use std::ops::{Deref, DerefMut};
45

Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: assignment to temporary
2-
--> $DIR/temporary_assignment.rs:47:5
2+
--> $DIR/temporary_assignment.rs:48:5
33
|
44
LL | Struct { field: 0 }.field = 1;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::temporary-assignment` implied by `-D warnings`
88

99
error: assignment to temporary
10-
--> $DIR/temporary_assignment.rs:48:5
10+
--> $DIR/temporary_assignment.rs:49:5
1111
|
1212
LL | / MultiStruct {
1313
LL | | structure: Struct { field: 0 },
@@ -17,40 +17,16 @@ LL | | .field = 1;
1717
| |______________^
1818

1919
error: assignment to temporary
20-
--> $DIR/temporary_assignment.rs:53:5
20+
--> $DIR/temporary_assignment.rs:54:5
2121
|
2222
LL | ArrayStruct { array: [0] }.array[0] = 1;
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error: assignment to temporary
26-
--> $DIR/temporary_assignment.rs:54:5
26+
--> $DIR/temporary_assignment.rs:55:5
2727
|
2828
LL | (0, 0).0 = 1;
2929
| ^^^^^^^^^^^^
3030

31-
error: assignment to temporary
32-
--> $DIR/temporary_assignment.rs:56:5
33-
|
34-
LL | A.0 = 2;
35-
| ^^^^^^^
36-
37-
error: assignment to temporary
38-
--> $DIR/temporary_assignment.rs:57:5
39-
|
40-
LL | B.field = 2;
41-
| ^^^^^^^^^^^
42-
43-
error: assignment to temporary
44-
--> $DIR/temporary_assignment.rs:58:5
45-
|
46-
LL | C.structure.field = 2;
47-
| ^^^^^^^^^^^^^^^^^^^^^
48-
49-
error: assignment to temporary
50-
--> $DIR/temporary_assignment.rs:59:5
51-
|
52-
LL | D.array[0] = 2;
53-
| ^^^^^^^^^^^^^^
54-
55-
error: aborting due to 8 previous errors
31+
error: aborting due to 4 previous errors
5632

0 commit comments

Comments
 (0)