X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_lint%2Fbuiltin.rs;h=d98dfb5478a366eefad92ffb70e6b97593d73e69;hb=f8b32dfb27976f52b47bb278fee397b65efddc18;hp=267b09bae35e427604ce0ae16f2d1ca737685ff9;hpb=481068a707679257e2a738b40987246e0420e787;p=rust.git diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 267b09bae35..d98dfb5478a 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -64,9 +64,25 @@ declare_lint_pass!(WhileTrue => [WHILE_TRUE]); +fn as_while_cond(expr: &hir::Expr) -> Option<&hir::Expr> { + if let hir::ExprKind::Loop(blk, ..) = &expr.node { + if let Some(match_expr) = &blk.expr { + if let hir::ExprKind::Match(cond, .., hir::MatchSource::WhileDesugar) + = &match_expr.node + { + if let hir::ExprKind::DropTemps(cond) = &cond.node { + return Some(cond); + } + } + } + } + + None +} + impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue { fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) { - if let hir::ExprKind::While(ref cond, ..) = e.node { + if let Some(ref cond) = as_while_cond(e) { if let hir::ExprKind::Lit(ref lit) = cond.node { if let ast::LitKind::Bool(true) = lit.node { if lit.span.ctxt() == SyntaxContext::empty() {