suggest_borrow_generic_arg: instantiate clauses properly by dianne · Pull Request #133130 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation8 Commits1 Checks6 Files changed

Conversation

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

[ Show hidden characters]({{ revealButtonHref }})

dianne

This simplifies and fixes the way suggest_borrow_generic_arg instantiates callees' predicates when testing them to see if a moved argument can instead be borrowed. Previously, it would ICE if the moved argument's type included a region variable, since it was getting passed to a call of EarlyBinder::instantiate. This makes the instantiation much more straightforward, which also fixes the ICE.

Fixes #133118

This also modifies tests/ui/moves/moved-value-on-as-ref-arg.rs to have more useful bounds on the tests for suggestions to borrow Borrow and BorrowMut arguments. With its old tautological T: BorrowMut<T> bound, this fix would make it suggest a shared borrow for that argument.

@rustbot

r? @estebank

rustbot has assigned @estebank.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

labels

Nov 17, 2024

compiler-errors

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain that this is the right fix. If we're instantiating/substituting the wrong set of region variables into a type, then this is bound to happen with a generic type or const as well, right? Those cannot be erased.

I'd at least like to see an explanation for why this issue was happening before this fix; this feels like it's just masking the underlying issue which is that this code is handling generics kinda strangely in general.

compiler-errors

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real bug is that in clause_for_ref, you're substituting it once with the self type (ref_ty), then you're substituting it again in the call to predicate_must_hold_modulo_regions.

I don't think this really makes sense -- substituting it once should be sufficient, since you've already set up the generic args to have the right self type (new_args).

@compiler-errors

I hope that's enough info to guide you towards the right solution :) -- @rustbot author

@rustbot rustbot added S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Nov 17, 2024

@dianne

Fixes issue 133118. This also modifies tests/ui/moves/moved-value-on-as-ref-arg.rs to have more useful bounds on the tests for suggestions to borrow Borrow and BorrowMut arguments. With its old tautological T: BorrowMut<T> bound, this fix would make it suggest a shared borrow for that argument.

@compiler-errors

This approach looks correct. Please update the description and title, then I can approve

@dianne dianne changed the titlesuggest_borrow_generic_arg: erase region variables from moved_arg_ty sooner suggest_borrow_generic_arg: instantiate clauses properly

Nov 18, 2024

@dianne

Done. Thank you! That helped. I think it reads much nicer now too.
@rustbot ready

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

and removed S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

labels

Nov 18, 2024

@compiler-errors

@bors

📌 Commit 546ba3d has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Nov 18, 2024

bors added a commit to rust-lang-ci/rust that referenced this pull request

Nov 18, 2024

@bors

Rollup of 7 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Nov 18, 2024

@rust-timer

Rollup merge of rust-lang#133130 - dianne:fix-133118, r=compiler-errors

suggest_borrow_generic_arg: instantiate clauses properly

This simplifies and fixes the way suggest_borrow_generic_arg instantiates callees' predicates when testing them to see if a moved argument can instead be borrowed. Previously, it would ICE if the moved argument's type included a region variable, since it was getting passed to a call of EarlyBinder::instantiate. This makes the instantiation much more straightforward, which also fixes the ICE.

Fixes rust-lang#133118

This also modifies tests/ui/moves/moved-value-on-as-ref-arg.rs to have more useful bounds on the tests for suggestions to borrow Borrow and BorrowMut arguments. With its old tautological T: BorrowMut<T> bound, this fix would make it suggest a shared borrow for that argument.

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.