X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Fmixed_read_write_in_expression.rs;h=321fa4b7f9996681000b59321216a3474766df11;hb=a85c8f33ff0da5192bb44ac52cb838f638ad7c03;hp=405fc23e8de0a5b68cab209b7d34f7bd663cd5f3;hpb=bf2e63104ddb2e596f74b21502a71f9540f11d2e;p=rust.git diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index 405fc23e8de..321fa4b7f99 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -25,14 +25,16 @@ /// ```rust /// let mut x = 0; /// - /// // Bad /// let a = { /// x = 1; /// 1 /// } + x; /// // Unclear whether a is 1 or 2. + /// ``` /// - /// // Good + /// Use instead: + /// ```rust + /// # let mut x = 0; /// let tmp = { /// x = 1; /// 1 @@ -112,7 +114,7 @@ struct DivergenceVisitor<'a, 'tcx> { impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> { fn maybe_walk_expr(&mut self, e: &'tcx Expr<'_>) { match e.kind { - ExprKind::Closure(..) => {}, + ExprKind::Closure { .. } => {}, ExprKind::Match(e, arms, _) => { self.visit_expr(e); for arm in arms { @@ -120,7 +122,7 @@ fn maybe_walk_expr(&mut self, e: &'tcx Expr<'_>) { self.visit_expr(if_expr); } // make sure top level arm expressions aren't linted - self.maybe_walk_expr(&*arm.body); + self.maybe_walk_expr(arm.body); } }, _ => walk_expr(self, e), @@ -188,10 +190,7 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) { if parent_id == cur_id { break; } - let parent_node = match map.find(parent_id) { - Some(parent) => parent, - None => break, - }; + let Some(parent_node) = map.find(parent_id) else { break }; let stop_early = match parent_node { Node::Expr(expr) => check_expr(vis, expr), @@ -219,7 +218,7 @@ enum StopEarly { Stop, } -fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr<'_>) -> StopEarly { +fn check_expr<'tcx>(vis: &mut ReadVisitor<'_, 'tcx>, expr: &'tcx Expr<'_>) -> StopEarly { if expr.hir_id == vis.last_expr.hir_id { return StopEarly::KeepGoing; } @@ -243,7 +242,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr<'_>) - walk_expr(vis, expr); } }, - ExprKind::Closure(_, _, _, _, _) => { + ExprKind::Closure { .. } => { // Either // // * `var` is defined in the closure body, in which case we've reached the top of the enclosing @@ -266,7 +265,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr<'_>) - StopEarly::KeepGoing } -fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt<'_>) -> StopEarly { +fn check_stmt<'tcx>(vis: &mut ReadVisitor<'_, 'tcx>, stmt: &'tcx Stmt<'_>) -> StopEarly { match stmt.kind { StmtKind::Expr(expr) | StmtKind::Semi(expr) => check_expr(vis, expr), // If the declaration is of a local variable, check its initializer @@ -315,7 +314,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { // We're about to descend a closure. Since we don't know when (or // if) the closure will be evaluated, any reads in it might not // occur here (or ever). Like above, bail to avoid false positives. - ExprKind::Closure(_, _, _, _, _) | + ExprKind::Closure{..} | // We want to avoid a false positive when a variable name occurs // only to have its address taken, so we stop here. Technically,