Skip to content

Conversation

@kaimast
Copy link
Contributor

@kaimast kaimast commented Jul 9, 2025

Motivation

A project I work on (snarkOS) uses this crate (through self_update). We have certain features that do not compile on WebAssembly. There's unfortunately not a nice way to set up these conflicts in Cargo or build.rs.
When they build those features, they get a fairly useless error that does not indicate anything related to wasm.

So, I thought it would be best to add a check in this crate, as it only seems to support unix and windows. I also found a few typos in lib.rs that the PR fixes.

Outcome

Before, you get a fairly cryptic error:

error[E0308]: mismatched types
   --> src/lib.rs:148:50
    |
148 | pub fn self_delete_at<P: AsRef<Path>>(exe: P) -> Result<(), io::Error> {
    |        --------------                            ^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Error>`, found `()`
    |        |
    |        implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `std::result::Result<(), std::io::Error>`
            found unit type `()`

error[E0308]: mismatched types
   --> src/lib.rs:165:58
    |
165 | pub fn self_delete_outside_path<P: AsRef<Path>>(p: P) -> Result<(), io::Error> {
    |        ------------------------                          ^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Error>`, found `()`
    |        |
    |        implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `std::result::Result<(), std::io::Error>`
            found unit type `()`

error[E0308]: mismatched types
   --> src/lib.rs:199:59
    |
199 | pub fn self_replace<P: AsRef<Path>>(new_executable: P) -> Result<(), io::Error> {
    |        ------------                                       ^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), Error>`, found `()`
    |        |
    |        implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `std::result::Result<(), std::io::Error>`
            found unit type `()`

With this change, it simply prints:

error: self-replace cannot be built for this target (only windows and unix is supported)
   --> src/lib.rs:124:1
    |
124 | compile_error!("self-replace cannot be built for this target (only windows and unix is supported)");
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@mitsuhiko mitsuhiko merged commit ea2a549 into mitsuhiko:main Jul 10, 2025
7 checks passed
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