aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-05-12 19:36:36 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-05-12 19:36:36 +0100
commit0f57564f78207946fdb09e0cddc21a55966b1bc5 (patch)
treee8aa2948b2bb301f453307c35311634cda5de43b /crates/ra_hir/src/ty/tests.rs
parent02ba107bbf24b1d09e61f76bb64b7355076744c4 (diff)
parentbc59f83991a6444ff2f2364b0e942e8a82943b6d (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.rs41
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]
2505fn method_resolution_trait_from_prelude() {
2506 let (mut db, pos) = MockDatabase::with_position(
2507 r#"
2508//- /main.rs
2509struct S;
2510impl Clone for S {}
2511
2512fn test() {
2513 S.clone()<|>;
2514}
2515
2516//- /lib.rs
2517#[prelude_import] use foo::*;
2518
2519mod 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]
2505fn method_resolution_where_clause_for_unknown_trait() { 2534fn 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
2623trait Send {} 2652trait SendX {}
2624 2653
2625struct S1; impl Send for S1; 2654struct S1; impl SendX for S1;
2626struct S2; impl Send for S2; 2655struct S2; impl SendX for S2;
2627struct U1; 2656struct U1;
2628 2657
2629trait Trait { fn method(self); } 2658trait Trait { fn method(self); }
2630 2659
2631struct X1<A, B> {} 2660struct X1<A, B> {}
2632impl<A, B> Send for X1<A, B> where A: Send, B: Send {} 2661impl<A, B> SendX for X1<A, B> where A: SendX, B: SendX {}
2633 2662
2634struct S<B, C> {} 2663struct S<B, C> {}
2635 2664
2636trait Fn {} 2665trait FnX {}
2637 2666
2638impl<B, C> Trait for S<B, C> where C: Fn, B: Send {} 2667impl<B, C> Trait for S<B, C> where C: FnX, B: SendX {}
2639 2668
2640fn test() { (S {}).method()<|>; } 2669fn test() { (S {}).method()<|>; }
2641"#, 2670"#,