From 7fda874dd4c84d4b53ed625e9eccc92c3fa9a48e Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 11 May 2019 20:31:41 +0200 Subject: Blacklist some traits from being considered in where clauses For Send/Sync/Sized, we don't handle auto traits correctly yet and because they have a lot of impls, they can easily lead to slowdowns. In the case of Fn/FnMut/FnOnce, we don't parse the special Fn notation correctly yet and don't handle closures yet, so we are very unlikely to find an impl. --- crates/ra_hir/src/ty/tests.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src/ty/tests.rs') diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 59c85daed..510fa5333 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -2620,22 +2620,22 @@ fn method_resolution_slow() { let t = type_at( r#" //- /main.rs -trait Send {} +trait SendX {} -struct S1; impl Send for S1; -struct S2; impl Send for S2; +struct S1; impl SendX for S1; +struct S2; impl SendX for S2; struct U1; trait Trait { fn method(self); } struct X1 {} -impl Send for X1 where A: Send, B: Send {} +impl SendX for X1 where A: SendX, B: SendX {} struct S {} -trait Fn {} +trait FnX {} -impl Trait for S where C: Fn, B: Send {} +impl Trait for S where C: FnX, B: SendX {} fn test() { (S {}).method()<|>; } "#, -- cgit v1.2.3 From bc59f83991a6444ff2f2364b0e942e8a82943b6d Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 12 May 2019 14:58:37 +0200 Subject: Use traits from prelude for method resolution --- crates/ra_hir/src/ty/tests.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'crates/ra_hir/src/ty/tests.rs') diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 510fa5333..978cc2587 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -2501,6 +2501,35 @@ fn test() { (&S).foo()<|>; } assert_eq!(t, "u128"); } +#[test] +fn method_resolution_trait_from_prelude() { + let (mut db, pos) = MockDatabase::with_position( + r#" +//- /main.rs +struct S; +impl Clone for S {} + +fn test() { + S.clone()<|>; +} + +//- /lib.rs +#[prelude_import] use foo::*; + +mod foo { + trait Clone { + fn clone(&self) -> Self; + } +} +"#, + ); + db.set_crate_graph_from_fixture(crate_graph! { + "main": ("/main.rs", ["other_crate"]), + "other_crate": ("/lib.rs", []), + }); + assert_eq!("S", type_at_pos(&db, pos)); +} + #[test] fn method_resolution_where_clause_for_unknown_trait() { // The blanket impl shouldn't apply because we can't even resolve UnknownTrait -- cgit v1.2.3