Skip to content

Commit 87a4495

Browse files
committed
Auto merge of #6027 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents e0f46a1 + 2d56512 commit 87a4495

5 files changed

+21
-54
lines changed

clippy_lints/src/temporary_assignment.rs

Lines changed: 3 additions & 8 deletions
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,12 +21,8 @@ declare_clippy_lint! {
2221
"assignments to temporaries"
2322
}
2423

25-
fn is_temporary(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
26-
match &expr.kind {
27-
ExprKind::Struct(..) | ExprKind::Tup(..) => true,
28-
ExprKind::Path(qpath) => matches!(cx.qpath_res(qpath, expr.hir_id), Res::Def(DefKind::Const, ..)),
29-
_ => false,
30-
}
24+
fn is_temporary(expr: &Expr<'_>) -> bool {
25+
matches!(&expr.kind, ExprKind::Struct(..) | ExprKind::Tup(..))
3126
}
3227

3328
declare_lint_pass!(TemporaryAssignment => [TEMPORARY_ASSIGNMENT]);
@@ -39,7 +34,7 @@ impl<'tcx> LateLintPass<'tcx> for TemporaryAssignment {
3934
while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.kind {
4035
base = f;
4136
}
42-
if is_temporary(cx, base) && !is_adjusted(cx, base) {
37+
if is_temporary(base) && !is_adjusted(cx, base) {
4338
span_lint(cx, TEMPORARY_ASSIGNMENT, expr.span, "assignment to temporary");
4439
}
4540
}

tests/ui/borrow_interior_mutable_const.rs

Lines changed: 1 addition & 0 deletions
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};

tests/ui/borrow_interior_mutable_const.stderr

Lines changed: 16 additions & 16 deletions
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
| ^^^^^^^^^^^

tests/ui/temporary_assignment.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ fn main() {
5353
ArrayStruct { array: [0] }.array[0] = 1;
5454
(0, 0).0 = 1;
5555

56-
A.0 = 2;
57-
B.field = 2;
58-
C.structure.field = 2;
59-
D.array[0] = 2;
60-
6156
// no error
6257
s.field = 1;
6358
t.0 = 1;

tests/ui/temporary_assignment.stderr

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,5 @@ error: assignment to temporary
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)