diff options
| author | Michael Goulet <michael@errs.io> | 2022-12-21 05:49:12 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-12-21 06:06:47 +0000 |
| commit | 85a9d85435ec60b840f54a03460412c261517d12 (patch) | |
| tree | cdc77dab792355b52cb3c26ff204da5026111490 | |
| parent | c6ef53477ee68ace77bead81439971a71669b22f (diff) | |
| download | rust-85a9d85435ec60b840f54a03460412c261517d12.tar.gz rust-85a9d85435ec60b840f54a03460412c261517d12.zip | |
Don't call typeck if we have no typeck results
This has a 10000000% chance of us causing a cycle if we're not careful
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index ba1ef324866..eb5e1d5ad5c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -335,7 +335,7 @@ pub trait TypeErrCtxtExt<'tcx> { err: &mut Diagnostic, trait_pred: ty::PolyTraitPredicate<'tcx>, ); - fn function_argument_obligation( + fn note_function_argument_obligation( &self, arg_hir_id: HirId, err: &mut Diagnostic, @@ -2909,7 +2909,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ref parent_code, .. } => { - self.function_argument_obligation( + self.note_function_argument_obligation( arg_hir_id, err, parent_code, @@ -3141,7 +3141,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ); } } - fn function_argument_obligation( + fn note_function_argument_obligation( &self, arg_hir_id: HirId, err: &mut Diagnostic, @@ -3152,12 +3152,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ) { let tcx = self.tcx; let hir = tcx.hir(); - if let Some(Node::Expr(expr)) = hir.find(arg_hir_id) { - let parent_id = hir.get_parent_item(arg_hir_id); - let typeck_results: &TypeckResults<'tcx> = match &self.typeck_results { - Some(t) if t.hir_owner == parent_id => t, - _ => self.tcx.typeck(parent_id.def_id), - }; + if let Some(Node::Expr(expr)) = hir.find(arg_hir_id) + && let Some(typeck_results) = &self.typeck_results + { if let hir::Expr { kind: hir::ExprKind::Block(..), .. } = expr { let expr = expr.peel_blocks(); let ty = typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(tcx.ty_error()); @@ -3219,9 +3216,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // If the expression we're calling on is a binding, we want to point at the // `let` when talking about the type. Otherwise we'll point at every part // of the method chain with the type. - self.point_at_chain(binding_expr, typeck_results, type_diffs, param_env, err); + self.point_at_chain(binding_expr, &typeck_results, type_diffs, param_env, err); } else { - self.point_at_chain(expr, typeck_results, type_diffs, param_env, err); + self.point_at_chain(expr, &typeck_results, type_diffs, param_env, err); } } let call_node = hir.find(call_hir_id); |
