Skip to content

Fix unreachable code warning for functions that return !#265

Merged
dtolnay merged 1 commit intodtolnay:masterfrom
de-vri-es:fix-unreachable-code-warning
Apr 11, 2024
Merged

Fix unreachable code warning for functions that return !#265
dtolnay merged 1 commit intodtolnay:masterfrom
de-vri-es:fix-unreachable-code-warning

Conversation

@de-vri-es
Copy link
Contributor

The generated code for function bodies produces an unreachable_code warning if the function has a ! return type.

The offending bit is:

if let Some(__ret) == None::<!> {
  // unreachable
}

This PR fixes the warning by simply adding #[allow(unreachable_code)] to the return statement. It also adds a test for it.

This problem can only be triggered on nightly with the never_type feature enabled, but it is easy to fix here.

The generated code for function bodies produces an `unreachable_code`
warning if the function has a `!` return type.

The offending bit is:
```rust
if let Some(__ret) == None::<!> {
  // unreachable
}
```

This PR fixes the warning by simply adding `#[allow(unreachable_code)]`
to the return statement. It also adds a test for it.

This problem can only be triggered on nightly with the `never_type`
feature enabled, but it is easy to fix here.
@dtolnay dtolnay linked an issue Apr 11, 2024 that may be closed by this pull request
Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thank you!

@dtolnay dtolnay merged commit b683da8 into dtolnay:master Apr 11, 2024
@dtolnay
Copy link
Owner

dtolnay commented Apr 11, 2024

Published in async-trait 0.1.80.

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.

async fn() -> ! triggers "unreachable expression" warning

2 participants