rust/crates
bors[bot] 550c49657e
Merge #7147
7147: ssr: Allow replacing expressions with statements r=davidlattimore a=MarijnS95

Depends on #6587

Until that is merged, the diff is https://github.com/MarijnS95/rust-analyzer/compare/stmt..replace-expr-with-stmt

---

Now that statements can be matched and replaced (#6587) some usecases require expressions to be replaced with statements as well. This happens when something that can ambiguously be an expression or statement like `if` and loop blocks appear in the last position of a block, as trailing expression. In this case a replacement pattern of the form `if foo(){$a();}==>>$a();` will only substitute `if` blocks in the list of statements but not if they (implicitly) end up in the trailing expression, where they are not wrapped by an EXPR_STMT (but the pattern and template are, as parsing only succeeds for the `stmt ==>> stmt` case).

Instead of adding two rules that match an expression - and emit duplicate matching errors - allow the template for expressions to be a statement if it fails to parse as an expression.

---

Another gross change that does not seem to break any tests currently, but perhaps a safeguard should be added to only allow this kind of replacement in blocks by "pushing" the replacement template to the statement list and clearing the trailing expression?

CC @davidlattimore 

Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>
2021-01-04 20:36:13 +00:00
..
arena
assists rename exrtract_assignment -> pull 2021-01-04 16:41:57 +03: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 Show GotoTypeAction for TypeParam 2021-01-04 15:54:45 +01:00
hir_def Merge #7113 2021-01-03 18:22:07 +00:00
hir_expand Refactor TokenBuffer for reduc cloning 2021-01-05 02:00:46 +08:00
hir_ty Update crates 2021-01-04 11:12:42 -05:00
ide Show GotoTypeAction for TypeParam 2021-01-04 15:54:45 +01:00
ide_db Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
mbe Simplify SubtreeTokenSource 2021-01-05 02:00:51 +08: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 Fix HoverAction::Implementation typo 2021-01-04 14:38:08 +01:00
ssr Merge #7147 2021-01-04 20:36:13 +00:00
stdx
syntax Update crates 2021-01-04 11:12:42 -05:00
test_utils
text_edit
toolchain
tt Refactor TokenBuffer for reduc cloning 2021-01-05 02:00:46 +08:00
vfs
vfs-notify