Skip to content
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

Fix unreachable code warning for functions that return ! #265

Merged
merged 1 commit into from
Apr 11, 2024

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
10 checks passed
@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