diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-11-03 12:08:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-03 12:08:54 +0100 |
| commit | 1a0ab892cd2ccb75244c52d68e9db9abca0d1065 (patch) | |
| tree | 4bf5cb067d7a163f4d6b65b2696f5d24190da4cd /compiler | |
| parent | 625264329f8019013172c158cec2068f6b162acc (diff) | |
| parent | 82f8b8f0e3f44c7280f21364b54840f59890610a (diff) | |
| download | rust-1a0ab892cd2ccb75244c52d68e9db9abca0d1065.tar.gz rust-1a0ab892cd2ccb75244c52d68e9db9abca0d1065.zip | |
Rollup merge of #132528 - compiler-errors:fallback-sugg-opt, r=jieyouxu
Use `*_opt` typeck results fns to not ICE in fallback suggestion Self-explanatory. Fixes #132517.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fallback.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index 8d8573c65c5..97f3807c252 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -643,7 +643,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> { fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) -> Self::Result { // Try to replace `_` with `()`. if let hir::TyKind::Infer = hir_ty.kind - && let ty = self.fcx.typeck_results.borrow().node_type(hir_ty.hir_id) + && let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(hir_ty.hir_id) && let Some(vid) = self.fcx.root_vid(ty) && self.reachable_vids.contains(&vid) { @@ -680,7 +680,8 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> { if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind && let Res::Def(DefKind::AssocFn, def_id) = path.res && self.fcx.tcx.trait_of_item(def_id).is_some() - && let self_ty = self.fcx.typeck_results.borrow().node_args(expr.hir_id).type_at(0) + && let Some(args) = self.fcx.typeck_results.borrow().node_args_opt(expr.hir_id) + && let self_ty = args.type_at(0) && let Some(vid) = self.fcx.root_vid(self_ty) && self.reachable_vids.contains(&vid) && let [.., trait_segment, _method_segment] = path.segments @@ -701,7 +702,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> { fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) -> Self::Result { // For a local, try suggest annotating the type if it's missing. if let None = local.ty - && let ty = self.fcx.typeck_results.borrow().node_type(local.hir_id) + && let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(local.hir_id) && let Some(vid) = self.fcx.root_vid(ty) && self.reachable_vids.contains(&vid) { |
