about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2019-05-27 20:11:15 +0100
committervarkor <github@varkor.com>2019-06-03 18:19:29 +0100
commit3c768ade4d7c18db873c201a8aebda0f9c243a30 (patch)
tree0698f59c338effc3ce747a5a539b66b9c6975510
parente121d9671afe4eae1f418db14a6fdae07652c51c (diff)
downloadrust-3c768ade4d7c18db873c201a8aebda0f9c243a30.tar.gz
rust-3c768ade4d7c18db873c201a8aebda0f9c243a30.zip
Fix issue with recursively encountering uninhabited type
-rw-r--r--src/librustc_lint/unused.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs
index a2bf0b894f6..bbec42b238f 100644
--- a/src/librustc_lint/unused.rs
+++ b/src/librustc_lint/unused.rs
@@ -48,14 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
         }
 
         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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
         }
 
         // 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, _) => {