diff options
author | David Lattimore <[email protected]> | 2020-07-26 08:43:47 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-07-26 12:58:35 +0100 |
commit | b3ca36b2d9fe5f2ef27cc19ced232e3168b77a38 (patch) | |
tree | d7dce0768767f683eae0335a5c27e5cdcf4d7312 /crates/ra_ssr/src/tests.rs | |
parent | bb587fae1dc169aca2e587bc7876611852186dd5 (diff) |
SSR: Fix for path resolution of locals
It seems that Semantics::scope, if given a statement node, won't resolve
locals that were defined in the current scope, only in parent scopes.
Not sure if this is intended / expected behavior, but we work around it
for now by finding another nearby node to use as the scope (e.g. the
expression inside the EXPR_STMT).
Diffstat (limited to 'crates/ra_ssr/src/tests.rs')
-rw-r--r-- | crates/ra_ssr/src/tests.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/ra_ssr/src/tests.rs b/crates/ra_ssr/src/tests.rs index b38807c0f..18ef2506a 100644 --- a/crates/ra_ssr/src/tests.rs +++ b/crates/ra_ssr/src/tests.rs | |||
@@ -885,3 +885,40 @@ fn ufcs_matches_method_call() { | |||
885 | "#]], | 885 | "#]], |
886 | ); | 886 | ); |
887 | } | 887 | } |
888 | |||
889 | #[test] | ||
890 | fn replace_local_variable_reference() { | ||
891 | // The pattern references a local variable `foo` in the block containing the cursor. We should | ||
892 | // only replace references to this variable `foo`, not other variables that just happen to have | ||
893 | // the same name. | ||
894 | mark::check!(cursor_after_semicolon); | ||
895 | assert_ssr_transform( | ||
896 | "foo + $a ==>> $a - foo", | ||
897 | r#" | ||
898 | fn bar1() -> i32 { | ||
899 | let mut res = 0; | ||
900 | let foo = 5; | ||
901 | res += foo + 1; | ||
902 | let foo = 10; | ||
903 | res += foo + 2;<|> | ||
904 | res += foo + 3; | ||
905 | let foo = 15; | ||
906 | res += foo + 4; | ||
907 | res | ||
908 | } | ||
909 | "#, | ||
910 | expect![[r#" | ||
911 | fn bar1() -> i32 { | ||
912 | let mut res = 0; | ||
913 | let foo = 5; | ||
914 | res += foo + 1; | ||
915 | let foo = 10; | ||
916 | res += 2 - foo; | ||
917 | res += 3 - foo; | ||
918 | let foo = 15; | ||
919 | res += foo + 4; | ||
920 | res | ||
921 | } | ||
922 | "#]], | ||
923 | ) | ||
924 | } | ||