aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ssr/src/tests.rs
diff options
context:
space:
mode:
authorDavid Lattimore <[email protected]>2020-08-05 10:48:52 +0100
committerDavid Lattimore <[email protected]>2020-08-13 11:24:55 +0100
commit3100de842b3cc33c9ad364f10c7f740ac760f564 (patch)
tree7713e2aea0b47ec8141fcefba101871137137c09 /crates/ra_ssr/src/tests.rs
parentde1d93455f85747410efb69c28e0c1379e8e328a (diff)
Structured search replace now handles UFCS calls to trait methods
Diffstat (limited to 'crates/ra_ssr/src/tests.rs')
-rw-r--r--crates/ra_ssr/src/tests.rs29
1 files changed, 29 insertions, 0 deletions
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() {
1143 "#]], 1143 "#]],
1144 ); 1144 );
1145} 1145}
1146
1147#[test]
1148fn match_trait_method_call() {
1149 // `Bar::foo` and `Bar2::foo` resolve to the same function. Make sure we only match if the type
1150 // matches what's in the pattern. Also checks that we handle autoderef.
1151 let code = r#"
1152 pub struct Bar {}
1153 pub struct Bar2 {}
1154 pub trait Foo {
1155 fn foo(&self, _: i32) {}
1156 }
1157 impl Foo for Bar {}
1158 impl Foo for Bar2 {}
1159 fn main() {
1160 let v1 = Bar {};
1161 let v2 = Bar2 {};
1162 let v1_ref = &v1;
1163 let v2_ref = &v2;
1164 v1.foo(1);
1165 v2.foo(2);
1166 Bar::foo(&v1, 3);
1167 Bar2::foo(&v2, 4);
1168 v1_ref.foo(5);
1169 v2_ref.foo(6);
1170 }
1171 "#;
1172 assert_matches("Bar::foo($a, $b)", code, &["v1.foo(1)", "Bar::foo(&v1, 3)", "v1_ref.foo(5)"]);
1173 assert_matches("Bar2::foo($a, $b)", code, &["v2.foo(2)", "Bar2::foo(&v2, 4)", "v2_ref.foo(6)"]);
1174}