Merge pull request #19050 from ChayimFriedman2/iter-self

fix: Don't suggest `into_iter().method()` on iterators
This commit is contained in:
Lukas Wirth 2025-01-27 17:41:02 +00:00 committed by GitHub
commit b27c5b4cae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 1 deletions

View file

@ -4961,6 +4961,17 @@ impl Type {
self.normalize_trait_assoc_type(db, &[], iterator_item.into())
}
pub fn impls_iterator(self, db: &dyn HirDatabase) -> bool {
let Some(iterator_trait) =
db.lang_item(self.env.krate, LangItem::Iterator).and_then(|it| it.as_trait())
else {
return false;
};
let canonical_ty =
Canonical { value: self.ty.clone(), binders: CanonicalVarKinds::empty(Interner) };
method_resolution::implements_trait_unique(&canonical_ty, db, &self.env, iterator_trait)
}
/// Resolves the projection `<Self as IntoIterator>::IntoIter` and returns the resulting type
pub fn into_iterator_iter(self, db: &dyn HirDatabase) -> Option<Type> {
let trait_ = db.lang_item(self.env.krate, LangItem::IntoIterIntoIter).and_then(|it| {