diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests/traits.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index c6851fb69..17611ddbf 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -1014,6 +1014,31 @@ fn test() { | |||
1014 | } | 1014 | } |
1015 | 1015 | ||
1016 | #[test] | 1016 | #[test] |
1017 | fn argument_impl_trait_to_fn_pointer() { | ||
1018 | assert_snapshot!( | ||
1019 | infer_with_mismatches(r#" | ||
1020 | trait Trait {} | ||
1021 | fn foo(x: impl Trait) { loop {} } | ||
1022 | struct S; | ||
1023 | impl Trait for S {} | ||
1024 | |||
1025 | fn test() { | ||
1026 | let f: fn(S) -> () = foo; | ||
1027 | } | ||
1028 | "#, true), | ||
1029 | @r###" | ||
1030 | [23; 24) 'x': impl Trait | ||
1031 | [38; 49) '{ loop {} }': () | ||
1032 | [40; 47) 'loop {}': ! | ||
1033 | [45; 47) '{}': () | ||
1034 | [91; 124) '{ ...foo; }': () | ||
1035 | [101; 102) 'f': fn(S) -> () | ||
1036 | [118; 121) 'foo': fn foo(S) -> () | ||
1037 | "### | ||
1038 | ); | ||
1039 | } | ||
1040 | |||
1041 | #[test] | ||
1017 | #[ignore] | 1042 | #[ignore] |
1018 | fn impl_trait() { | 1043 | fn impl_trait() { |
1019 | assert_snapshot!( | 1044 | assert_snapshot!( |
@@ -1377,6 +1402,32 @@ fn test<T: Trait1, U: Trait2>(x: T, y: U) { | |||
1377 | } | 1402 | } |
1378 | 1403 | ||
1379 | #[test] | 1404 | #[test] |
1405 | fn super_trait_impl_trait_method_resolution() { | ||
1406 | assert_snapshot!( | ||
1407 | infer(r#" | ||
1408 | mod foo { | ||
1409 | trait SuperTrait { | ||
1410 | fn foo(&self) -> u32 {} | ||
1411 | } | ||
1412 | } | ||
1413 | trait Trait1: foo::SuperTrait {} | ||
1414 | |||
1415 | fn test(x: &impl Trait1) { | ||
1416 | x.foo(); | ||
1417 | } | ||
1418 | "#), | ||
1419 | @r###" | ||
1420 | [50; 54) 'self': &Self | ||
1421 | [63; 65) '{}': () | ||
1422 | [116; 117) 'x': &impl Trait1 | ||
1423 | [133; 149) '{ ...o(); }': () | ||
1424 | [139; 140) 'x': &impl Trait1 | ||
1425 | [139; 146) 'x.foo()': u32 | ||
1426 | "### | ||
1427 | ); | ||
1428 | } | ||
1429 | |||
1430 | #[test] | ||
1380 | fn super_trait_cycle() { | 1431 | fn super_trait_cycle() { |
1381 | // This just needs to not crash | 1432 | // This just needs to not crash |
1382 | assert_snapshot!( | 1433 | assert_snapshot!( |