Skip to content
Merged
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
7 changes: 7 additions & 0 deletions crates/hir-ty/src/next_solver/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,13 @@ pub(crate) fn convert_ty_for_result<'db>(interner: DbInterner<'db>, ty: Ty<'db>)
}),
);

// Rust and chalk have slightly different
// representation for trait objects.
//
// Chalk uses `for<T0> for<'a> T0: Trait<'a>` while rustc
// uses `ExistentialPredicate`s, which do not have a self ty.
// We need to shift escaping bound vars by 1 to accommodate
// the newly introduced `for<T0>` binder.
let p = shift_vars(interner, p, 1);

let where_clause = match p.skip_binder() {
Expand Down
32 changes: 32 additions & 0 deletions crates/hir-ty/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4994,3 +4994,35 @@ fn main() {
"#]],
);
}

#[test]
fn trait_object_binders() {
check_infer(
r#"
//- minicore: iterator, dispatch_from_dyn
fn main() {
struct Box<T: ?Sized>(*const T);
impl<I: Iterator + ?Sized> Iterator for Box<I> {
type Item = I::Item;
fn next(&mut self) -> Option<I::Item> {
loop {}
}
}
let iter: Box<dyn Iterator<Item = &[u8]> + 'static> = loop {};
let _ = iter.into_iter();
}"#,
expect![[r#"
10..313 '{ ...r(); }': ()
223..227 'iter': Box<dyn Iterator<Item = &'? [u8]> + 'static>
273..280 'loop {}': !
278..280 '{}': ()
290..291 '_': Box<dyn Iterator<Item = &'? [u8]> + 'static>
294..298 'iter': Box<dyn Iterator<Item = &'? [u8]> + 'static>
294..310 'iter.i...iter()': Box<dyn Iterator<Item = &'? [u8]> + 'static>
152..156 'self': &'? mut Box<I>
177..208 '{ ... }': Option<Iterator::Item<I>>
191..198 'loop {}': !
196..198 '{}': ()
"#]],
);
}
Loading