Skip to content

Commit d747148

Browse files
authored
Rollup merge of #125514 - compiler-errors:builtin-index, r=lcnr
Structurally resolve before `builtin_index` in EUV r? lcnr
2 parents 3fc8fe0 + 61aac55 commit d747148

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,11 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
17411741
}
17421742

17431743
PatKind::Slice(before, ref slice, after) => {
1744-
let Some(element_ty) = place_with_id.place.ty().builtin_index() else {
1744+
let Some(element_ty) = self
1745+
.cx
1746+
.try_structurally_resolve_type(pat.span, place_with_id.place.ty())
1747+
.builtin_index()
1748+
else {
17451749
debug!("explicit index of non-indexable type {:?}", place_with_id);
17461750
return Err(self
17471751
.cx

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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
// Fixes a regression in `rustc_attr` where we weren't normalizing the
5+
// output type of a index operator performing a `Ty::builtin_index` call,
6+
// leading to an ICE.
7+
8+
fn main() {
9+
let mut vec = [1, 2, 3];
10+
let x = || {
11+
let [..] = &vec[..];
12+
};
13+
}

0 commit comments

Comments
 (0)