Skip to content

Commit

Permalink
Resolve inference variables before trying to remove overloaded indexing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Aaron1011 committed Nov 25, 2020
1 parent db79d2f commit 0b64110
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_typeck/src/check/writeback.rs
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions 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() {}

0 comments on commit 0b64110

Please sign in to comment.