diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-12 19:36:36 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-12 19:36:36 +0100 |
commit | 0f57564f78207946fdb09e0cddc21a55966b1bc5 (patch) | |
tree | e8aa2948b2bb301f453307c35311634cda5de43b /crates/ra_hir/src/ty/tests.rs | |
parent | 02ba107bbf24b1d09e61f76bb64b7355076744c4 (diff) | |
parent | bc59f83991a6444ff2f2364b0e942e8a82943b6d (diff) |
Merge #1266
1266: Chalk integration / method resolution fixes r=matklad a=flodiebold
- fix impl blocks with unresolved target trait being treated as inherent impls
- add traits from prelude for method resolution, and deduplicate them
- blacklist some traits from being considered in where clauses, namely `Send`, `Sync`, `Sized`, and the `Fn` traits. We don't handle these correctly yet for several reasons, and this makes us much less likely to run into cases where Chalk gets very slow (because these usually only happen if there is no solution, and that's more likely to happen for these traits).
- when there's an errored where clause, return just that one (since it will be always false anyway). This also makes things easier on Chalk ;)
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 59c85daed..978cc2587 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -2502,6 +2502,35 @@ fn test() { (&S).foo()<|>; } | |||
2502 | } | 2502 | } |
2503 | 2503 | ||
2504 | #[test] | 2504 | #[test] |
2505 | fn method_resolution_trait_from_prelude() { | ||
2506 | let (mut db, pos) = MockDatabase::with_position( | ||
2507 | r#" | ||
2508 | //- /main.rs | ||
2509 | struct S; | ||
2510 | impl Clone for S {} | ||
2511 | |||
2512 | fn test() { | ||
2513 | S.clone()<|>; | ||
2514 | } | ||
2515 | |||
2516 | //- /lib.rs | ||
2517 | #[prelude_import] use foo::*; | ||
2518 | |||
2519 | mod foo { | ||
2520 | trait Clone { | ||
2521 | fn clone(&self) -> Self; | ||
2522 | } | ||
2523 | } | ||
2524 | "#, | ||
2525 | ); | ||
2526 | db.set_crate_graph_from_fixture(crate_graph! { | ||
2527 | "main": ("/main.rs", ["other_crate"]), | ||
2528 | "other_crate": ("/lib.rs", []), | ||
2529 | }); | ||
2530 | assert_eq!("S", type_at_pos(&db, pos)); | ||
2531 | } | ||
2532 | |||
2533 | #[test] | ||
2505 | fn method_resolution_where_clause_for_unknown_trait() { | 2534 | fn method_resolution_where_clause_for_unknown_trait() { |
2506 | // The blanket impl shouldn't apply because we can't even resolve UnknownTrait | 2535 | // The blanket impl shouldn't apply because we can't even resolve UnknownTrait |
2507 | let t = type_at( | 2536 | let t = type_at( |
@@ -2620,22 +2649,22 @@ fn method_resolution_slow() { | |||
2620 | let t = type_at( | 2649 | let t = type_at( |
2621 | r#" | 2650 | r#" |
2622 | //- /main.rs | 2651 | //- /main.rs |
2623 | trait Send {} | 2652 | trait SendX {} |
2624 | 2653 | ||
2625 | struct S1; impl Send for S1; | 2654 | struct S1; impl SendX for S1; |
2626 | struct S2; impl Send for S2; | 2655 | struct S2; impl SendX for S2; |
2627 | struct U1; | 2656 | struct U1; |
2628 | 2657 | ||
2629 | trait Trait { fn method(self); } | 2658 | trait Trait { fn method(self); } |
2630 | 2659 | ||
2631 | struct X1<A, B> {} | 2660 | struct X1<A, B> {} |
2632 | impl<A, B> Send for X1<A, B> where A: Send, B: Send {} | 2661 | impl<A, B> SendX for X1<A, B> where A: SendX, B: SendX {} |
2633 | 2662 | ||
2634 | struct S<B, C> {} | 2663 | struct S<B, C> {} |
2635 | 2664 | ||
2636 | trait Fn {} | 2665 | trait FnX {} |
2637 | 2666 | ||
2638 | impl<B, C> Trait for S<B, C> where C: Fn, B: Send {} | 2667 | impl<B, C> Trait for S<B, C> where C: FnX, B: SendX {} |
2639 | 2668 | ||
2640 | fn test() { (S {}).method()<|>; } | 2669 | fn test() { (S {}).method()<|>; } |
2641 | "#, | 2670 | "#, |