]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_lint/builtin.rs
Remove ExprKind::While from HIR.
[rust.git] / src / librustc_lint / builtin.rs
index 267b09bae35e427604ce0ae16f2d1ca737685ff9..d98dfb5478a366eefad92ffb70e6b97593d73e69 100644 (file)
 
 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() {