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

Improve documentation for unreachable #19316

Merged
merged 1 commit into from
Nov 27, 2014
Merged

Conversation

steveklabnik
Copy link
Member

Fixes #18876

/// // The above loop always returns, so we must hint to the
/// // type checker that it isn't possible to get down here
///
/// unreachable!();
Copy link
Contributor

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 the loop can be exited (besides panicking) is with a return.

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops! All good points...

/// 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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation width?

Copy link
Member Author

Choose a reason for hiding this comment

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

to what?

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Nov 27, 2014
@bors bors merged commit 4ce3ba4 into rust-lang:master Nov 27, 2014
@steveklabnik steveklabnik deleted the gh18876 branch October 25, 2017 18: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.

Possibly bad example in documentation for 'unreachable!()'
5 participants