diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/snapshots/tests__recursive_vars.snap | 14 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/snapshots/tests__recursive_vars_2.snap | 21 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 32 |
3 files changed, 67 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/snapshots/tests__recursive_vars.snap b/crates/ra_hir/src/ty/snapshots/tests__recursive_vars.snap new file mode 100644 index 000000000..c3227ff7e --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__recursive_vars.snap | |||
@@ -0,0 +1,14 @@ | |||
1 | --- | ||
2 | created: "2019-01-26T22:42:22.329980185+00:00" | ||
3 | creator: [email protected] | ||
4 | expression: "&result" | ||
5 | source: crates/ra_hir/src/ty/tests.rs | ||
6 | --- | ||
7 | [11; 48) '{ ...&y]; }': () | ||
8 | [21; 22) 'y': &[unknown] | ||
9 | [25; 32) 'unknown': &[unknown] | ||
10 | [38; 45) '[y, &y]': [&&[unknown]] | ||
11 | [39; 40) 'y': &[unknown] | ||
12 | [42; 44) '&y': &&[unknown] | ||
13 | [43; 44) 'y': &[unknown] | ||
14 | |||
diff --git a/crates/ra_hir/src/ty/snapshots/tests__recursive_vars_2.snap b/crates/ra_hir/src/ty/snapshots/tests__recursive_vars_2.snap new file mode 100644 index 000000000..de124da5b --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__recursive_vars_2.snap | |||
@@ -0,0 +1,21 @@ | |||
1 | --- | ||
2 | created: "2019-01-26T22:42:22.331805845+00:00" | ||
3 | creator: [email protected] | ||
4 | expression: "&result" | ||
5 | source: crates/ra_hir/src/ty/tests.rs | ||
6 | --- | ||
7 | [11; 80) '{ ...x)]; }': () | ||
8 | [21; 22) 'x': &&[unknown] | ||
9 | [25; 32) 'unknown': &&[unknown] | ||
10 | [42; 43) 'y': &&[unknown] | ||
11 | [46; 53) 'unknown': &&[unknown] | ||
12 | [59; 77) '[(x, y..., &x)]': [(&&[unknown], &&[unknown])] | ||
13 | [60; 66) '(x, y)': (&&[unknown], &&[unknown]) | ||
14 | [61; 62) 'x': &&[unknown] | ||
15 | [64; 65) 'y': &&[unknown] | ||
16 | [68; 76) '(&y, &x)': (&&&[unknown], &&&[unknown]) | ||
17 | [69; 71) '&y': &&&[unknown] | ||
18 | [70; 71) 'y': &&[unknown] | ||
19 | [73; 75) '&x': &&&[unknown] | ||
20 | [74; 75) 'x': &&[unknown] | ||
21 | |||
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index e1165f682..f74d6f5ea 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -3,6 +3,7 @@ use std::fmt::Write; | |||
3 | 3 | ||
4 | use ra_db::{SourceDatabase, salsa::Database}; | 4 | use ra_db::{SourceDatabase, salsa::Database}; |
5 | use ra_syntax::ast::{self, AstNode}; | 5 | use ra_syntax::ast::{self, AstNode}; |
6 | use test_utils::covers; | ||
6 | 7 | ||
7 | use crate::{ | 8 | use crate::{ |
8 | source_binder, | 9 | source_binder, |
@@ -562,6 +563,37 @@ fn quux() { | |||
562 | ); | 563 | ); |
563 | } | 564 | } |
564 | 565 | ||
566 | #[test] | ||
567 | fn recursive_vars() { | ||
568 | covers!(type_var_cycles_resolve_completely); | ||
569 | covers!(type_var_cycles_resolve_as_possible); | ||
570 | check_inference( | ||
571 | "recursive_vars", | ||
572 | r#" | ||
573 | fn test() { | ||
574 | let y = unknown; | ||
575 | [y, &y]; | ||
576 | } | ||
577 | "#, | ||
578 | ); | ||
579 | } | ||
580 | |||
581 | #[test] | ||
582 | fn recursive_vars_2() { | ||
583 | covers!(type_var_cycles_resolve_completely); | ||
584 | covers!(type_var_cycles_resolve_as_possible); | ||
585 | check_inference( | ||
586 | "recursive_vars_2", | ||
587 | r#" | ||
588 | fn test() { | ||
589 | let x = unknown; | ||
590 | let y = unknown; | ||
591 | [(x, y), (&y, &x)]; | ||
592 | } | ||
593 | "#, | ||
594 | ); | ||
595 | } | ||
596 | |||
565 | fn infer(content: &str) -> String { | 597 | fn infer(content: &str) -> String { |
566 | let (db, _, file_id) = MockDatabase::with_single_file(content); | 598 | let (db, _, file_id) = MockDatabase::with_single_file(content); |
567 | let source_file = db.parse(file_id); | 599 | let source_file = db.parse(file_id); |