Skip to content

Commit 0b64110

Browse files
committed
Resolve inference variables before trying to remove overloaded indexing
Fixes #79152 This code was already set up to handle indexing an array. However, it appears that we never end up with an inference variable for the slice case, so the missing call to `resolve_vars_if_possible` had no effect until now.
1 parent db79d2f commit 0b64110

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

compiler/rustc_typeck/src/check/writeback.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
194194
let mut typeck_results = self.fcx.typeck_results.borrow_mut();
195195

196196
// All valid indexing looks like this; might encounter non-valid indexes at this point.
197-
let base_ty = typeck_results.expr_ty_adjusted_opt(&base).map(|t| t.kind());
197+
let base_ty = typeck_results
198+
.expr_ty_adjusted_opt(&base)
199+
.map(|t| self.fcx.resolve_vars_if_possible(t).kind());
198200
if base_ty.is_none() {
199201
// When encountering `return [0][0]` outside of a `fn` body we can encounter a base
200202
// that isn't in the type table. We assume more relevant errors have already been
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
// Regression test for issue #79152
3+
//
4+
// Tests that we can index an array in a const function
5+
6+
const fn foo() {
7+
let mut array = [[0; 1]; 1];
8+
array[0][0] = 1;
9+
}
10+
11+
fn main() {}

0 commit comments

Comments
 (0)