Skip to content

Allow unreachable_code in wasm error helper#1687

Merged
leighmcculloch merged 2 commits intomainfrom
fix-new-warning
Jan 22, 2026
Merged

Allow unreachable_code in wasm error helper#1687
leighmcculloch merged 2 commits intomainfrom
fix-new-warning

Conversation

@leighmcculloch
Copy link
Copy Markdown
Member

@leighmcculloch leighmcculloch commented Jan 20, 2026

What

Add #[allow(unreachable_code)] attribute to the error_from_error_val function for wasm targets to suppress a compiler warning introduced in Rust 1.92.0.

Why

I started seeing the following errors when building contracts using the soroban-sdk:

warning: unreachable expression
    --> soroban-sdk/src/env.rs:1770:6
     |
1769 |         self.env_impl.error_from_error_val(e)
     |         ------------------------------------- any code following this expression is unreachable
1770 |     }
     |      ^ unreachable expression
     |
note: this expression has type `Infallible`, which is uninhabited
    --> soroban-sdk/src/env.rs:1769:9
     |
1769 |         self.env_impl.error_from_error_val(e)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default

It appears Rust 1.92.0 changed how unreachable_code warnings are detected.

The error_from_error_val function returns Infallible, an uninhabited type. This is intentional behaviour. The function is designed to never return so the warning is suppressed.

I think this is probably the result of rust-lang/rust#142390 which landed in 1.92.0, but that change is quite deep and so I'm not certain of that.

In any case, I don't think what the code is doing here is incorrect, just a new warning is highlighting that there's an unreachable condition here, which is expected, so we should allow the condition.

@leighmcculloch leighmcculloch requested review from a team and graydon January 20, 2026 13:10
@leighmcculloch leighmcculloch marked this pull request as ready for review January 20, 2026 13:10
Copilot AI review requested due to automatic review settings January 20, 2026 13:10
Comment thread soroban-sdk/src/env.rs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a #[allow(unreachable_code)] attribute to suppress a new compiler warning introduced in Rust 1.92.0 for the error_from_error_val function when targeting wasm.

Changes:

  • Adds #[allow(unreachable_code)] attribute to the wasm-targeted error_from_error_val function to suppress a warning about unreachable closing brace

@leighmcculloch
Copy link
Copy Markdown
Member Author

Copy link
Copy Markdown
Contributor

@graydon graydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur with your assessment (though I also concur with "this is a little murky and I could be wrong")

Comment thread soroban-sdk/src/env.rs
@leighmcculloch leighmcculloch added this pull request to the merge queue Jan 22, 2026
Merged via the queue into main with commit 2bbd069 Jan 22, 2026
87 of 94 checks passed
@leighmcculloch leighmcculloch deleted the fix-new-warning branch January 22, 2026 04:27
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.

3 participants