Handle generic reborrow in expression-use adjustment walking#156795
Open
P8L1 wants to merge 1 commit into
Open
Handle generic reborrow in expression-use adjustment walking#156795P8L1 wants to merge 1 commit into
P8L1 wants to merge 1 commit into
Conversation
Collaborator
|
rustbot has assigned @nikomatsakis. Use Why was this reviewer chosen?The reviewer was selected based on:
|
53084cc to
90709a5
Compare
aapoalas
approved these changes
May 21, 2026
| // assignment. This is a contradiction. | ||
| unreachable!("Reborrow trait usage during adjustment walk"); | ||
| adjustment::Adjust::GenericReborrow(mutability) => { | ||
| let bk = ty::BorrowKind::from_mutbl(mutability); |
Contributor
There was a problem hiding this comment.
thought: I don't have in-depth understanding about what this exactly doing and if that matches my understanding but... probably it does :) Definitely it's better than an ICE.
The interesting corner-case would probably be something like this:
fn id_with_closure<'a>(x: CustomMut<'a>) -> CustomMut<'a> {
let cb = || x;
cb()
}Right now due to a mistake/complication in the implementation this wouldn't even work with just returning x, but once that's fixed then the closure version should also work.
Contributor
|
Does this fix #156339 ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes an ICE in expression-use adjustment walking where
Adjust::GenericReborrowcould reach a match arm that assumed generic reborrow was unreachable.GenericReborrowis already emitted by typeck and classified as rvalue-producing elsewhere inexpr_use_visitor.rs, so the adjustment walker must handle it explicitly instead of panicking.This PR models
GenericReborrowas a borrow-like use of the source expression:Mutability::Mutis treated like an exclusive/mutable reborrow use.Mutability::Notis treated like a shared/coerce-shared borrow-like use.cc @aapoalas