Better ICE message for unresolved upvars

This commit is contained in:
Michael Goulet 2024-05-24 15:47:50 -04:00
parent 213ad10c8f
commit 1af490de42

View File

@ -4,7 +4,6 @@
use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
use crate::build::{BlockAnd, BlockAndExtension, Builder, Capture, CaptureMap};
use rustc_hir::def_id::LocalDefId;
use rustc_middle::bug;
use rustc_middle::hir::place::Projection as HirProjection;
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
use rustc_middle::middle::region;
@ -13,6 +12,7 @@
use rustc_middle::thir::*;
use rustc_middle::ty::AdtDef;
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, Variance};
use rustc_middle::{bug, span_bug};
use rustc_span::Span;
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
use tracing::{debug, instrument, trace};
@ -252,7 +252,18 @@ fn strip_prefix<'a, 'tcx>(
impl<'tcx> PlaceBuilder<'tcx> {
pub(in crate::build) fn to_place(&self, cx: &Builder<'_, 'tcx>) -> Place<'tcx> {
self.try_to_place(cx).unwrap()
self.try_to_place(cx).unwrap_or_else(|| match self.base {
PlaceBase::Local(local) => span_bug!(
cx.local_decls[local].source_info.span,
"could not resolve local: {local:#?} + {:?}",
self.projection
),
PlaceBase::Upvar { var_hir_id, closure_def_id: _ } => span_bug!(
cx.tcx.hir().span(var_hir_id.0),
"could not resolve upvar: {var_hir_id:?} + {:?}",
self.projection
),
})
}
/// Creates a `Place` or returns `None` if an upvar cannot be resolved