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

suggest_borrow_generic_arg: instantiate clauses properly #133130

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

dianne
Copy link
Contributor

@dianne dianne commented Nov 17, 2024

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
Copy link
Collaborator

rustbot commented Nov 17, 2024

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
Copy link
Member

@compiler-errors compiler-errors left a comment

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.

Copy link
Member

@compiler-errors compiler-errors left a comment

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
Copy link
Member

compiler-errors commented Nov 17, 2024

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
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
Copy link
Member

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

@dianne dianne changed the title suggest_borrow_generic_arg: erase region variables from moved_arg_ty sooner suggest_borrow_generic_arg: instantiate clauses properly Nov 18, 2024
@dianne
Copy link
Contributor Author

dianne commented Nov 18, 2024

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
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 18, 2024

📌 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
Rollup of 7 pull requests

Successful merges:

 - rust-lang#132795 (Check `use<..>` in RPITIT for refinement)
 - rust-lang#132944 (add parentheses when unboxing suggestion needed)
 - rust-lang#132993 (Make rustc consider itself a stable compiler when `RUSTC_BOOTSTRAP=-1`)
 - rust-lang#133130 (`suggest_borrow_generic_arg`: instantiate clauses properly)
 - rust-lang#133133 (rustdoc-search: add standalone trailing `::` test)
 - rust-lang#133143 (Diagnostics for let mut in item context)
 - rust-lang#133147 (Fixup some test directives)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit fc4f71d into rust-lang:master Nov 18, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 18, 2024
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.
@dianne dianne deleted the fix-133118 branch November 18, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: unexpected region
5 participants