aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-08-23 13:29:30 +0100
committerFlorian Diebold <[email protected]>2019-09-03 12:25:29 +0100
commit966ab9abd2253e68d2e410a58dc1328805ee7f61 (patch)
tree8d48793e69f3cb5f7f398c5579d383c666f1207f
parent1c0672b7f802c7e7814ba9a1b3b21ecf866343d6 (diff)
Add test for assoc type bindings
-rw-r--r--crates/ra_hir/src/ty/tests.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index cde9801f6..42bcae157 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -3552,6 +3552,71 @@ fn test() {
3552 ); 3552 );
3553} 3553}
3554 3554
3555#[test]
3556fn assoc_type_bindings() {
3557 assert_snapshot!(
3558 infer(r#"
3559trait Trait {
3560 type Type;
3561}
3562
3563fn get<T: Trait>(t: T) -> <T as Trait>::Type {}
3564fn get2<U, T: Trait<Type = U>>(t: T) -> U {}
3565fn set<T: Trait<Type = u64>>(t: T) -> T {t}
3566
3567struct S<T>;
3568impl<T> Trait for S<T> { type Type = T; }
3569
3570fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
3571 get(x);
3572 get2(x);
3573 get(y);
3574 get2(y);
3575 get(set(S));
3576 get2(set(S));
3577 get2(S::<str>);
3578}
3579"#),
3580 @r###"
3581 [50; 51) 't': T
3582 [78; 80) '{}': ()
3583 [112; 113) 't': T
3584 [123; 125) '{}': ()
3585 [155; 156) 't': T
3586 [166; 169) '{t}': T
3587 [167; 168) 't': T
3588 [257; 258) 'x': T
3589 [263; 264) 'y': impl Trait
3590 [290; 398) '{ ...r>); }': ()
3591 [296; 299) 'get': fn get<T>(T) -> <T as Trait>::Type
3592 [296; 302) 'get(x)': {unknown}
3593 [300; 301) 'x': T
3594 [308; 312) 'get2': fn get2<{unknown}, T>(T) -> U
3595 [308; 315) 'get2(x)': {unknown}
3596 [313; 314) 'x': T
3597 [321; 324) 'get': fn get<impl Trait>(T) -> <T as Trait>::Type
3598 [321; 327) 'get(y)': {unknown}
3599 [325; 326) 'y': impl Trait
3600 [333; 337) 'get2': fn get2<{unknown}, impl Trait>(T) -> U
3601 [333; 340) 'get2(y)': {unknown}
3602 [338; 339) 'y': impl Trait
3603 [346; 349) 'get': fn get<S<{unknown}>>(T) -> <T as Trait>::Type
3604 [346; 357) 'get(set(S))': {unknown}
3605 [350; 353) 'set': fn set<S<{unknown}>>(T) -> T
3606 [350; 356) 'set(S)': S<{unknown}>
3607 [354; 355) 'S': S<{unknown}>
3608 [363; 367) 'get2': fn get2<{unknown}, S<{unknown}>>(T) -> U
3609 [363; 375) 'get2(set(S))': {unknown}
3610 [368; 371) 'set': fn set<S<{unknown}>>(T) -> T
3611 [368; 374) 'set(S)': S<{unknown}>
3612 [372; 373) 'S': S<{unknown}>
3613 [381; 385) 'get2': fn get2<{unknown}, S<str>>(T) -> U
3614 [381; 395) 'get2(S::<str>)': {unknown}
3615 [386; 394) 'S::<str>': S<str>
3616 "###
3617 );
3618}
3619
3555fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 3620fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
3556 let file = db.parse(pos.file_id).ok().unwrap(); 3621 let file = db.parse(pos.file_id).ok().unwrap();
3557 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); 3622 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();