@@ -60,19 +60,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
6060 }
6161
6262 let t = cx. tables . expr_ty ( & expr) ;
63- // FIXME(varkor): replace with `t.is_unit() || t.conservative_is_uninhabited()`.
64- let type_permits_no_use = match t. sty {
65- ty:: Tuple ( ref tys) if tys. is_empty ( ) => true ,
66- ty:: Never => true ,
67- ty:: Adt ( def, _) => {
68- if def. variants . is_empty ( ) {
69- true
70- } else {
71- check_must_use ( cx, def. did , s. span , "" )
72- }
63+ let type_permits_lack_of_use = if t. is_unit ( )
64+ || cx. tcx . is_ty_uninhabited_from ( cx. tcx . hir . get_module_parent ( expr. id ) , t) {
65+ true
66+ } else {
67+ match t. sty {
68+ ty:: Adt ( def, _) => check_must_use ( cx, def. did , s. span , "" ) ,
69+ _ => false ,
7370 }
74- _ => false ,
75- } ;
71+ }
7672
7773 let mut fn_warned = false ;
7874 let mut op_warned = false ;
@@ -99,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
9995 if let Some ( def) = maybe_def {
10096 let def_id = def. def_id ( ) ;
10197 fn_warned = check_must_use ( cx, def_id, s. span , "return value of " ) ;
102- } else if type_permits_no_use {
98+ } else if type_permits_lack_of_use {
10399 // We don't warn about unused unit or uninhabited types.
104100 // (See https://github.com/rust-lang/rust/issues/43806 for details.)
105101 return ;
@@ -148,7 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
148144 op_warned = true ;
149145 }
150146
151- if !( type_permits_no_use || fn_warned || op_warned) {
147+ if !( type_permits_lack_of_use || fn_warned || op_warned) {
152148 cx. span_lint ( UNUSED_RESULTS , s. span , "unused result" ) ;
153149 }
154150
0 commit comments