Skip to content

Commit 7aa7ecc

Browse files
committed
Factor out a helper function to check if a type is uninhabited
1 parent 2d95dfd commit 7aa7ecc

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

compiler/rustc_lint/src/unused.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
277277
return Some(MustUsePath::Suppressed);
278278
}
279279
let parent_mod_did = cx.tcx.parent_module(expr.hir_id).to_def_id();
280-
if !ty.is_inhabited_from(cx.tcx, parent_mod_did, cx.typing_env()) {
280+
let is_uninhabited =
281+
|t: Ty<'tcx>| !t.is_inhabited_from(cx.tcx, parent_mod_did, cx.typing_env());
282+
if is_uninhabited(ty) {
281283
return Some(MustUsePath::Suppressed);
282284
}
283285

@@ -295,23 +297,15 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
295297
ty::Adt(def, args)
296298
if cx.tcx.is_diagnostic_item(sym::Result, def.did())
297299
&& args.type_at(0).is_unit()
298-
&& !args.type_at(1).is_inhabited_from(
299-
cx.tcx,
300-
parent_mod_did,
301-
cx.typing_env(),
302-
) =>
300+
&& is_uninhabited(args.type_at(1)) =>
303301
{
304302
Some(MustUsePath::Suppressed)
305303
}
306304
// Suppress warnings on `ControlFlow<Uninhabited, ()>` (e.g. `ControlFlow<!, ()>`).
307305
ty::Adt(def, args)
308306
if cx.tcx.is_diagnostic_item(sym::ControlFlow, def.did())
309307
&& args.type_at(1).is_unit()
310-
&& !args.type_at(0).is_inhabited_from(
311-
cx.tcx,
312-
parent_mod_did,
313-
cx.typing_env(),
314-
) =>
308+
&& is_uninhabited(args.type_at(0)) =>
315309
{
316310
Some(MustUsePath::Suppressed)
317311
}

0 commit comments

Comments
 (0)