Skip to content

Conversation

steveklabnik
Copy link
Contributor

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
Contributor 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
Contributor 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
lnicola pushed a commit to lnicola/rust that referenced this pull request Mar 10, 2025
fix: do not apply editorconfig to git commit msg
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