Skip to content

Commit 1af490d

Browse files
Better ICE message for unresolved upvars
1 parent 213ad10 commit 1af490d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: compiler/rustc_mir_build/src/build/expr/as_place.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::build::expr::category::Category;
44
use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
55
use crate::build::{BlockAnd, BlockAndExtension, Builder, Capture, CaptureMap};
66
use rustc_hir::def_id::LocalDefId;
7-
use rustc_middle::bug;
87
use rustc_middle::hir::place::Projection as HirProjection;
98
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
109
use rustc_middle::middle::region;
@@ -13,6 +12,7 @@ use rustc_middle::mir::*;
1312
use rustc_middle::thir::*;
1413
use rustc_middle::ty::AdtDef;
1514
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, Variance};
15+
use rustc_middle::{bug, span_bug};
1616
use rustc_span::Span;
1717
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
1818
use tracing::{debug, instrument, trace};
@@ -252,7 +252,18 @@ fn strip_prefix<'a, 'tcx>(
252252

253253
impl<'tcx> PlaceBuilder<'tcx> {
254254
pub(in crate::build) fn to_place(&self, cx: &Builder<'_, 'tcx>) -> Place<'tcx> {
255-
self.try_to_place(cx).unwrap()
255+
self.try_to_place(cx).unwrap_or_else(|| match self.base {
256+
PlaceBase::Local(local) => span_bug!(
257+
cx.local_decls[local].source_info.span,
258+
"could not resolve local: {local:#?} + {:?}",
259+
self.projection
260+
),
261+
PlaceBase::Upvar { var_hir_id, closure_def_id: _ } => span_bug!(
262+
cx.tcx.hir().span(var_hir_id.0),
263+
"could not resolve upvar: {var_hir_id:?} + {:?}",
264+
self.projection
265+
),
266+
})
256267
}
257268

258269
/// Creates a `Place` or returns `None` if an upvar cannot be resolved

0 commit comments

Comments
 (0)