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

+1-1
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

+3-3
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

+1-1
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

+1-1
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

+1-1
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

+6-6
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

+3-1
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

+1-1
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

+1-1
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

+2-2
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,

clippy_lints/src/swap.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) {
8686

8787
// foo() = bar();
8888
if let StmtKind::Semi(ref first) = w[1].kind;
89-
if let ExprKind::Assign(ref lhs1, ref rhs1) = first.kind;
89+
if let ExprKind::Assign(ref lhs1, ref rhs1, _) = first.kind;
9090

9191
// bar() = t;
9292
if let StmtKind::Semi(ref second) = w[2].kind;
93-
if let ExprKind::Assign(ref lhs2, ref rhs2) = second.kind;
93+
if let ExprKind::Assign(ref lhs2, ref rhs2, _) = second.kind;
9494
if let ExprKind::Path(QPath::Resolved(None, ref rhs2)) = rhs2.kind;
9595
if rhs2.segments.len() == 1;
9696

@@ -222,8 +222,8 @@ fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) {
222222
if let StmtKind::Semi(ref first) = w[0].kind;
223223
if let StmtKind::Semi(ref second) = w[1].kind;
224224
if !differing_macro_contexts(first.span, second.span);
225-
if let ExprKind::Assign(ref lhs0, ref rhs0) = first.kind;
226-
if let ExprKind::Assign(ref lhs1, ref rhs1) = second.kind;
225+
if let ExprKind::Assign(ref lhs0, ref rhs0, _) = first.kind;
226+
if let ExprKind::Assign(ref lhs1, ref rhs1, _) = second.kind;
227227
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs0, rhs1);
228228
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, rhs0);
229229
then {

clippy_lints/src/temporary_assignment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ declare_lint_pass!(TemporaryAssignment => [TEMPORARY_ASSIGNMENT]);
4242

4343
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TemporaryAssignment {
4444
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
45-
if let ExprKind::Assign(target, _) = &expr.kind {
45+
if let ExprKind::Assign(target, ..) = &expr.kind {
4646
let mut base = target;
4747
while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.kind {
4848
base = f;

clippy_lints/src/utils/author.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,13 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
380380
self.current = block_pat;
381381
self.visit_block(block);
382382
},
383-
ExprKind::Assign(ref target, ref value) => {
383+
ExprKind::Assign(ref target, ref value, _) => {
384384
let target_pat = self.next("target");
385385
let value_pat = self.next("value");
386-
println!("Assign(ref {}, ref {}) = {};", target_pat, value_pat, current);
386+
println!(
387+
"Assign(ref {}, ref {}, ref _span) = {};",
388+
target_pat, value_pat, current
389+
);
387390
self.current = target_pat;
388391
self.visit_expr(target);
389392
self.current = value_pat;

clippy_lints/src/utils/hir_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
8484
(&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
8585
both(&li.label, &ri.label, |l, r| l.ident.as_str() == r.ident.as_str())
8686
},
87-
(&ExprKind::Assign(ref ll, ref lr), &ExprKind::Assign(ref rl, ref rr)) => {
87+
(&ExprKind::Assign(ref ll, ref lr, _), &ExprKind::Assign(ref rl, ref rr, _)) => {
8888
self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
8989
},
9090
(&ExprKind::AssignOp(ref lo, ref ll, ref lr), &ExprKind::AssignOp(ref ro, ref rl, ref rr)) => {
@@ -412,7 +412,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
412412
self.hash_name(i.ident.name);
413413
}
414414
},
415-
ExprKind::Assign(ref l, ref r) => {
415+
ExprKind::Assign(ref l, ref r, _) => {
416416
self.hash_expr(l);
417417
self.hash_expr(r);
418418
},

clippy_lints/src/utils/inspector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
229229
hir::ExprKind::Block(_, _) => {
230230
println!("{}Block", ind);
231231
},
232-
hir::ExprKind::Assign(ref lhs, ref rhs) => {
232+
hir::ExprKind::Assign(ref lhs, ref rhs, _) => {
233233
println!("{}Assign", ind);
234234
println!("{}lhs:", ind);
235235
print_expr(cx, lhs, indent + 1);

clippy_lints/src/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (O
395395
}
396396
idx += 1;
397397
},
398-
ExprKind::Assign(lhs, rhs) => {
398+
ExprKind::Assign(lhs, rhs, _) => {
399399
if let ExprKind::Lit(_) = rhs.kind {
400400
if let ExprKind::Path(_, p) = &lhs.kind {
401401
let mut all_simple = true;

tests/ui/author/for_loop.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if_chain! {
2626
if let ExprKind::Path(ref path3) = inner.kind;
2727
if match_qpath(path3, &["iter"]);
2828
if arms1.len() == 2;
29-
if let ExprKind::Assign(ref target, ref value) = arms1[0].body.kind;
29+
if let ExprKind::Assign(ref target, ref value, ref _span) = arms1[0].body.kind;
3030
if let ExprKind::Path(ref path4) = target.kind;
3131
if match_qpath(path4, &["__next"]);
3232
if let ExprKind::Path(ref path5) = value.kind;

tests/ui/missing_const_for_fn/could_be_const.rs

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ fn generic<T>(t: T) -> T {
4141
t
4242
}
4343

44-
// FIXME: Depends on the `const_transmute` and `const_fn` feature gates.
45-
// In the future Clippy should be able to suggest this as const, too.
4644
fn sub(x: u32) -> usize {
4745
unsafe { transmute(&x) }
4846
}

tests/ui/missing_const_for_fn/could_be_const.stderr

+10-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,20 @@ LL | | }
5050
| |_^
5151

5252
error: this could be a const_fn
53-
--> $DIR/could_be_const.rs:65:9
53+
--> $DIR/could_be_const.rs:44:1
54+
|
55+
LL | / fn sub(x: u32) -> usize {
56+
LL | | unsafe { transmute(&x) }
57+
LL | | }
58+
| |_^
59+
60+
error: this could be a const_fn
61+
--> $DIR/could_be_const.rs:63:9
5462
|
5563
LL | / pub fn b(self, a: &A) -> B {
5664
LL | | B
5765
LL | | }
5866
| |_________^
5967

60-
error: aborting due to 7 previous errors
68+
error: aborting due to 8 previous errors
6169

0 commit comments

Comments
 (0)