Skip to content

Commit e0f9780

Browse files
committed
Add some tests for Chalk built-in trait impls
1 parent 02c2bea commit e0f9780

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

crates/ra_hir_ty/src/tests/traits.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,3 +2602,81 @@ fn test(x: &dyn Foo) {
26022602
"###
26032603
);
26042604
}
2605+
2606+
#[test]
2607+
fn builtin_copy() {
2608+
assert_snapshot!(
2609+
infer_with_mismatches(r#"
2610+
#[lang = "copy"]
2611+
trait Copy {}
2612+
2613+
struct IsCopy;
2614+
impl Copy for IsCopy {}
2615+
struct NotCopy;
2616+
2617+
trait Test { fn test(&self) -> bool; }
2618+
impl<T: Copy> Test for T {}
2619+
2620+
fn 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]
2647+
fn builtin_sized() {
2648+
assert_snapshot!(
2649+
infer_with_mismatches(r#"
2650+
#[lang = "sized"]
2651+
trait Sized {}
2652+
2653+
trait Test { fn test(&self) -> bool; }
2654+
impl<T: Sized> Test for T {}
2655+
2656+
fn 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+
}

0 commit comments

Comments
 (0)