Rollup merge of #110193 - compiler-errors:body-owner-issue, r=WaffleLapkin

Check for body owner fallibly in error reporting

Sometimes the "body id" we use for an obligation cause is not actually a body owner, like when we're doing WF checking on items.

Fixes #110157
This commit is contained in:
Matthias Krüger 2023-04-13 21:58:36 +02:00 committed by GitHub
commit 232eb698ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View file

@ -2396,8 +2396,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
if let Some(ty::subst::GenericArgKind::Type(_)) = subst.map(|subst| subst.unpack())
&& let Some(body_id) = self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id)
{
let body_id = self.tcx.hir().body_owned_by(obligation.cause.body_id);
let mut expr_finder = FindExprBySpan::new(span);
expr_finder.visit_expr(&self.tcx.hir().body(body_id).value);