rust/crates
bors[bot] ac123ac9e4
Merge #6587
6587: SSR: Support statement matching and replacing r=davidlattimore a=MarijnS95


For #3186

Hi!

This is a smaller initial patchset that came up while working on support for statement lists (and my first time working on RA 😁). It has me stuck on trailing semicolons for which I hope to receive some feedback. Matching (and replacing) `let` bindings with a trailing semicolon works fine, but trying to omit these (to make patterns more ergonomic) turns out more complex than expected.

The "optional trailing semicolon solution" implemented in this PR is ugly because `Matcher::attempt_match_token` should only consume a trailing `;` when parsing `let` bindings to prevent other code from breaking. That at the same time has a nasty side-effect of `;` ending up in the matched code: any replacements on that should include the trailing semicolon as well even if it was not in the pattern. A better example is in the tests:

3ae1649c24/crates/ssr/src/tests.rs (L178-L184)

The end result to achieve is (I guess) allowing replacement of let bindings without trailing semicolon like `let x = $a ==>> let x = 1` (but including them on both sides is still fine), and should make replacement in a macro call (where `foo!(let a = 2;)` for a `$x:stmt` is invalid syntax) possible as well. That should allow to enable/fix these tests:

3ae1649c24/crates/ssr/src/tests.rs (L201-L214)

A possible MVP of this PR might be to drop this optional `;' handling entirely and only allow an SSR pattern/template with semicolons on either side.

Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>
2021-01-04 11:14:40 +00:00
..
arena
assists Support assignment to FieldExpr for extract_assignment assist 2021-01-03 15:46:57 +01:00
base_db Add support for Rust 2021. 2021-01-01 17:22:23 +01:00
cfg Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
completion Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
flycheck
hir Merge #7068 2021-01-03 09:03:15 +00:00
hir_def Merge #7113 2021-01-03 18:22:07 +00:00
hir_expand Revert "Proper handling $crate and local_inner_macros" 2021-01-03 11:47:57 +01:00
hir_ty Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
ide Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
ide_db Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
mbe Revert "Proper handling $crate and local_inner_macros" 2021-01-03 11:47:57 +01:00
parser parser,syntax: Add separate parser for stmt with optional semicolon 2021-01-03 12:05:52 +01:00
paths
proc_macro_api Remove serde_stacker which depends on cc 2021-01-01 15:26:55 +08:00
proc_macro_srv Fix spacing in proc-macro tokens to_string 2020-12-31 13:36:19 +08:00
proc_macro_test
profile
project_model Add support for Rust 2021. 2021-01-01 17:22:23 +01:00
rust-analyzer Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
ssr Merge #6587 2021-01-04 11:14:40 +00:00
stdx
syntax Merge #6587 2021-01-04 11:14:40 +00:00
test_utils
text_edit
toolchain
tt Move TokenExpander to base_db and rename it 2020-12-27 15:29:47 +01:00
vfs
vfs-notify