aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-05-05 13:21:00 +0100
committerFlorian Diebold <[email protected]>2019-05-11 15:21:20 +0100
commit50bbf9eb09dc34781cc34e10bfba5f154e833123 (patch)
tree6ed1ff97c8923ddeea085c75d417d5185493ef11 /crates/ra_hir/src/ty/tests.rs
parent940c538ecf42a53e5a0e0e9ebad7267c1fe843ca (diff)
Handle where clauses in trait solving
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs41
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() {
2510trait Clone {} 2510trait Clone {}
2511trait Trait { fn foo(self) -> u128; } 2511trait Trait { fn foo(self) -> u128; }
2512struct S; 2512struct S;
2513impl S { fn foo(self) -> i8 { 0 } } 2513impl<T> Trait for T where T: Clone {}
2514impl<T> Trait for T where T: Clone { fn foo(self) -> u128 { 0 } }
2515fn test() { (&S).foo()<|>; } 2514fn 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]
2524fn method_resolution_where_clause_1() {
2525 let t = type_at(
2526 r#"
2527//- /main.rs
2528trait Clone {}
2529trait Trait { fn foo(self) -> u128; }
2530struct S;
2531impl Clone for S {};
2532impl<T> Trait for T where T: Clone {}
2533fn test() { S.foo()<|>; }
2534"#,
2535 );
2536 assert_eq!(t, "u128");
2537}
2538
2539#[test]
2540fn method_resolution_where_clause_2() {
2541 let t = type_at(
2542 r#"
2543//- /main.rs
2544trait Into<T> { fn into(self) -> T; }
2545trait From<T> { fn from(other: T) -> Self; }
2546struct S1;
2547struct S2;
2548impl From<S2> for S1 {};
2549impl<T, U> Into<U> for T where U: From<T> {}
2550fn test() { S2.into()<|>; }
2551"#,
2552 );
2553 assert_eq!(t, "S1");
2519} 2554}
2520 2555
2521fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 2556fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {