Rollup merge of #131802 - compiler-errors:fnonce-coverage, r=Zalathar

Dont ICE when computing coverage of synthetic async closure body

I'm not totally certain if this is *right*, but at least it doesn't ICE.

The issue is that we end up generating two MIR bodies for each async closure, since the `FnOnce` and `Fn`/`FnMut` implementations have different borrowing behavior of their captured variables. They should ideally both contribute to the coverage, since those MIR bodies are (*to the user*) the same code and should have no behavioral differences.

This PR at least suppresses the ICEs, and then I guess worst case we can fix this the right way later.

r? Zalathar or re-roll

Fixes #131190
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-10-18 12:00:51 +01:00 committed by GitHub
commit aae4730c78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 102 additions and 19 deletions

View file

@ -223,6 +223,7 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>(
// Inherited from the by-ref coroutine.
body_def.codegen_fn_attrs(tcx.codegen_fn_attrs(coroutine_def_id).clone());
body_def.coverage_attr_on(tcx.coverage_attr_on(coroutine_def_id));
body_def.constness(tcx.constness(coroutine_def_id));
body_def.coroutine_kind(tcx.coroutine_kind(coroutine_def_id));
body_def.def_ident_span(tcx.def_ident_span(coroutine_def_id));

View file

@ -524,6 +524,11 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
// FIXME(#79625): Consider improving MIR to provide the information needed, to avoid going back
// to HIR for it.
// HACK: For synthetic MIR bodies (async closures), use the def id of the HIR body.
if tcx.is_synthetic_mir(def_id) {
return extract_hir_info(tcx, tcx.local_parent(def_id));
}
let hir_node = tcx.hir_node_by_def_id(def_id);
let fn_body_id = hir_node.body_id().expect("HIR node is a function with body");
let hir_body = tcx.hir().body(fn_body_id);