Fix regionck failure when converting Index to IndexMut#74960
Fix regionck failure when converting Index to IndexMut#74960bors merged 2 commits intorust-lang:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
|
r? @nikomatsakis I suppose, will try to check in on this soon |
There was a problem hiding this comment.
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.
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 someUandT. LetVbe theexpr_ty_adjustedofindex.If this expression ends up being used in any mutable context (or used in a function call with
&mut selfreceiver 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 asVwill be equal toT, however this is not always true whenV/Tare 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).Tcan retrieved in the fixup path usingnode_substs.