about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-07-19 02:15:56 +0400
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-07-19 02:15:56 +0400
commit2edad7d77c91145b594ac80c3dc7906998b7674a (patch)
treee6c885e01e980ca89f3ea98477517654a89ed388
parentda2752e00f0139fb13282b2bd97aa0f8c665aee9 (diff)
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 <michael@errs.io>
-rw-r--r--compiler/rustc_typeck/src/check/demand.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs
index 30d7cc2e5fc..e5f8b6b5f1e 100644
--- a/compiler/rustc_typeck/src/check/demand.rs
+++ b/compiler/rustc_typeck/src/check/demand.rs
@@ -358,10 +358,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     let sole_field = &variant.fields[0];
 
                     if !sole_field.did.is_local()
-                        && !sole_field.vis.is_accessible_from(
-                            self.tcx.parent_module(expr.hir_id).to_def_id(),
-                            self.tcx,
-                        )
+                        && !sole_field
+                            .vis
+                            .is_accessible_from(expr.hir_id.owner.to_def_id(), self.tcx)
                     {
                         return None;
                     }
@@ -433,8 +432,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             // In case Option<NonZero*> is wanted, but * is provided, suggest calling new
             ty::Adt(adt, substs) if tcx.is_diagnostic_item(sym::Option, adt.did()) => {
                 // Unwrap option
-                let Some(fst) = substs.first() else { return };
-                let ty::Adt(adt, _) = fst.expect_ty().kind() else { return };
+                let ty::Adt(adt, _) = substs.type_at(0).kind() else { return };
 
                 (adt, "")
             }
@@ -458,8 +456,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
         let Some((s, _)) = map
             .iter()
-            .find(|&&(s, _)| self.tcx.is_diagnostic_item(s, adt.did()))
-            .filter(|&&(_, t)| { self.can_coerce(expr_ty, t) })
+            .find(|&&(s, t)| self.tcx.is_diagnostic_item(s, adt.did()) && self.can_coerce(expr_ty, t))
             else { return };
 
         let path = self.tcx.def_path_str(adt.non_enum_variant().def_id);