-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Unreachable code warning even when no code follows #89779
Comments
The match expression in this case I think is the one being linted against, and it is indeed dead in some sense. We might want to special case empty matches as sort of a "is uninhabited" assertion in code, I suppose... |
Here's a simple case that doesn't involve match. And code does follow fn main() {
if false {
stop().unwrap();
}
println!("Hello, world!");
}
fn stop() -> Result<std::convert::Infallible, u64> {
Err(5)
} The compiler warns that the println!() statement is unreachable, but the program works and prints as expected. I'm using stable-aarch64-apple-darwin rustc 1.56.0 (09c42c4 2021-10-18). The code that uncovered this contains a call to nix::unistd::execv. |
Yes, that seems like a genuine bug. Thanks! My guess is we're seeing that the println! is unreachable if the code path goes through the if expression, but of course, that can't actually happen here. cc @FabianWolff |
I have a case where all branches are reachable (appeared with rust 1.56) enum Never {}
fn terminate() -> Never
{
std::process::exit(1);
}
fn main() {
if std::env::args().count() > 1 {
println!("terminate");
terminate();
}
println!("Hello, world!");
}
|
#89779 (comment) and #89779 (comment) no longer trigger |
#85556 introduced an unreachable code warning after uninhabited expressions; unfortunately that warning fires even when no code follows the expression.
This makes it impossible to use patterns such as:
where the
match
is being used in the manner suggested by @nikomatsakis in a blog post.The text was updated successfully, but these errors were encountered: