Skip to content

Commit a6b199c

Browse files
authored
Merge pull request #20462 from jackh726/nts-part3
Add test for webrender-2022 dyn issue
2 parents 03a6465 + 651ec4b commit a6b199c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

crates/hir-ty/src/next_solver/mapping.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,13 @@ pub(crate) fn convert_ty_for_result<'db>(interner: DbInterner<'db>, ty: Ty<'db>)
11481148
}),
11491149
);
11501150

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

11531160
let where_clause = match p.skip_binder() {

crates/hir-ty/src/tests/traits.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4994,3 +4994,35 @@ fn main() {
49944994
"#]],
49954995
);
49964996
}
4997+
4998+
#[test]
4999+
fn trait_object_binders() {
5000+
check_infer(
5001+
r#"
5002+
//- minicore: iterator, dispatch_from_dyn
5003+
fn main() {
5004+
struct Box<T: ?Sized>(*const T);
5005+
impl<I: Iterator + ?Sized> Iterator for Box<I> {
5006+
type Item = I::Item;
5007+
fn next(&mut self) -> Option<I::Item> {
5008+
loop {}
5009+
}
5010+
}
5011+
let iter: Box<dyn Iterator<Item = &[u8]> + 'static> = loop {};
5012+
let _ = iter.into_iter();
5013+
}"#,
5014+
expect![[r#"
5015+
10..313 '{ ...r(); }': ()
5016+
223..227 'iter': Box<dyn Iterator<Item = &'? [u8]> + 'static>
5017+
273..280 'loop {}': !
5018+
278..280 '{}': ()
5019+
290..291 '_': Box<dyn Iterator<Item = &'? [u8]> + 'static>
5020+
294..298 'iter': Box<dyn Iterator<Item = &'? [u8]> + 'static>
5021+
294..310 'iter.i...iter()': Box<dyn Iterator<Item = &'? [u8]> + 'static>
5022+
152..156 'self': &'? mut Box<I>
5023+
177..208 '{ ... }': Option<Iterator::Item<I>>
5024+
191..198 'loop {}': !
5025+
196..198 '{}': ()
5026+
"#]],
5027+
);
5028+
}

0 commit comments

Comments
 (0)