Skip to content

Can't resolve SyntaxNodePtr when extracting struct from enum variant #16328

Closed
@shepmaster

Description

@shepmaster
enum TheEnum {
    TheVariant { the_field: u8 },
}

fn main() {
    vec![TheEnum::TheVariant { the_field: 42 }];
}

Place the cursor on TheVariant on line 2. Invoke "Extract struct from enum variant".

Panic context:
> 
version: 0.0.0 (12e7aa3132 2024-01-08)
request: codeAction/resolve CodeAction {
    title: "Extract struct from enum variant",
    group: None,
    kind: Some(
        CodeActionKind(
            "refactor.rewrite",
        ),
    ),
    command: None,
    edit: None,
    is_preferred: None,
    data: Some(
        CodeActionData {
            code_action_params: CodeActionParams {
                text_document: TextDocumentIdentifier {
                    uri: Url {
                        scheme: "file",
                        cannot_be_a_base: false,
                        username: "",
                        password: None,
                        host: None,
                        port: None,
                        path: "/private/tmp/reduce/src/main.rs",
                        query: None,
                        fragment: None,
                    },
                },
                range: Range {
                    start: Position {
                        line: 1,
                        character: 4,
                    },
                    end: Position {
                        line: 1,
                        character: 4,
                    },
                },
                context: CodeActionContext {
                    diagnostics: [],
                    only: None,
                    trigger_kind: None,
                },
                work_done_progress_params: WorkDoneProgressParams {
                    work_done_token: None,
                },
                partial_result_params: PartialResultParams {
                    partial_result_token: None,
                },
            },
            id: "extract_struct_from_enum_variant:RefactorRewrite:1",
        },
    ),
}

thread 'Worker' panicked at /Users/shep/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rowan-0.15.15/src/ast.rs:73:50:
can't resolve SyntaxNodePtr { kind: PATH_SEGMENT, range: 64..74 } with [email protected]
stack backtrace:
   0: rust_begin_unwind
             at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/core/src/panicking.rs:72:14
   2: rowan::ast::SyntaxNodePtr<L>::to_node
   3: ide_db::source_change::TreeMutator::make_syntax_mut
   4: ide_db::source_change::SourceChangeBuilder::make_mut
   5: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
   6: alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
   7: ide_assists::assist_context::Assists::add::{{closure}}
   8: ide_assists::assist_context::Assists::add_impl
   9: ide_assists::handlers::extract_struct_from_enum_variant::extract_struct_from_enum_variant
  10: ide_assists::assists
  11: std::panicking::try
  12: ide::Analysis::with_db
  13: ide::Analysis::assists_with_fixes
  14: rust_analyzer::handlers::request::handle_code_action_resolve
  15: std::panicking::try
  16: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

rust-analyzer version: rust-analyzer 0.0.0 (12e7aa3132 2024-01-08)

rustc version: rustc 1.75.0 (82e1608df 2023-12-21)

relevant settings: I'm using this through emacs.

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