diff options
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 291bc9ae5..82c4aeddb 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -2336,6 +2336,66 @@ fn test() -> u64 { | |||
2336 | ); | 2336 | ); |
2337 | } | 2337 | } |
2338 | 2338 | ||
2339 | #[ignore] | ||
2340 | #[test] | ||
2341 | fn method_resolution_trait_before_autoref() { | ||
2342 | let t = type_at( | ||
2343 | r#" | ||
2344 | //- /main.rs | ||
2345 | trait Trait { fn foo(self) -> u128; } | ||
2346 | struct S; | ||
2347 | impl S { fn foo(&self) -> i8 { 0 } } | ||
2348 | impl Trait for S { fn foo(self) -> u128 { 0 } } | ||
2349 | fn test() { S.foo()<|>; } | ||
2350 | "#, | ||
2351 | ); | ||
2352 | assert_eq!(t, "u128"); | ||
2353 | } | ||
2354 | |||
2355 | #[test] | ||
2356 | fn method_resolution_trait_before_autoderef() { | ||
2357 | let t = type_at( | ||
2358 | r#" | ||
2359 | //- /main.rs | ||
2360 | trait Trait { fn foo(self) -> u128; } | ||
2361 | struct S; | ||
2362 | impl S { fn foo(self) -> i8 { 0 } } | ||
2363 | impl Trait for &S { fn foo(self) -> u128 { 0 } } | ||
2364 | fn test() { (&S).foo()<|>; } | ||
2365 | "#, | ||
2366 | ); | ||
2367 | assert_eq!(t, "u128"); | ||
2368 | } | ||
2369 | |||
2370 | #[test] | ||
2371 | fn method_resolution_impl_before_trait() { | ||
2372 | let t = type_at( | ||
2373 | r#" | ||
2374 | //- /main.rs | ||
2375 | trait Trait { fn foo(self) -> u128; } | ||
2376 | struct S; | ||
2377 | impl S { fn foo(self) -> i8 { 0 } } | ||
2378 | impl Trait for S { fn foo(self) -> u128 { 0 } } | ||
2379 | fn test() { S.foo()<|>; } | ||
2380 | "#, | ||
2381 | ); | ||
2382 | assert_eq!(t, "i8"); | ||
2383 | } | ||
2384 | |||
2385 | #[test] | ||
2386 | fn method_resolution_trait_autoderef() { | ||
2387 | let t = type_at( | ||
2388 | r#" | ||
2389 | //- /main.rs | ||
2390 | trait Trait { fn foo(self) -> u128; } | ||
2391 | struct S; | ||
2392 | impl Trait for S { fn foo(self) -> u128 { 0 } } | ||
2393 | fn test() { (&S).foo()<|>; } | ||
2394 | "#, | ||
2395 | ); | ||
2396 | assert_eq!(t, "u128"); | ||
2397 | } | ||
2398 | |||
2339 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | 2399 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { |
2340 | let file = db.parse(pos.file_id); | 2400 | let file = db.parse(pos.file_id); |
2341 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); | 2401 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); |
@@ -2344,6 +2404,11 @@ fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | |||
2344 | ty.display(db).to_string() | 2404 | ty.display(db).to_string() |
2345 | } | 2405 | } |
2346 | 2406 | ||
2407 | fn type_at(content: &str) -> String { | ||
2408 | let (db, file_pos) = MockDatabase::with_position(content); | ||
2409 | type_at_pos(&db, file_pos) | ||
2410 | } | ||
2411 | |||
2347 | fn infer(content: &str) -> String { | 2412 | fn infer(content: &str) -> String { |
2348 | let (db, _, file_id) = MockDatabase::with_single_file(content); | 2413 | let (db, _, file_id) = MockDatabase::with_single_file(content); |
2349 | let source_file = db.parse(file_id); | 2414 | let source_file = db.parse(file_id); |