@@ -60,19 +60,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
60
60
}
61
61
62
62
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 ,
73
70
}
74
- _ => false ,
75
- } ;
71
+ }
76
72
77
73
let mut fn_warned = false ;
78
74
let mut op_warned = false ;
@@ -99,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
99
95
if let Some ( def) = maybe_def {
100
96
let def_id = def. def_id ( ) ;
101
97
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 {
103
99
// We don't warn about unused unit or uninhabited types.
104
100
// (See https://github.com/rust-lang/rust/issues/43806 for details.)
105
101
return ;
@@ -148,7 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
148
144
op_warned = true ;
149
145
}
150
146
151
- if !( type_permits_no_use || fn_warned || op_warned) {
147
+ if !( type_permits_lack_of_use || fn_warned || op_warned) {
152
148
cx. span_lint ( UNUSED_RESULTS , s. span , "unused result" ) ;
153
149
}
154
150
0 commit comments