Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions crates/hir-ty/src/next_solver/infer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,28 @@ impl<'db> rustc_type_ir::InferCtxtLike for InferCtxt<'db> {

fn opaques_with_sub_unified_hidden_type(
&self,
_ty: TyVid,
ty: TyVid,
) -> Vec<rustc_type_ir::AliasTy<Self::Interner>> {
// FIXME: I guess we are okay without this for now since currently r-a lacks of
// detailed checks over opaque types. Might need to implement this in future.
vec![]
let ty_sub_vid = self.sub_unification_table_root_var(ty);
let inner = &mut *self.inner.borrow_mut();
let mut type_variables = inner.type_variable_storage.with_log(&mut inner.undo_log);
inner
.opaque_type_storage
.iter_opaque_types()
.filter_map(|(key, hidden_ty)| {
let TyKind::Infer(InferTy::TyVar(hidden_vid)) = hidden_ty.ty.kind() else {
return None;
};
(type_variables.sub_unification_table_root_var(hidden_vid) == ty_sub_vid).then(
|| {
rustc_type_ir::AliasTy::new_from_args(
self.interner,
rustc_type_ir::Opaque { def_id: key.def_id },
key.args,
)
},
)
})
.collect()
}
}
34 changes: 34 additions & 0 deletions crates/hir-ty/src/tests/regression/new_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,40 @@ where
);
}

#[test]
fn opaque_iterator_uses_blanket_into_iterator_impl() {
check_types(
r#"
//- minicore: iterator
struct Item;
impl Item {
fn method(&self) -> usize {
0
}
}

struct Iter;
impl Iterator for Iter {
type Item = Item;

fn next(&mut self) -> Option<Self::Item> {
None
}
}

fn iterator(recurse: bool) -> impl Iterator<Item = Item> {
if recurse {
for item in iterator(false) {
item.method();
//^^^^^^^^^^^^^ usize
}
}
Iter
}
"#,
);
}

#[test]
fn regression_16282() {
check_infer(
Expand Down