]> git.lizzy.rs Git - rust.git/commitdiff
Fix issue with recursively encountering uninhabited type
authorvarkor <github@varkor.com>
Mon, 27 May 2019 19:11:15 +0000 (20:11 +0100)
committervarkor <github@varkor.com>
Mon, 3 Jun 2019 17:19:29 +0000 (18:19 +0100)
src/librustc_lint/unused.rs

index a2bf0b894f6c11e7c7aee38da6f18717bf5e066a..bbec42b238f46be2becaf107ef46a24ce61d6a30 100644 (file)
@@ -48,14 +48,7 @@ fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
         }
 
         let ty = cx.tables.expr_ty(&expr);
-        let type_permits_lack_of_use = if ty.is_unit()
-            || cx.tcx.is_ty_uninhabited_from(
-                cx.tcx.hir().get_module_parent_by_hir_id(expr.hir_id), ty)
-        {
-            true
-        } else {
-            check_must_use_ty(cx, ty, &expr, s.span)
-        };
+        let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span);
 
         let mut fn_warned = false;
         let mut op_warned = false;
@@ -135,12 +128,18 @@ fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
         }
 
         // Returns whether an error has been emitted (and thus another does not need to be later).
-        fn check_must_use_ty(
-            cx: &LateContext<'_, '_>,
-            ty: Ty<'_>,
+        fn check_must_use_ty<'tcx>(
+            cx: &LateContext<'_, 'tcx>,
+            ty: Ty<'tcx>,
             expr: &hir::Expr,
             span: Span,
         ) -> bool {
+            if ty.is_unit() || cx.tcx.is_ty_uninhabited_from(
+                cx.tcx.hir().get_module_parent_by_hir_id(expr.hir_id), ty)
+            {
+                return true;
+            }
+
             match ty.sty {
                 ty::Adt(def, _) => check_must_use_def(cx, def.did, span, "", ""),
                 ty::Opaque(def, _) => {