Skip to content

Commit 2edad7d

Browse files
Apply suggestions from the review
- Use `expr.hir_id.owner` instead of `self.tcx.parent_module(expr.hir_id)` - Use `.type_at()` instead of `.first()` + `.expect_ty()` - Use single `.find()` with `&&` condition Co-authored-by: Michael Goulet <[email protected]>
1 parent da2752e commit 2edad7d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

compiler/rustc_typeck/src/check/demand.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
358358
let sole_field = &variant.fields[0];
359359

360360
if !sole_field.did.is_local()
361-
&& !sole_field.vis.is_accessible_from(
362-
self.tcx.parent_module(expr.hir_id).to_def_id(),
363-
self.tcx,
364-
)
361+
&& !sole_field
362+
.vis
363+
.is_accessible_from(expr.hir_id.owner.to_def_id(), self.tcx)
365364
{
366365
return None;
367366
}
@@ -433,8 +432,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
433432
// In case Option<NonZero*> is wanted, but * is provided, suggest calling new
434433
ty::Adt(adt, substs) if tcx.is_diagnostic_item(sym::Option, adt.did()) => {
435434
// Unwrap option
436-
let Some(fst) = substs.first() else { return };
437-
let ty::Adt(adt, _) = fst.expect_ty().kind() else { return };
435+
let ty::Adt(adt, _) = substs.type_at(0).kind() else { return };
438436

439437
(adt, "")
440438
}
@@ -458,8 +456,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
458456

459457
let Some((s, _)) = map
460458
.iter()
461-
.find(|&&(s, _)| self.tcx.is_diagnostic_item(s, adt.did()))
462-
.filter(|&&(_, t)| { self.can_coerce(expr_ty, t) })
459+
.find(|&&(s, t)| self.tcx.is_diagnostic_item(s, adt.did()) && self.can_coerce(expr_ty, t))
463460
else { return };
464461

465462
let path = self.tcx.def_path_str(adt.non_enum_variant().def_id);

0 commit comments

Comments
 (0)