aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index fc4054159..c590a09db 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -418,6 +418,69 @@ fn test() {
418 ); 418 );
419} 419}
420 420
421#[test]
422fn infer_struct_generics() {
423 check_inference(
424 r#"
425struct A<T> {
426 x: T,
427}
428
429fn test(a1: A<u32>, i: i32) {
430 a1.x;
431 let a2 = A { x: i };
432 a2.x;
433 let a3 = A::<i128> { x: 1 };
434 a3.x;
435}
436"#,
437 "struct_generics.txt",
438 );
439}
440
441#[test]
442fn infer_function_generics() {
443 check_inference(
444 r#"
445fn id<T>(t: T) -> T { t }
446
447fn test() {
448 id(1u32);
449 id::<i128>(1);
450 let x: u64 = id(1);
451}
452"#,
453 "function_generics.txt",
454 );
455}
456
457#[test]
458fn infer_generic_chain() {
459 check_inference(
460 r#"
461struct A<T> {
462 x: T,
463}
464impl<T2> A<T2> {
465 fn x(self) -> T2 {
466 self.x
467 }
468}
469fn id<T>(t: T) -> T { t }
470
471fn test() -> i128 {
472 let x = 1;
473 let y = id(x);
474 let a = A { x: id(y) };
475 let z = id(a.x);
476 let b = A { x: z };
477 b.x()
478}
479"#,
480 "generic_chain.txt",
481 );
482}
483
421fn infer(content: &str) -> String { 484fn infer(content: &str) -> String {
422 let (db, _, file_id) = MockDatabase::with_single_file(content); 485 let (db, _, file_id) = MockDatabase::with_single_file(content);
423 let source_file = db.source_file(file_id); 486 let source_file = db.source_file(file_id);