kkoomen / vim-doge

(Do)cumentation (Ge)nerator for nearly 20 languages 📚 Generate proper code documentation with a single keypress. ⚡️🔥
GNU General Public License v3.0
1.01k stars 51 forks source link

Rust: Function parameters as patterns causes panic in helper #617

Closed RasmusRendal closed 1 year ago

RasmusRendal commented 1 year ago

Describe the bug Consider the following function:

pub fn do_thing((i, j): (u8, u8)) -> u8 {
    i * j
}

Apparently, you can use irrefutable patterns in function parameters to deconstruct your input.

But the parser in the helper does not account for that, leading to a panic:

$ vim-doge-helper --filepath src/test.rs --parser rust --line 1 --doc-name rustdoc
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/rust/parser.rs:108:34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

https://github.com/kkoomen/vim-doge/blob/4a1b44fa7c09556b79e87316ede5a7a45ff601dc/helper/src/rust/parser.rs#L103-L108

To Reproduce

  1. Create a file containing the code above
  2. Try to create documentation for the function do_thing

Expected behavior

Output of ./bin/vim-doge-helper --version

vim-doge-helper 4.3.2

Built from source using commit 4a1b44fa7c09556b79e87316ede5a7a45ff601dc

Output of vim --version Not applicable

kkoomen commented 1 year ago

Hi,

I didn't knew Rust had destructuring tbh, I rarely see this. Nonetheless, see corresponding PR #618 for the fix. I'll do a new release after #618 has been merged.

kkoomen commented 1 year ago

After #619 is merged, you can upgrade to the newest version.