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

fix: Wrong closure kind deduction for closures with predicates #16630

Merged
merged 4 commits into from Feb 27, 2024

Conversation

ShoyuVanilla
Copy link
Contributor

Completes #16472, fixes #16421

The changed closure kind deduction is mostly simlar to rustc_hir_typeck/src/closure.rs.
Porting closure sig deduction from it seems possible too and I'm considering doing it with another PR

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 21, 2024
Comment on lines 179 to 189
fn fn_trait_kind_from_trait_id(&self, trait_id: hir_def::TraitId) -> Option<FnTrait> {
utils::fn_traits(self.db.upcast(), self.owner.module(self.db.upcast()).krate())
.enumerate()
.find_map(|(i, t)| (t == trait_id).then_some(i))
.map(|i| match i {
0 => FnTrait::Fn,
1 => FnTrait::FnMut,
2 => FnTrait::FnOnce,
_ => unreachable!(),
})
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn fn_trait_kind_from_trait_id(&self, trait_id: hir_def::TraitId) -> Option<FnTrait> {
utils::fn_traits(self.db.upcast(), self.owner.module(self.db.upcast()).krate())
.enumerate()
.find_map(|(i, t)| (t == trait_id).then_some(i))
.map(|i| match i {
0 => FnTrait::Fn,
1 => FnTrait::FnMut,
2 => FnTrait::FnOnce,
_ => unreachable!(),
})
}
fn fn_trait_kind_from_trait_id(&self, trait_id: hir_def::TraitId) -> Option<FnTrait> {
FnTrait::from_lang_item(self.db.lang_attr(trait_id.into())?)
}

Something like this should be a bit more performant (less db lookups)

Comment on lines +44 to +46
let obligations = pending_obligations
.iter()
.filter_map(|obligation| match obligation.value.value.goal.data(Interner) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are not mutating pending_obligations - it should be returned back to its original place self.table.pending_obligations - I think that to use Vec::retain(), we should clone the whole pending_obligations

@Veykril Veykril 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 Feb 26, 2024
@bors
Copy link
Collaborator

bors commented Feb 26, 2024

☔ The latest upstream changes (presumably #16669) made this pull request unmergeable. Please resolve the merge conflicts.

@Veykril
Copy link
Member

Veykril commented Feb 27, 2024

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Feb 27, 2024

📌 Commit a4021f6 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Feb 27, 2024

⌛ Testing commit a4021f6 with merge a3236be...

@bors
Copy link
Collaborator

bors commented Feb 27, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing a3236be to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive "cannot mutate immutable variable (E0384)" error
4 participants