Skip to content

Refused to compile so I fixed refutable pattern matches in path conversion. #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from

Conversation

MustafaAamir
Copy link
Contributor

Error as a result of running cargo run:

error[E0005]: refutable pattern in local binding
   --> /home/mustafa/.cargo/registry/src/index.crates.io-6f17d22bba15001f/asm-lsp-0.10.0/lsp.rs:180:9
    |
180 |     let Ok(path) = PathBuf::from_str(&clean_path);
    |         ^^^^^^^^ pattern `Err(_)` not covered
    |
    = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
    = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
    = note: the matched value is of type `Result<PathBuf, Infallible>`
help: you might want to use `let else` to handle the variant that isn't matched
    |
180 |     let Ok(path) = PathBuf::from_str(&clean_path) else { todo!() };
    |                                                   ++++++++++++++++

error[E0005]: refutable pattern in local binding
    --> /home/mustafa/.cargo/registry/src/index.crates.io-6f17d22bba15001f/asm-lsp-0.10.0/lsp.rs:1948:17
     |
1948 |             let Ok(parsed) = PathBuf::from_str(folder.uri.path().as_str());
     |                 ^^^^^^^^^^ pattern `Err(_)` not covered
     |
     = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
     = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
     = note: the matched value is of type `Result<PathBuf, Infallible>`
help: you might want to use `let else` to handle the variant that isn't matched
     |
1948 |             let Ok(parsed) = PathBuf::from_str(folder.uri.path().as_str()) else { todo!() };
     |                                                                            ++++++++++++++++

error[E0005]: refutable pattern in local binding
    --> /home/mustafa/.cargo/registry/src/index.crates.io-6f17d22bba15001f/asm-lsp-0.10.0/lsp.rs:1959:13
     |
1959 |         let Ok(parsed) = PathBuf::from_str(root_uri.path().as_str());
     |             ^^^^^^^^^^ pattern `Err(_)` not covered
     |
     = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
     = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
     = note: the matched value is of type `Result<PathBuf, Infallible>`
help: you might want to use `let else` to handle the variant that isn't matched
     |
1959 |         let Ok(parsed) = PathBuf::from_str(root_uri.path().as_str()) else { todo!() };
     |                                                                      ++++++++++++++++

error[E0005]: refutable pattern in local binding
    --> /home/mustafa/.cargo/registry/src/index.crates.io-6f17d22bba15001f/asm-lsp-0.10.0/lsp.rs:1969:13
     |
1969 |         let Ok(parsed) = PathBuf::from_str(root_path.as_str());
     |             ^^^^^^^^^^ pattern `Err(_)` not covered
     |
     = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
     = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
     = note: the matched value is of type `Result<PathBuf, Infallible>`
help: you might want to use `let else` to handle the variant that isn't matched
     |
1969 |         let Ok(parsed) = PathBuf::from_str(root_path.as_str()) else { todo!() };
     |                                                                ++++++++++++++++

For more information about this error, try `rustc --explain E0005`.
error: could not compile `asm-lsp` (lib) due to 4 previous errors

Cargo version: cargo 1.81.0-nightly (154fdac39 2024-07-07)

Solution:

Explicitly handle the Err(_) case when parsing path.

- let Ok(path) = PathBuf::from_str(&clean_path);
+ let path = match PathBuf::from_str(&clean_path) {
+     Ok(path) => path,
+     Err(_) => continue,
+ }

@WillLillis
Copy link
Collaborator

This change was made intentionally in #162, as the original code was unnecessary verbose. I don't want to pull these changes into the project, but I really appreciate your desire to help out! If you'd like to add a MSRV in the README instead to help prevent issues like this in the future, I'd be happy to accept that.

@MustafaAamir
Copy link
Contributor Author

No worries! I'm curious though, why doesn't it compile with the cargo 1.81.0-nightly?

@WillLillis
Copy link
Collaborator

I'm not 100% sure, but it looks like this was stabilized in 1.82. Before that, it looks like the feature was gated behind the min_exhaustive_patterns feature.

@WillLillis
Copy link
Collaborator

Gentle ping @MustafaAamir. Would love a MSRV entry added to the README if you get the chance. :)

@MustafaAamir
Copy link
Contributor Author

Of course! I'm not familiar with msrv conventions for rust, but I ran cargo-msrv msrv find in the root directory of this project, which gave the following output:

Result:
   Considered (min … max):   Rust 0.11.0 … Rust 1.86.0
   Search method:            bisect
   MSRV:                     1.81.0
   Target:                   x86_64-unknown-linux-gnu
``
Will the MSRV information suffice on its own in the README? Or should I add the other findings as well. Thanks!

@WillLillis
Copy link
Collaborator

Of course! I'm not familiar with msrv conventions for rust, but I ran cargo-msrv msrv find in the root directory of this project, which gave the following output:

Result:
   Considered (min … max):   Rust 0.11.0 … Rust 1.86.0
   Search method:            bisect
   MSRV:                     1.81.0
   Target:                   x86_64-unknown-linux-gnu
``
Will the MSRV information suffice on its own in the README? Or should I add the other findings as well. Thanks!

No worries! The MSRV is 1.81.0 on this branch, but it's 1.82.0 on the current master:

Result:
   Considered (min ... max):   Rust 0.11.0 ... Rust 1.86.0
   Search method:            bisect
   MSRV:                     1.82.0
   Target:                   x86_64-unknown-linux-gnu

I would add something like the following just below the install instructions in the README:

Note that the minimum supported rust version (MSRV) for asm-lsp is 1.82.0, This is subject to change on the master branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants