Skip to content

Destrure struct or tuple panic for usage in macro #20716

@A4-Tacks

Description

@A4-Tacks

rust-analyzer version: rust-analyzer 1.91.0-nightly (040a98a 2025-08-20)

rustc version: rustc 1.91.0-nightly (040a98a 2025-08-20)

editor or extension: Vim

code snippet to reproduce:

fn main() {
    let $0x = (2, 3);
    write!((), "{}", x.0);
}

fn main() {
    struct Foo { y: i8 }
    let $0x = Foo { y: 8 };
    write!((), "{}", x.y);
}

Panics:

can't resolve SyntaxNodePtr { kind: FIELD_EXPR, range: 25..28 } with SOURCE_FILE@0..92
    at handleResponse (/home/lrne/.vim/plugged/coc.nvim/build/index.js:20774:40)
    at handleMessage (/home/lrne/.vim/plugged/coc.nvim/build/index.js:20634:18)
    at Immediate.<anonymous> (/home/lrne/.vim/plugged/coc.nvim/build/index.js:20609:24)
    at process.processImmediate (node:internal/timers:511:21) {
  code: -32603,
  data: undefined
}

On tests panics:

panicked at /path/to/rust-analyzer/crates/syntax/src/syntax_editor.rs:98:9
assertion failed: is_ancestor_or_self_of_element(&old, &self.root)

But it seems difficult for me to fix it.

I use ctx.sema.original_range to get the range, but it's TokenTree and I can't get the FieldExpr

@rustbot label +A-assists

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions