Cleanup of rustup

This commit is contained in:
flip1995 2020-09-10 14:18:05 +02:00
parent 961f18317d
commit 2d56512580
No known key found for this signature in database
GPG Key ID: 693086869D506637
3 changed files with 7 additions and 16 deletions

View File

@ -21,11 +21,8 @@
"assignments to temporaries"
}
fn is_temporary(_cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
match &expr.kind {
ExprKind::Struct(..) | ExprKind::Tup(..) => true,
_ => false,
}
fn is_temporary(expr: &Expr<'_>) -> bool {
matches!(&expr.kind, ExprKind::Struct(..) | ExprKind::Tup(..))
}
declare_lint_pass!(TemporaryAssignment => [TEMPORARY_ASSIGNMENT]);
@ -37,7 +34,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.kind {
base = f;
}
if is_temporary(cx, base) && !is_adjusted(cx, base) {
if is_temporary(base) && !is_adjusted(cx, base) {
span_lint(cx, TEMPORARY_ASSIGNMENT, expr.span, "assignment to temporary");
}
}

View File

@ -1,5 +1,4 @@
#![warn(clippy::temporary_assignment)]
#![allow(const_item_mutation)]
use std::ops::{Deref, DerefMut};
@ -54,11 +53,6 @@ fn main() {
ArrayStruct { array: [0] }.array[0] = 1;
(0, 0).0 = 1;
A.0 = 2;
B.field = 2;
C.structure.field = 2;
D.array[0] = 2;
// no error
s.field = 1;
t.0 = 1;

View File

@ -1,5 +1,5 @@
error: assignment to temporary
--> $DIR/temporary_assignment.rs:48:5
--> $DIR/temporary_assignment.rs:47:5
|
LL | Struct { field: 0 }.field = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -7,7 +7,7 @@ LL | Struct { field: 0 }.field = 1;
= note: `-D clippy::temporary-assignment` implied by `-D warnings`
error: assignment to temporary
--> $DIR/temporary_assignment.rs:49:5
--> $DIR/temporary_assignment.rs:48:5
|
LL | / MultiStruct {
LL | | structure: Struct { field: 0 },
@ -17,13 +17,13 @@ LL | | .field = 1;
| |______________^
error: assignment to temporary
--> $DIR/temporary_assignment.rs:54:5
--> $DIR/temporary_assignment.rs:53:5
|
LL | ArrayStruct { array: [0] }.array[0] = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: assignment to temporary
--> $DIR/temporary_assignment.rs:55:5
--> $DIR/temporary_assignment.rs:54:5
|
LL | (0, 0).0 = 1;
| ^^^^^^^^^^^^