Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eval_order_dependence async false positive #7174

Merged
merged 2 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions clippy_lints/src/eval_order_dependence.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id};
use if_chain::if_chain;
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass};
Expand Down Expand Up @@ -70,20 +71,19 @@ declare_lint_pass!(EvalOrderDependence => [EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_
impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
// Find a write to a local variable.
match expr.kind {
ExprKind::Assign(lhs, ..) | ExprKind::AssignOp(_, lhs, _) => {
if let Some(var) = path_to_local(lhs) {
let mut visitor = ReadVisitor {
cx,
var,
write_expr: expr,
last_expr: expr,
};
check_for_unsequenced_reads(&mut visitor);
}
},
_ => {},
}
let var = if_chain! {
if let ExprKind::Assign(lhs, ..) | ExprKind::AssignOp(_, lhs, _) = expr.kind;
if let Some(var) = path_to_local(lhs);
if expr.span.desugaring_kind().is_none();
then { var } else { return; }
};
let mut visitor = ReadVisitor {
cx,
var,
write_expr: expr,
last_expr: expr,
};
check_for_unsequenced_reads(&mut visitor);
}
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
match stmt.kind {
Expand Down Expand Up @@ -305,7 +305,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
self.cx,
EVAL_ORDER_DEPENDENCE,
expr.span,
"unsequenced read of a variable",
&format!("unsequenced read of `{}`", self.cx.tcx.hir().name(self.var)),
Some(self.write_expr.span),
"whether read occurs before this write depends on evaluation order",
);
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/eval_order_dependence.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// edition:2018

#[warn(clippy::eval_order_dependence)]
#[allow(
unused_assignments,
Expand Down Expand Up @@ -107,3 +109,7 @@ fn main() {
},
);
}

async fn issue_6925() {
let _ = vec![async { true }.await, async { false }.await];
}
24 changes: 12 additions & 12 deletions tests/ui/eval_order_dependence.stderr
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
error: unsequenced read of a variable
--> $DIR/eval_order_dependence.rs:15:9
error: unsequenced read of `x`
--> $DIR/eval_order_dependence.rs:17:9
|
LL | } + x;
| ^
|
= note: `-D clippy::eval-order-dependence` implied by `-D warnings`
note: whether read occurs before this write depends on evaluation order
--> $DIR/eval_order_dependence.rs:13:9
--> $DIR/eval_order_dependence.rs:15:9
|
LL | x = 1;
| ^^^^^

error: unsequenced read of a variable
--> $DIR/eval_order_dependence.rs:18:5
error: unsequenced read of `x`
--> $DIR/eval_order_dependence.rs:20:5
|
LL | x += {
| ^
|
note: whether read occurs before this write depends on evaluation order
--> $DIR/eval_order_dependence.rs:19:9
--> $DIR/eval_order_dependence.rs:21:9
|
LL | x = 20;
| ^^^^^^

error: unsequenced read of a variable
--> $DIR/eval_order_dependence.rs:31:12
error: unsequenced read of `x`
--> $DIR/eval_order_dependence.rs:33:12
|
LL | a: x,
| ^
|
note: whether read occurs before this write depends on evaluation order
--> $DIR/eval_order_dependence.rs:33:13
--> $DIR/eval_order_dependence.rs:35:13
|
LL | x = 6;
| ^^^^^

error: unsequenced read of a variable
--> $DIR/eval_order_dependence.rs:40:9
error: unsequenced read of `x`
--> $DIR/eval_order_dependence.rs:42:9
|
LL | x += {
| ^
|
note: whether read occurs before this write depends on evaluation order
--> $DIR/eval_order_dependence.rs:41:13
--> $DIR/eval_order_dependence.rs:43:13
|
LL | x = 20;
| ^^^^^^
Expand Down