aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-05-22 17:52:07 +0100
committerFlorian Diebold <[email protected]>2020-05-22 17:52:07 +0100
commite0f978018aad1a48390189ce54372913f324b2e3 (patch)
treee863dedc211f63c3bdbf0614a2907558e56e63d1 /crates
parent02c2beaa8c54201863ab4713f6f42cd98ae3951c (diff)
Add some tests for Chalk built-in trait impls
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs
index 34f4b9039..6826610cb 100644
--- a/crates/ra_hir_ty/src/tests/traits.rs
+++ b/crates/ra_hir_ty/src/tests/traits.rs
@@ -2602,3 +2602,81 @@ fn test(x: &dyn Foo) {
2602 "### 2602 "###
2603 ); 2603 );
2604} 2604}
2605
2606#[test]
2607fn builtin_copy() {
2608 assert_snapshot!(
2609 infer_with_mismatches(r#"
2610#[lang = "copy"]
2611trait Copy {}
2612
2613struct IsCopy;
2614impl Copy for IsCopy {}
2615struct NotCopy;
2616
2617trait Test { fn test(&self) -> bool; }
2618impl<T: Copy> Test for T {}
2619
2620fn test() {
2621 IsCopy.test();
2622 NotCopy.test();
2623 (IsCopy, IsCopy).test();
2624 (IsCopy, NotCopy).test();
2625}
2626"#, true),
2627 @r###"
2628 111..115 'self': &Self
2629 167..268 '{ ...t(); }': ()
2630 173..179 'IsCopy': IsCopy
2631 173..186 'IsCopy.test()': bool
2632 192..199 'NotCopy': NotCopy
2633 192..206 'NotCopy.test()': {unknown}
2634 212..228 '(IsCop...sCopy)': (IsCopy, IsCopy)
2635 212..235 '(IsCop...test()': bool
2636 213..219 'IsCopy': IsCopy
2637 221..227 'IsCopy': IsCopy
2638 241..258 '(IsCop...tCopy)': (IsCopy, NotCopy)
2639 241..265 '(IsCop...test()': {unknown}
2640 242..248 'IsCopy': IsCopy
2641 250..257 'NotCopy': NotCopy
2642 "###
2643 );
2644}
2645
2646#[test]
2647fn builtin_sized() {
2648 assert_snapshot!(
2649 infer_with_mismatches(r#"
2650#[lang = "sized"]
2651trait Sized {}
2652
2653trait Test { fn test(&self) -> bool; }
2654impl<T: Sized> Test for T {}
2655
2656fn test() {
2657 1u8.test();
2658 (*"foo").test(); // not Sized
2659 (1u8, 1u8).test();
2660 (1u8, *"foo").test(); // not Sized
2661}
2662"#, true),
2663 @r###"
2664 57..61 'self': &Self
2665 114..229 '{ ...ized }': ()
2666 120..123 '1u8': u8
2667 120..130 '1u8.test()': bool
2668 136..151 '(*"foo").test()': {unknown}
2669 137..143 '*"foo"': str
2670 138..143 '"foo"': &str
2671 170..180 '(1u8, 1u8)': (u8, u8)
2672 170..187 '(1u8, ...test()': bool
2673 171..174 '1u8': u8
2674 176..179 '1u8': u8
2675 193..206 '(1u8, *"foo")': (u8, str)
2676 193..213 '(1u8, ...test()': {unknown}
2677 194..197 '1u8': u8
2678 199..205 '*"foo"': str
2679 200..205 '"foo"': &str
2680 "###
2681 );
2682}