about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_typeck/src/check/writeback.rs4
-rw-r--r--src/test/ui/consts/issue-79152-const-array-index.rs11
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs
index 335f2cc2716..d1ada123c0d 100644
--- a/compiler/rustc_typeck/src/check/writeback.rs
+++ b/compiler/rustc_typeck/src/check/writeback.rs
@@ -194,7 +194,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
             let mut typeck_results = self.fcx.typeck_results.borrow_mut();
 
             // All valid indexing looks like this; might encounter non-valid indexes at this point.
-            let base_ty = typeck_results.expr_ty_adjusted_opt(&base).map(|t| t.kind());
+            let base_ty = typeck_results
+                .expr_ty_adjusted_opt(&base)
+                .map(|t| self.fcx.resolve_vars_if_possible(t).kind());
             if base_ty.is_none() {
                 // When encountering `return [0][0]` outside of a `fn` body we can encounter a base
                 // that isn't in the type table. We assume more relevant errors have already been
diff --git a/src/test/ui/consts/issue-79152-const-array-index.rs b/src/test/ui/consts/issue-79152-const-array-index.rs
new file mode 100644
index 00000000000..95518e1bbdb
--- /dev/null
+++ b/src/test/ui/consts/issue-79152-const-array-index.rs
@@ -0,0 +1,11 @@
+// check-pass
+// Regression test for issue #79152
+//
+// Tests that we can index an array in a const function
+
+const fn foo() {
+    let mut array = [[0; 1]; 1];
+    array[0][0] = 1;
+}
+
+fn main() {}