From 3100de842b3cc33c9ad364f10c7f740ac760f564 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Wed, 5 Aug 2020 19:48:52 +1000 Subject: Structured search replace now handles UFCS calls to trait methods --- crates/ra_ssr/src/tests.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'crates/ra_ssr/src/tests.rs') diff --git a/crates/ra_ssr/src/tests.rs b/crates/ra_ssr/src/tests.rs index 7d4d470c0..4bc09c1e4 100644 --- a/crates/ra_ssr/src/tests.rs +++ b/crates/ra_ssr/src/tests.rs @@ -1143,3 +1143,32 @@ fn replace_self() { "#]], ); } + +#[test] +fn match_trait_method_call() { + // `Bar::foo` and `Bar2::foo` resolve to the same function. Make sure we only match if the type + // matches what's in the pattern. Also checks that we handle autoderef. + let code = r#" + pub struct Bar {} + pub struct Bar2 {} + pub trait Foo { + fn foo(&self, _: i32) {} + } + impl Foo for Bar {} + impl Foo for Bar2 {} + fn main() { + let v1 = Bar {}; + let v2 = Bar2 {}; + let v1_ref = &v1; + let v2_ref = &v2; + v1.foo(1); + v2.foo(2); + Bar::foo(&v1, 3); + Bar2::foo(&v2, 4); + v1_ref.foo(5); + v2_ref.foo(6); + } + "#; + assert_matches("Bar::foo($a, $b)", code, &["v1.foo(1)", "Bar::foo(&v1, 3)", "v1_ref.foo(5)"]); + assert_matches("Bar2::foo($a, $b)", code, &["v2.foo(2)", "Bar2::foo(&v2, 4)", "v2_ref.foo(6)"]); +} -- cgit v1.2.3