@@ -59,15 +59,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
59
59
}
60
60
61
61
let t = cx. tables . expr_ty ( & expr) ;
62
- let ty_warned = match t. sty {
63
- ty:: Tuple ( ref tys) if tys. is_empty ( ) => return ,
64
- ty:: Never => return ,
62
+ // FIXME(varkor): replace with `t.is_unit() || t.conservative_is_uninhabited()`.
63
+ let type_permits_no_use = match t. sty {
64
+ ty:: Tuple ( ref tys) if tys. is_empty ( ) => true ,
65
+ ty:: Never => true ,
65
66
ty:: Adt ( def, _) => {
66
67
if def. variants . is_empty ( ) {
67
- return ;
68
+ true
69
+ } else {
70
+ check_must_use ( cx, def. did , s. span , "" )
68
71
}
69
- check_must_use ( cx, def. did , s. span , "" )
70
- } ,
72
+ }
71
73
_ => false ,
72
74
} ;
73
75
@@ -95,7 +97,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
95
97
if let Some ( def) = maybe_def {
96
98
let def_id = def. def_id ( ) ;
97
99
fn_warned = check_must_use ( cx, def_id, s. span , "return value of " ) ;
100
+ } else if type_permits_no_use {
101
+ // We don't warn about unused unit or uninhabited types.
102
+ // (See https://github.com/rust-lang/rust/issues/43806 for details.)
103
+ return ;
98
104
}
105
+
99
106
let must_use_op = match expr. node {
100
107
// Hardcoding operators here seemed more expedient than the
101
108
// refactoring that would be needed to look up the `#[must_use]`
@@ -139,7 +146,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
139
146
op_warned = true ;
140
147
}
141
148
142
- if !( ty_warned || fn_warned || op_warned) {
149
+ if !( type_permits_no_use || fn_warned || op_warned) {
143
150
cx. span_lint ( UNUSED_RESULTS , s. span , "unused result" ) ;
144
151
}
145
152
@@ -233,7 +240,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
233
240
. find ( |& & ( builtin, ty, _) | name == builtin && ty == AttributeType :: CrateLevel )
234
241
. is_some ( ) ;
235
242
236
- // Has a plugin registered this attribute as one which must be used at
243
+ // Has a plugin registered this attribute as one that must be used at
237
244
// the crate level?
238
245
let plugin_crate = plugin_attributes. iter ( )
239
246
. find ( |& & ( ref x, t) | name == & * * x && AttributeType :: CrateLevel == t)
0 commit comments