Skip to content

Commit 85a9d85

Browse files
committedDec 21, 2022
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
1 parent c6ef534 commit 85a9d85

File tree

1 file changed

+8
-11
lines changed
  • compiler/rustc_trait_selection/src/traits/error_reporting

1 file changed

+8
-11
lines changed
 

‎compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ pub trait TypeErrCtxtExt<'tcx> {
335335
err: &mut Diagnostic,
336336
trait_pred: ty::PolyTraitPredicate<'tcx>,
337337
);
338-
fn function_argument_obligation(
338+
fn note_function_argument_obligation(
339339
&self,
340340
arg_hir_id: HirId,
341341
err: &mut Diagnostic,
@@ -2909,7 +2909,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29092909
ref parent_code,
29102910
..
29112911
} => {
2912-
self.function_argument_obligation(
2912+
self.note_function_argument_obligation(
29132913
arg_hir_id,
29142914
err,
29152915
parent_code,
@@ -3141,7 +3141,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31413141
);
31423142
}
31433143
}
3144-
fn function_argument_obligation(
3144+
fn note_function_argument_obligation(
31453145
&self,
31463146
arg_hir_id: HirId,
31473147
err: &mut Diagnostic,
@@ -3152,12 +3152,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31523152
) {
31533153
let tcx = self.tcx;
31543154
let hir = tcx.hir();
3155-
if let Some(Node::Expr(expr)) = hir.find(arg_hir_id) {
3156-
let parent_id = hir.get_parent_item(arg_hir_id);
3157-
let typeck_results: &TypeckResults<'tcx> = match &self.typeck_results {
3158-
Some(t) if t.hir_owner == parent_id => t,
3159-
_ => self.tcx.typeck(parent_id.def_id),
3160-
};
3155+
if let Some(Node::Expr(expr)) = hir.find(arg_hir_id)
3156+
&& let Some(typeck_results) = &self.typeck_results
3157+
{
31613158
if let hir::Expr { kind: hir::ExprKind::Block(..), .. } = expr {
31623159
let expr = expr.peel_blocks();
31633160
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> {
32193216
// If the expression we're calling on is a binding, we want to point at the
32203217
// `let` when talking about the type. Otherwise we'll point at every part
32213218
// of the method chain with the type.
3222-
self.point_at_chain(binding_expr, typeck_results, type_diffs, param_env, err);
3219+
self.point_at_chain(binding_expr, &typeck_results, type_diffs, param_env, err);
32233220
} else {
3224-
self.point_at_chain(expr, typeck_results, type_diffs, param_env, err);
3221+
self.point_at_chain(expr, &typeck_results, type_diffs, param_env, err);
32253222
}
32263223
}
32273224
let call_node = hir.find(call_hir_id);

0 commit comments

Comments
 (0)
Please sign in to comment.