-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Improve documentation for unreachable #19316
Conversation
b0b288b
to
af71b34
Compare
/// // The above loop always returns, so we must hint to the | ||
/// // type checker that it isn't possible to get down here | ||
/// | ||
/// unreachable!(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a few problems with this example:
- The function name is misspelled: it should read
get_at_least_100
. - The function should return
u32
, not()
. sum
is never declared (let mut sum = 0;
at the start of the function should work).- Perhaps most importantly, the
unreachable!()
here is unnecessary (it throws a warning for unreachable code) and can be removed, as the compiler can already verify that the only way theloop
can be exited (besides panicking) is with areturn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! All good points...
af71b34
to
4ce3ba4
Compare
/// Some(n) if n >= 0 => println!("Some(Non-negative)"), | ||
/// Some(n) if n < 0 => println!("Some(Negative)"), | ||
/// Some(_) => unreachable!(), // compile error if commented out | ||
/// None => println!("None") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation width?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to what?
fix: do not apply editorconfig to git commit msg
Fixes #18876