aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-22 18:31:39 +0100
committerGitHub <[email protected]>2020-05-22 18:31:39 +0100
commitb38f9a5810f28563c45acb1ae8b82438649227c9 (patch)
treeea6b68dcbd47a92a5615c74723ae69dafd7d47f9 /crates/ra_hir_ty/src/tests
parentc5a22715809fa79b2c77d461c2161dbf5ebb411a (diff)
parente0f978018aad1a48390189ce54372913f324b2e3 (diff)
Merge #4570
4570: Use Chalk's built-in impls r=matklad a=flodiebold This contains two changes: - Chalk has begun adding built-in representations of primitive types; use these in our type conversion logic. There's one somewhat 'iffy' part here, namely references; we don't keep track of lifetimes, but Chalk does, so it will expect a lifetime parameter on references. If we didn't provide that, it could cause crashes in Chalk code that expects the lifetime, so I rather hackily add an (always the same) lifetime placeholder during conversion. I expect that we'll fully switch to using Chalk's types everywhere before we add lifetime support, so I think this is the best solution for now. - let Chalk know about well-known traits (from lang items), so it can apply its built-in impls. Before: ``` Total expressions: 181485 Expressions of unknown type: 2940 (1%) Expressions of partially unknown type: 2884 (1%) Type mismatches: 901 Inference: 37.821210245s, 0b allocated 0b resident Total: 53.399467609s, 0b allocated 0b resident ``` After: ``` Total expressions: 181485 Expressions of unknown type: 2923 (1%) Expressions of partially unknown type: 2879 (1%) Type mismatches: 734 Inference: 39.157752509s, 0b allocated 0b resident Total: 54.110767621s, 0b allocated 0b resident ``` (I will start splitting up `chalk.rs` in a separate PR, since it's getting pretty big...) Co-authored-by: Florian Diebold <[email protected]> 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/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}