rust-analyzer/crates
bors[bot] e6728a8cd3
Merge #8415
8415: Fix faulty assertion when extracting function with macro call r=matklad a=brandondong

**Reproduction:**
```rust
fn main() {
    let n = 1;
    let k = n * n;
    dbg!(n);
}
```
1. Select the second and third lines of the main function. Use the "Extract into function" code assist.
2. Panic occurs in debug, error is logged in release: "[ERROR ide_assists::handlers::extract_function] assertion failed: matches!(path, ast :: Expr :: PathExpr(_))".
3. Function generates successfully on release where the panic was bypassed.
```rust
fn fun_name(n: i32) {
    let k = n * n;
    dbg!(n);
}
```

**Cause:**
- The generated function will take `n` as a parameter. The extraction logic needs to search the usages of `n` to determine whether it is used mutably or not. The helper `path_element_of_reference` is called for each usage but the second usage is a macro call and fails the `Expr::PathExpr(_)` match assertion.
- The caller of `path_element_of_reference` does implicitly assume it to be a `Expr::PathExpr(_)` in how it looks at its parent node for determining whether it is used mutably. This logic will not work for macros.
- I'm not sure if there are any other cases besides macros where it could be something other than a `Expr::PathExpr(_)`. I tried various examples and could not find any.

**Fix:**
- Update assertion to include the macro case.
- Add a FIXME to properly handle checking if a macro usage requires mutable access. For now, return false instead of running the existing logic that is tailored for `Expr::PathExpr(_)`'s.

Co-authored-by: Brandon <brandondong604@hotmail.com>
2021-04-13 11:39:03 +00:00
..
base_db Adjust fixture docs a bit 2021-04-06 21:42:27 +03:00
cfg Make ast_to_token_tree infallible 2021-04-04 01:46:45 +02:00
flycheck Bump cargo_metadata 2021-03-02 14:27:29 +02:00
hir Improve indexing of impls 2021-04-09 11:21:31 +02:00
hir_def Support macros in pattern position 2021-04-11 01:25:50 +02:00
hir_expand Support macros in pattern position 2021-04-11 01:25:50 +02:00
hir_ty Remove assertion in impl collection 2021-04-11 12:07:58 +02:00
ide Merge #8489 2021-04-13 10:06:36 +00:00
ide_assists Merge #8415 2021-04-13 11:39:03 +00:00
ide_completion Use CompletionTextEdit::InsertAndReplace if supported by the client 2021-04-08 15:21:27 +02:00
ide_db Avoid O(n²) when constructing AttrSourceMap 2021-04-06 22:25:44 +02:00
ide_ssr syntax: return owned string instead of leaking string 2021-03-26 18:30:59 +01:00
mbe Make ast_to_token_tree infallible 2021-04-04 01:46:45 +02:00
parser Parse extended_key_value_attributes 2021-03-19 02:13:46 +01:00
paths Clearer naming 2021-04-06 16:22:26 +03:00
proc_macro_api Trim down IPC json size 2021-03-24 15:01:37 +08:00
proc_macro_srv Fix parse u128 bug in proc-macro 2021-03-31 19:50:36 +08:00
proc_macro_test Add description for crates that will be published 2020-08-24 13:07:22 +02:00
profile internal: revive google_cpu_profile infra 2021-03-30 17:29:43 +03:00
project_model feat: avoid checking the whole project during initial loading 2021-04-12 15:29:31 +03:00
rust-analyzer feat: improve performance by delaying computation of fixes for diagnostics 2021-04-13 12:09:04 +03:00
stdx feat: show errors from cargo metadata and initial cargo check in the status bar 2021-04-06 18:08:05 +03:00
syntax Update crates 2021-04-07 11:39:33 -04:00
test_utils internal: fix flakiness of accidentally quadratic test 2021-04-13 12:56:24 +03:00
text_edit Avoid turning completion objects into builders 2020-11-16 23:16:41 +02:00
toolchain Add description for crates that will be published 2020-08-24 13:07:22 +02:00
tt a lot of clippy::style fixes 2021-03-21 16:15:41 +01:00
vfs Avoid duplicating VfsPath in vfs::path_interner::PathInterner by using an IndexSet 2021-04-06 16:03:57 +03:00
vfs-notify Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00