-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fmt: remove crash! macro #5589
fmt: remove crash! macro #5589
Conversation
src/uu/fmt/src/linebreak.rs
Outdated
None => { | ||
return Err(USimpleError::new( | ||
1, | ||
"Failed to find a k-p linebreak solution. This should never happen.", |
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 think this text is right actually, this can, as far as I can tell, never happen. This is because the min_by_key
call only returns None
if the slice is empty, but the active
slice is initialized with at least one value. Maybe an unreachable!
call is more appropriate here. Although, I would also love to see the code refactored so that this case is eliminated. For example, we could also choose to just unwrap_or(0)
on this min_by_key
call, because active
is initialized with 0
. I'll leave that decision up to you :)
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.
This makes sense. Will mark the arm unreachable!
as unwrap_or
can give the impression that the default value can possibly be picked.
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.
Refactored to remove it completely.
GNU testsuite comparison:
|
@tertsdiepraam I've made the requested changes. I see another related PR on this issue, please let me know if these changes are now redundant. Also, on another note, I see that some unrelated tests are failing, ....is this supposed to happen? |
Ah I missed that there were two PRs. I don't think we should discard these changes necessarily. The other PR simply changes |
Thank you for your response @tertsdiepraam ! |
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 like it! Great work! I think this is the right way to go about it. I just think we should avoid the iter
method to simplify a bit.
src/uu/fmt/src/linebreak.rs
Outdated
.iter() | ||
.flat_map(|&&(mut best_idx)| { |
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.
.iter() | |
.flat_map(|&&(mut best_idx)| { | |
.map(|&(mut best_idx)| { |
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.
done!
src/uu/fmt/src/linebreak.rs
Outdated
} | ||
} | ||
}) | ||
.collect() |
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.
.collect() | |
.unwrap_or_default() |
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.
done!
GNU testsuite comparison:
|
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.
Great! Many thanks!
Related to issue: #5487
This removes
crash!
usage from fmt.