-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Fix regionck failure when converting Index to IndexMut #74960
Conversation
This comment has been minimized.
This comment has been minimized.
r? @nikomatsakis I suppose, will try to check in on this soon |
@@ -246,15 +246,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
|
|||
match expr.kind { | |||
hir::ExprKind::Index(ref base_expr, ref index_expr) => { | |||
// We need to get the final type in case dereferences were needed for the trait | |||
// to apply (#72002). | |||
let index_expr_ty = self.typeck_results.borrow().expr_ty_adjusted(index_expr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I narrowed down the issue to this line. This will cause the actual type (and lifetime) of index expression to be used, rather than a supertype of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if there is a way to retrieve the input_ty in try_index_step. If we could we could just use it as index_expr_ty.
@nikomatsakis have you had time to go through this? The issue it fixes is P-critical and regression-from-stable-to-beta, so we'd need to address it asap and backport to beta. |
@bors r+ sorry. I don't 100% understand what went wrong, but this fix seems good. |
📌 Commit 000f5cd has been approved by |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit 000f5cd has been approved by |
beta-nominating as a fix for for a stable-to-beta regression. |
Adding |
Rollup of 9 pull requests Successful merges: - rust-lang#74521 (older toolchains not valid anymore) - rust-lang#74960 (Fix regionck failure when converting Index to IndexMut) - rust-lang#75234 (Update asm! documentation in unstable book) - rust-lang#75368 (Move to doc links inside the prelude) - rust-lang#75371 (Move to doc links inside std/time.rs) - rust-lang#75394 (Add a function to `TyCtxt` for computing an `Allocation` for a `static` item's initializer) - rust-lang#75395 (Switch to intra-doc links in library/std/src/os/*/fs.rs) - rust-lang#75422 (Accept more safety comments) - rust-lang#75424 (fix wrong word in documentation) Failed merges: r? @ghost
…ulacrum [beta] backports * Fix regionck failure when converting Index to IndexMut rust-lang#74960 * Update RELEASES.md for 1.46.0 rust-lang#74744 * allow escaping bound vars when normalizing `ty::Opaque` rust-lang#75443 r? @ghost
Fixes #74933
Consider an overloaded index expression
base[index]
. Without knowing whether it will be mutated, this will initially be desugared into<U as Index<T>>::index(&base, index)
for someU
andT
. LetV
be theexpr_ty_adjusted
ofindex
.If this expression ends up being used in any mutable context (or used in a function call with
&mut self
receiver before #72280), we will need to fix it up. The current code will rewrite it to<U as IndexMut<V>>::index_mut(&mut base, index)
. In most cases this is fine asV
will be equal toT
, however this is not always true whenV/T
are references, as they may have different region.This issue is quite subtle before #72280 as this code path is only used to fixup function receivers, but after #72280 we've made this a common path.
The solution is basically just rewrite it to
<U as IndexMut<T>>::index_mut(&mut base, index)
.T
can retrieved in the fixup path usingnode_substs
.