diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-04 20:36:13 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-04 20:36:13 +0000 |
commit | 550c49657eabbe7583819c7e19c94eaa7d2c589e (patch) | |
tree | 1e022976d7828c59c9915b60ee8ee0068c9cd20d /crates/syntax | |
parent | 0708bfeb7270923be5a2059ad5b99de183e667ba (diff) | |
parent | d33edb4e9cf1cad1c9ceb7c99859d73993ccba29 (diff) |
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 <[email protected]>
Diffstat (limited to 'crates/syntax')
0 files changed, 0 insertions, 0 deletions