|
92 | 92 | let value = infcx.commit_if_ok(|_| { |
93 | 93 | let ocx = ObligationCtxt::new(infcx); |
94 | 94 | let value = op(&ocx).map_err(|_| { |
95 | | - infcx.dcx().span_delayed_bug(span, format!("error performing operation: {name}")) |
| 95 | + infcx.tcx.check_potentially_region_dependent_goals(root_def_id).err().unwrap_or_else( |
| 96 | + // FIXME: In this region-dependent context, `type_op` should only fail due to |
| 97 | + // region-dependent goals. Any other kind of failure indicates a bug and we |
| 98 | + // should ICE. |
| 99 | + // |
| 100 | + // In principle, all non-region errors are expected to be emitted before |
| 101 | + // borrowck. Such errors should taint the body and prevent borrowck from |
| 102 | + // running at all. However, this invariant does not currently hold. |
| 103 | + // |
| 104 | + // Consider: |
| 105 | + // |
| 106 | + // ```ignore (illustrative) |
| 107 | + // struct Foo<T>(T) |
| 108 | + // where |
| 109 | + // T: Iterator, |
| 110 | + // <T as Iterator>::Item: Default; |
| 111 | + // |
| 112 | + // fn foo<T>() -> Foo<T> { |
| 113 | + // loop {} |
| 114 | + // } |
| 115 | + // ``` |
| 116 | + // |
| 117 | + // Here, `fn foo` ought to error and taint the body before MIR build, since |
| 118 | + // `Foo<T>` is not well-formed. However, we currently avoid checking this |
| 119 | + // during HIR typeck to prevent duplicate diagnostics. |
| 120 | + // |
| 121 | + // If we ICE here on any non-region-dependent failure, we would trigger ICEs |
| 122 | + // too often for such cases. For now, we emit a delayed bug instead. |
| 123 | + || { |
| 124 | + infcx |
| 125 | + .dcx() |
| 126 | + .span_delayed_bug(span, format!("error performing operation: {name}")) |
| 127 | + }, |
| 128 | + ) |
96 | 129 | })?; |
97 | 130 | let errors = ocx.evaluate_obligations_error_on_ambiguity(); |
98 | 131 | if errors.is_empty() { |
|
0 commit comments