diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-15 21:25:42 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-15 21:25:42 +0100 |
commit | cffa70be01d4353184f874fc4768b692e255dd30 (patch) | |
tree | 481c93f91eec65f98a82fa28a123140d5a227eea /crates/ra_hir_ty/src/tests | |
parent | d51c1f62178c383363a2d95e865131d9a7b969d0 (diff) | |
parent | 3f42b2e837c4672a0fbe953e14ae2fd3fe6fc3b6 (diff) |
Merge #4470
4470: Handle `Self` in values and patterns r=matklad a=flodiebold
I.e.
- `Self(x)` or `Self` in tuple/unit struct impls
- `Self::Variant(x)` or `Self::Variant` in enum impls
- the same in patterns
Fixes #4454.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/patterns.rs | 39 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/simple.rs | 44 |
2 files changed, 83 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index af291092d..d83ff5e0e 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs | |||
@@ -369,6 +369,45 @@ fn test() { | |||
369 | } | 369 | } |
370 | 370 | ||
371 | #[test] | 371 | #[test] |
372 | fn enum_variant_through_self_in_pattern() { | ||
373 | assert_snapshot!( | ||
374 | infer(r#" | ||
375 | enum E { | ||
376 | A { x: usize }, | ||
377 | B(usize), | ||
378 | C | ||
379 | } | ||
380 | |||
381 | impl E { | ||
382 | fn test() { | ||
383 | match (loop {}) { | ||
384 | Self::A { x } => { x; }, | ||
385 | Self::B(x) => { x; }, | ||
386 | Self::C => {}, | ||
387 | }; | ||
388 | } | ||
389 | } | ||
390 | "#), | ||
391 | @r###" | ||
392 | 76..218 '{ ... }': () | ||
393 | 86..211 'match ... }': () | ||
394 | 93..100 'loop {}': ! | ||
395 | 98..100 '{}': () | ||
396 | 116..129 'Self::A { x }': E | ||
397 | 126..127 'x': usize | ||
398 | 133..139 '{ x; }': () | ||
399 | 135..136 'x': usize | ||
400 | 153..163 'Self::B(x)': E | ||
401 | 161..162 'x': usize | ||
402 | 167..173 '{ x; }': () | ||
403 | 169..170 'x': usize | ||
404 | 187..194 'Self::C': E | ||
405 | 198..200 '{}': () | ||
406 | "### | ||
407 | ); | ||
408 | } | ||
409 | |||
410 | #[test] | ||
372 | fn infer_generics_in_patterns() { | 411 | fn infer_generics_in_patterns() { |
373 | assert_snapshot!( | 412 | assert_snapshot!( |
374 | infer(r#" | 413 | infer(r#" |
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 322838f02..72122c070 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs | |||
@@ -576,6 +576,50 @@ impl S { | |||
576 | } | 576 | } |
577 | 577 | ||
578 | #[test] | 578 | #[test] |
579 | fn infer_self_as_path() { | ||
580 | assert_snapshot!( | ||
581 | infer(r#" | ||
582 | struct S1; | ||
583 | struct S2(isize); | ||
584 | enum E { | ||
585 | V1, | ||
586 | V2(u32), | ||
587 | } | ||
588 | |||
589 | impl S1 { | ||
590 | fn test() { | ||
591 | Self; | ||
592 | } | ||
593 | } | ||
594 | impl S2 { | ||
595 | fn test() { | ||
596 | Self(1); | ||
597 | } | ||
598 | } | ||
599 | impl E { | ||
600 | fn test() { | ||
601 | Self::V1; | ||
602 | Self::V2(1); | ||
603 | } | ||
604 | } | ||
605 | "#), | ||
606 | @r###" | ||
607 | 87..108 '{ ... }': () | ||
608 | 97..101 'Self': S1 | ||
609 | 135..159 '{ ... }': () | ||
610 | 145..149 'Self': S2(isize) -> S2 | ||
611 | 145..152 'Self(1)': S2 | ||
612 | 150..151 '1': isize | ||
613 | 185..231 '{ ... }': () | ||
614 | 195..203 'Self::V1': E | ||
615 | 213..221 'Self::V2': V2(u32) -> E | ||
616 | 213..224 'Self::V2(1)': E | ||
617 | 222..223 '1': u32 | ||
618 | "### | ||
619 | ); | ||
620 | } | ||
621 | |||
622 | #[test] | ||
579 | fn infer_binary_op() { | 623 | fn infer_binary_op() { |
580 | assert_snapshot!( | 624 | assert_snapshot!( |
581 | infer(r#" | 625 | infer(r#" |