aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r--crates/ra_hir_ty/src/tests/coercion.rs36
-rw-r--r--crates/ra_hir_ty/src/tests/macros.rs51
2 files changed, 87 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs
index 1530fcc63..58b22396f 100644
--- a/crates/ra_hir_ty/src/tests/coercion.rs
+++ b/crates/ra_hir_ty/src/tests/coercion.rs
@@ -1,3 +1,4 @@
1use super::infer_with_mismatches;
1use insta::assert_snapshot; 2use insta::assert_snapshot;
2use test_utils::covers; 3use test_utils::covers;
3 4
@@ -367,3 +368,38 @@ fn test() {
367 "### 368 "###
368 ); 369 );
369} 370}
371
372#[test]
373fn coerce_autoderef() {
374 assert_snapshot!(
375 infer_with_mismatches(r#"
376struct Foo;
377fn takes_ref_foo(x: &Foo) {}
378fn test() {
379 takes_ref_foo(&Foo);
380 takes_ref_foo(&&Foo);
381 takes_ref_foo(&&&Foo);
382}
383"#, true),
384 @r###"
385 [30; 31) 'x': &Foo
386 [39; 41) '{}': ()
387 [52; 133) '{ ...oo); }': ()
388 [58; 71) 'takes_ref_foo': fn takes_ref_foo(&Foo) -> ()
389 [58; 77) 'takes_...(&Foo)': ()
390 [72; 76) '&Foo': &Foo
391 [73; 76) 'Foo': Foo
392 [83; 96) 'takes_ref_foo': fn takes_ref_foo(&Foo) -> ()
393 [83; 103) 'takes_...&&Foo)': ()
394 [97; 102) '&&Foo': &&Foo
395 [98; 102) '&Foo': &Foo
396 [99; 102) 'Foo': Foo
397 [109; 122) 'takes_ref_foo': fn takes_ref_foo(&Foo) -> ()
398 [109; 130) 'takes_...&&Foo)': ()
399 [123; 129) '&&&Foo': &&&Foo
400 [124; 129) '&&Foo': &&Foo
401 [125; 129) '&Foo': &Foo
402 [126; 129) 'Foo': Foo
403 "###
404 );
405}
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs
index 0d9a35ce0..9c29a054e 100644
--- a/crates/ra_hir_ty/src/tests/macros.rs
+++ b/crates/ra_hir_ty/src/tests/macros.rs
@@ -266,3 +266,54 @@ fn main() {
266 "### 266 "###
267 ); 267 );
268} 268}
269
270#[test]
271fn infer_derive_clone_simple() {
272 let (db, pos) = TestDB::with_position(
273 r#"
274//- /main.rs crate:main deps:std
275#[derive(Clone)]
276struct S;
277fn test() {
278 S.clone()<|>;
279}
280
281//- /lib.rs crate:std
282#[prelude_import]
283use clone::*;
284mod clone {
285 trait Clone {
286 fn clone(&self) -> Self;
287 }
288}
289"#,
290 );
291 assert_eq!("S", type_at_pos(&db, pos));
292}
293
294#[test]
295fn infer_derive_clone_with_params() {
296 let (db, pos) = TestDB::with_position(
297 r#"
298//- /main.rs crate:main deps:std
299#[derive(Clone)]
300struct S;
301#[derive(Clone)]
302struct Wrapper<T>(T);
303struct NonClone;
304fn test() {
305 (Wrapper(S).clone(), Wrapper(NonClone).clone())<|>;
306}
307
308//- /lib.rs crate:std
309#[prelude_import]
310use clone::*;
311mod clone {
312 trait Clone {
313 fn clone(&self) -> Self;
314 }
315}
316"#,
317 );
318 assert_eq!("(Wrapper<S>, {unknown})", type_at_pos(&db, pos));
319}