diff options
author | David Lattimore <[email protected]> | 2020-08-01 08:41:42 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-08-01 08:41:42 +0100 |
commit | 6bbeffc8c56893548f5667844f59ce5a76f9fd98 (patch) | |
tree | 446162072916f99a3c9b4c5e1734fbcc56cbd3f1 /crates/ra_ssr/src/tests.rs | |
parent | 5af32aeb2b83c7ae8adf3e088bf4f3691aa45eb1 (diff) |
SSR: Allow `self` in patterns.
It's now consistent with other variables in that if the pattern
references self, only the `self` in scope where the rule is invoked will
be accepted. Since `self` doesn't work the same as other paths, this is
implemented by restricting the search to just the current function.
Prior to this change (since path resolution was implemented), having
self in a pattern would just result in no matches.
Diffstat (limited to 'crates/ra_ssr/src/tests.rs')
-rw-r--r-- | crates/ra_ssr/src/tests.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/crates/ra_ssr/src/tests.rs b/crates/ra_ssr/src/tests.rs index 2ae03c64c..d483640df 100644 --- a/crates/ra_ssr/src/tests.rs +++ b/crates/ra_ssr/src/tests.rs | |||
@@ -1044,3 +1044,38 @@ fn replace_nonpath_within_selection() { | |||
1044 | }"#]], | 1044 | }"#]], |
1045 | ); | 1045 | ); |
1046 | } | 1046 | } |
1047 | |||
1048 | #[test] | ||
1049 | fn replace_self() { | ||
1050 | // `foo(self)` occurs twice in the code, however only the first occurrence is the `self` that's | ||
1051 | // in scope where the rule is invoked. | ||
1052 | assert_ssr_transform( | ||
1053 | "foo(self) ==>> bar(self)", | ||
1054 | r#" | ||
1055 | struct S1 {} | ||
1056 | fn foo(_: &S1) {} | ||
1057 | fn bar(_: &S1) {} | ||
1058 | impl S1 { | ||
1059 | fn f1(&self) { | ||
1060 | foo(self)<|> | ||
1061 | } | ||
1062 | fn f2(&self) { | ||
1063 | foo(self) | ||
1064 | } | ||
1065 | } | ||
1066 | "#, | ||
1067 | expect![[r#" | ||
1068 | struct S1 {} | ||
1069 | fn foo(_: &S1) {} | ||
1070 | fn bar(_: &S1) {} | ||
1071 | impl S1 { | ||
1072 | fn f1(&self) { | ||
1073 | bar(self) | ||
1074 | } | ||
1075 | fn f2(&self) { | ||
1076 | foo(self) | ||
1077 | } | ||
1078 | } | ||
1079 | "#]], | ||
1080 | ); | ||
1081 | } | ||