-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fix: Wrong closure kind deduction for closures with predicates #16630
Conversation
crates/hir-ty/src/infer/closure.rs
Outdated
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!(), | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
let obligations = pending_obligations | ||
.iter() | ||
.filter_map(|obligation| match obligation.value.value.goal.data(Interner) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could make use of https://doc.rust-lang.org/std/vec/struct.Vec.html#method.retain I think?
There was a problem hiding this comment.
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
☔ The latest upstream changes (presumably #16669) made this pull request unmergeable. Please resolve the merge conflicts. |
6983e8f
to
46cdce1
Compare
Thanks! |
☀️ Test successful - checks-actions |
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