Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve inference variables before trying to remove overloaded indexing #79427

Merged
merged 1 commit into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_typeck/src/check/writeback.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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() {}