Skip to content

Commit 74bb5e0

Browse files
committed
Auto merge of #4948 - lzutao:rustup-67538, r=phansch
rustup "Add span information to `ExprKind::Assign`" cc rust-lang/rust#67538 changelog: none
2 parents 82b0325 + 652666b commit 74bb5e0

19 files changed

+45
-34
lines changed

clippy_lints/src/assign_ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
7676
}
7777
}
7878
},
79-
hir::ExprKind::Assign(assignee, e) => {
79+
hir::ExprKind::Assign(assignee, e, _) => {
8080
if let hir::ExprKind::Binary(op, l, r) = &e.kind {
8181
#[allow(clippy::cognitive_complexity)]
8282
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {

clippy_lints/src/eval_order_dependence.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
6262
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
6363
// Find a write to a local variable.
6464
match expr.kind {
65-
ExprKind::Assign(ref lhs, _) | ExprKind::AssignOp(_, ref lhs, _) => {
65+
ExprKind::Assign(ref lhs, ..) | ExprKind::AssignOp(_, ref lhs, _) => {
6666
if let ExprKind::Path(ref qpath) = lhs.kind {
6767
if let QPath::Resolved(_, ref path) = *qpath {
6868
if path.segments.len() == 1 {
@@ -224,7 +224,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> St
224224
| ExprKind::Tup(_)
225225
| ExprKind::MethodCall(..)
226226
| ExprKind::Call(_, _)
227-
| ExprKind::Assign(_, _)
227+
| ExprKind::Assign(..)
228228
| ExprKind::Index(_, _)
229229
| ExprKind::Repeat(_, _)
230230
| ExprKind::Struct(_, _, _) => {
@@ -345,7 +345,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
345345
/// Returns `true` if `expr` is the LHS of an assignment, like `expr = ...`.
346346
fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
347347
if let Some(parent) = get_parent_expr(cx, expr) {
348-
if let ExprKind::Assign(ref lhs, _) = parent.kind {
348+
if let ExprKind::Assign(ref lhs, ..) = parent.kind {
349349
return lhs.hir_id == expr.hir_id;
350350
}
351351
}

clippy_lints/src/formatting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl EarlyLintPass for Formatting {
131131

132132
/// Implementation of the `SUSPICIOUS_ASSIGNMENT_FORMATTING` lint.
133133
fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) {
134-
if let ExprKind::Assign(ref lhs, ref rhs) = expr.kind {
134+
if let ExprKind::Assign(ref lhs, ref rhs, _) = expr.kind {
135135
if !differing_macro_contexts(lhs.span, rhs.span) && !lhs.span.from_expansion() {
136136
let eq_span = lhs.span.between(rhs.span);
137137
if let ExprKind::Unary(op, ref sub_rhs) = rhs.kind {

clippy_lints/src/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
615615
tys.clear();
616616
}
617617
},
618-
Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(_, hir::Mutability::Mut, ref target) => {
618+
Assign(ref target, ..) | AssignOp(_, ref target, _) | AddrOf(_, hir::Mutability::Mut, ref target) => {
619619
self.mutates_static |= is_mutated_static(self.cx, target)
620620
},
621621
_ => {},

clippy_lints/src/let_if_seq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn check_assign<'a, 'tcx>(
169169
if block.expr.is_none();
170170
if let Some(expr) = block.stmts.iter().last();
171171
if let hir::StmtKind::Semi(ref expr) = expr.kind;
172-
if let hir::ExprKind::Assign(ref var, ref value) = expr.kind;
172+
if let hir::ExprKind::Assign(ref var, ref value, _) = expr.kind;
173173
if let hir::ExprKind::Path(ref qpath) = var.kind;
174174
if let Res::Local(local_id) = qpath_res(cx, qpath, var.hir_id);
175175
if decl == local_id;

clippy_lints/src/loops.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
682682
},
683683
ExprKind::Call(ref e, ref es) => never_loop_expr_all(&mut once(&**e).chain(es.iter()), main_loop_id),
684684
ExprKind::Binary(_, ref e1, ref e2)
685-
| ExprKind::Assign(ref e1, ref e2)
685+
| ExprKind::Assign(ref e1, ref e2, _)
686686
| ExprKind::AssignOp(_, ref e1, ref e2)
687687
| ExprKind::Index(ref e1, ref e2) => never_loop_expr_all(&mut [&**e1, &**e2].iter().cloned(), main_loop_id),
688688
ExprKind::Loop(ref b, _, _) => {
@@ -887,7 +887,7 @@ fn get_indexed_assignments<'a, 'tcx>(
887887
e: &Expr,
888888
var: HirId,
889889
) -> Option<(FixedOffsetVar, FixedOffsetVar)> {
890-
if let ExprKind::Assign(ref lhs, ref rhs) = e.kind {
890+
if let ExprKind::Assign(ref lhs, ref rhs, _) = e.kind {
891891
match (
892892
get_fixed_offset_var(cx, lhs, var),
893893
fetch_cloned_fixed_offset_var(cx, rhs, var),
@@ -1861,7 +1861,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18611861

18621862
let old = self.prefer_mutable;
18631863
match expr.kind {
1864-
ExprKind::AssignOp(_, ref lhs, ref rhs) | ExprKind::Assign(ref lhs, ref rhs) => {
1864+
ExprKind::AssignOp(_, ref lhs, ref rhs) | ExprKind::Assign(ref lhs, ref rhs, _) => {
18651865
self.prefer_mutable = true;
18661866
self.visit_expr(lhs);
18671867
self.prefer_mutable = false;
@@ -2083,7 +2083,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
20832083
}
20842084
}
20852085
},
2086-
ExprKind::Assign(ref lhs, _) if lhs.hir_id == expr.hir_id => *state = VarState::DontWarn,
2086+
ExprKind::Assign(ref lhs, _, _) if lhs.hir_id == expr.hir_id => *state = VarState::DontWarn,
20872087
ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mut => {
20882088
*state = VarState::DontWarn
20892089
},
@@ -2161,7 +2161,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21612161
ExprKind::AssignOp(_, ref lhs, _) if lhs.hir_id == expr.hir_id => {
21622162
self.state = VarState::DontWarn;
21632163
},
2164-
ExprKind::Assign(ref lhs, ref rhs) if lhs.hir_id == expr.hir_id => {
2164+
ExprKind::Assign(ref lhs, ref rhs, _) if lhs.hir_id == expr.hir_id => {
21652165
self.state = if is_integer_const(&self.cx, rhs, 0) && self.depth == 0 {
21662166
VarState::Warn
21672167
} else {
@@ -2303,7 +2303,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
23032303
return;
23042304
}
23052305
match expr.kind {
2306-
ExprKind::Assign(ref path, _) | ExprKind::AssignOp(_, ref path, _) => {
2306+
ExprKind::Assign(ref path, _, _) | ExprKind::AssignOp(_, ref path, _) => {
23072307
if match_var(path, self.iterator) {
23082308
self.nesting = RuledOut;
23092309
}

clippy_lints/src/misc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,9 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
590590
fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
591591
if let Some(parent) = get_parent_expr(cx, expr) {
592592
match parent.kind {
593-
ExprKind::Assign(_, ref rhs) | ExprKind::AssignOp(_, _, ref rhs) => SpanlessEq::new(cx).eq_expr(rhs, expr),
593+
ExprKind::Assign(_, ref rhs, _) | ExprKind::AssignOp(_, _, ref rhs) => {
594+
SpanlessEq::new(cx).eq_expr(rhs, expr)
595+
},
594596
_ => is_used(cx, parent),
595597
}
596598
} else {

clippy_lints/src/misc_early.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl EarlyLintPass for MiscEarlyLints {
451451
if let ExprKind::Closure(..) = t.kind;
452452
if let PatKind::Ident(_, ident, _) = local.pat.kind;
453453
if let StmtKind::Semi(ref second) = w[1].kind;
454-
if let ExprKind::Assign(_, ref call) = second.kind;
454+
if let ExprKind::Assign(_, ref call, _) = second.kind;
455455
if let ExprKind::Call(ref closure, _) = call.kind;
456456
if let ExprKind::Path(_, ref path) = closure.kind;
457457
then {

clippy_lints/src/slow_vector_initialization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SlowVectorInit {
6363
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
6464
// Matches initialization on reassignements. For example: `vec = Vec::with_capacity(100)`
6565
if_chain! {
66-
if let ExprKind::Assign(ref left, ref right) = expr.kind;
66+
if let ExprKind::Assign(ref left, ref right, _) = expr.kind;
6767

6868
// Extract variable name
6969
if let ExprKind::Path(QPath::Resolved(_, ref path)) = left.kind;

clippy_lints/src/strings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd {
9696
if !is_allowed(cx, STRING_ADD_ASSIGN, e.hir_id) {
9797
let parent = get_parent_expr(cx, e);
9898
if let Some(p) = parent {
99-
if let ExprKind::Assign(ref target, _) = p.kind {
99+
if let ExprKind::Assign(ref target, _, _) = p.kind {
100100
// avoid duplicate matches
101101
if SpanlessEq::new(cx).eq_expr(target, left) {
102102
return;
@@ -111,7 +111,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd {
111111
"you added something to a string. Consider using `String::push_str()` instead",
112112
);
113113
}
114-
} else if let ExprKind::Assign(ref target, ref src) = e.kind {
114+
} else if let ExprKind::Assign(ref target, ref src, _) = e.kind {
115115
if is_string(cx, target) && is_add(cx, src, target) {
116116
span_lint(
117117
cx,

0 commit comments

Comments
 (0)