diff options
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index a38fe35c7..c3edf42b1 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -2510,12 +2510,47 @@ fn method_resolution_where_clause_not_met() { | |||
2510 | trait Clone {} | 2510 | trait Clone {} |
2511 | trait Trait { fn foo(self) -> u128; } | 2511 | trait Trait { fn foo(self) -> u128; } |
2512 | struct S; | 2512 | struct S; |
2513 | impl S { fn foo(self) -> i8 { 0 } } | 2513 | impl<T> Trait for T where T: Clone {} |
2514 | impl<T> Trait for T where T: Clone { fn foo(self) -> u128 { 0 } } | ||
2515 | fn test() { (&S).foo()<|>; } | 2514 | fn test() { (&S).foo()<|>; } |
2516 | "#, | 2515 | "#, |
2517 | ); | 2516 | ); |
2518 | assert_eq!(t, "i8"); | 2517 | // This is also to make sure that we don't resolve to the foo method just |
2518 | // because that's the only method named foo we can find, which would make | ||
2519 | // the below tests not work | ||
2520 | assert_eq!(t, "{unknown}"); | ||
2521 | } | ||
2522 | |||
2523 | #[test] | ||
2524 | fn method_resolution_where_clause_1() { | ||
2525 | let t = type_at( | ||
2526 | r#" | ||
2527 | //- /main.rs | ||
2528 | trait Clone {} | ||
2529 | trait Trait { fn foo(self) -> u128; } | ||
2530 | struct S; | ||
2531 | impl Clone for S {}; | ||
2532 | impl<T> Trait for T where T: Clone {} | ||
2533 | fn test() { S.foo()<|>; } | ||
2534 | "#, | ||
2535 | ); | ||
2536 | assert_eq!(t, "u128"); | ||
2537 | } | ||
2538 | |||
2539 | #[test] | ||
2540 | fn method_resolution_where_clause_2() { | ||
2541 | let t = type_at( | ||
2542 | r#" | ||
2543 | //- /main.rs | ||
2544 | trait Into<T> { fn into(self) -> T; } | ||
2545 | trait From<T> { fn from(other: T) -> Self; } | ||
2546 | struct S1; | ||
2547 | struct S2; | ||
2548 | impl From<S2> for S1 {}; | ||
2549 | impl<T, U> Into<U> for T where U: From<T> {} | ||
2550 | fn test() { S2.into()<|>; } | ||
2551 | "#, | ||
2552 | ); | ||
2553 | assert_eq!(t, "S1"); | ||
2519 | } | 2554 | } |
2520 | 2555 | ||
2521 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | 2556 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { |