@@ -643,7 +643,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
643
643
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) -> Self::Result {
644
644
// Try to replace `_` with `()`.
645
645
if let hir::TyKind::Infer = hir_ty.kind
646
- && let ty = self.fcx.typeck_results.borrow().node_type (hir_ty.hir_id)
646
+ && let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt (hir_ty.hir_id)
647
647
&& let Some(vid) = self.fcx.root_vid(ty)
648
648
&& self.reachable_vids.contains(&vid)
649
649
{
@@ -680,7 +680,8 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
680
680
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
681
681
&& let Res::Def(DefKind::AssocFn, def_id) = path.res
682
682
&& self.fcx.tcx.trait_of_item(def_id).is_some()
683
- && let self_ty = self.fcx.typeck_results.borrow().node_args(expr.hir_id).type_at(0)
683
+ && let Some(args) = self.fcx.typeck_results.borrow().node_args_opt(expr.hir_id)
684
+ && let self_ty = args.type_at(0)
684
685
&& let Some(vid) = self.fcx.root_vid(self_ty)
685
686
&& self.reachable_vids.contains(&vid)
686
687
&& let [.., trait_segment, _method_segment] = path.segments
@@ -701,7 +702,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
701
702
fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) -> Self::Result {
702
703
// For a local, try suggest annotating the type if it's missing.
703
704
if let None = local.ty
704
- && let ty = self.fcx.typeck_results.borrow().node_type (local.hir_id)
705
+ && let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt (local.hir_id)
705
706
&& let Some(vid) = self.fcx.root_vid(ty)
706
707
&& self.reachable_vids.contains(&vid)
707
708
{
0 commit comments