Skip to content

Commit 2997070

Browse files
committed
unused_must_use: Factor out a variable for the parent module DefId
This simplifies the initial conditional, and will allow reusing the variable in subsequent checks.
1 parent e2c96cc commit 2997070

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

compiler/rustc_lint/src/unused.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
273273
expr: &hir::Expr<'_>,
274274
span: Span,
275275
) -> Option<MustUsePath> {
276-
if ty.is_unit()
277-
|| !ty.is_inhabited_from(
278-
cx.tcx,
279-
cx.tcx.parent_module(expr.hir_id).to_def_id(),
280-
cx.typing_env(),
281-
)
282-
{
276+
if ty.is_unit() {
277+
return Some(MustUsePath::Suppressed);
278+
}
279+
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()) {
283281
return Some(MustUsePath::Suppressed);
284282
}
285283

0 commit comments

Comments
 (0)