about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-05-25 12:54:37 +0200
committerGitHub <noreply@github.com>2024-05-25 12:54:37 +0200
commitd747148ba86ba067f3312c9b82dcba6d10a02100 (patch)
treebdd925a1ebfd3adabab95f70c24e0f2848dd110a
parent3fc8fe0490557fa8c8cf4827943d0a75db59fd0d (diff)
parent61aac551b81573d160f19bafbf6deb83f8f0b2be (diff)
downloadrust-d747148ba86ba067f3312c9b82dcba6d10a02100.tar.gz
rust-d747148ba86ba067f3312c9b82dcba6d10a02100.zip
Rollup merge of #125514 - compiler-errors:builtin-index, r=lcnr
Structurally resolve before `builtin_index` in EUV

r? lcnr
-rw-r--r--compiler/rustc_hir_typeck/src/expr_use_visitor.rs6
-rw-r--r--compiler/rustc_mir_build/src/build/expr/as_place.rs15
-rw-r--r--tests/ui/traits/next-solver/typeck/index-of-projection.rs13
3 files changed, 31 insertions, 3 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs
index 89f62577506..0ba4bd090f5 100644
--- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs
+++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs
@@ -1741,7 +1741,11 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
             }
 
             PatKind::Slice(before, ref slice, after) => {
-                let Some(element_ty) = place_with_id.place.ty().builtin_index() else {
+                let Some(element_ty) = self
+                    .cx
+                    .try_structurally_resolve_type(pat.span, place_with_id.place.ty())
+                    .builtin_index()
+                else {
                     debug!("explicit index of non-indexable type {:?}", place_with_id);
                     return Err(self
                         .cx
diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs
index 93d0d4e59ba..4b62afa61bb 100644
--- a/compiler/rustc_mir_build/src/build/expr/as_place.rs
+++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs
@@ -4,7 +4,6 @@ use crate::build::expr::category::Category;
 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::mir::*;
 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
diff --git a/tests/ui/traits/next-solver/typeck/index-of-projection.rs b/tests/ui/traits/next-solver/typeck/index-of-projection.rs
new file mode 100644
index 00000000000..5023be0bb14
--- /dev/null
+++ b/tests/ui/traits/next-solver/typeck/index-of-projection.rs
@@ -0,0 +1,13 @@
+//@ compile-flags: -Znext-solver
+//@ check-pass
+
+// Fixes a regression in `rustc_attr` where we weren't normalizing the
+// output type of a index operator performing a `Ty::builtin_index` call,
+// leading to an ICE.
+
+fn main() {
+    let mut vec = [1, 2, 3];
+    let x = || {
+        let [..] = &vec[..];
+    };
+}