Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,11 @@ macro_rules! debug_assert_eq(
/// Iterators:
///
/// ```rust
/// fn divide_by_three(x: i32) -> i32 { // one of the poorest implementations of x/3
/// for i in std::iter::count(0_i32, 1) {
/// if i < 0 { panic!("i32 overflow"); }
/// if x < 3*i { return i; }
/// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
/// for i in std::iter::count(0_u32, 1) {
/// if 3*i < i { panic!("u32 overflow"); }
/// if x < 3*i { return i-1; }
Copy link
Contributor

Choose a reason for hiding this comment

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

<= 3*i should be sufficient (and more clear), no? Using checked_mul would also make more sense to me than the explicit panic guard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, with <= 3*i, this gives:

0/3=0
1/3=1
2/3=1
3/3=1
4/3=2
5/3=2
6/3=2

Copy link
Contributor

Choose a reason for hiding this comment

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

Derp, yes.

/// }
///
/// unreachable!();
/// }
/// ```
Expand Down