-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Use let...else instead of match foo { ... _ => return }; and if let ... else return in std
#149795
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
base: main
Are you sure you want to change the base?
Conversation
…f let ... else return` in std
|
rustbot has assigned @Mark-Simulacrum. Use |
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.
some of these format kinda weirdly.
| if let Some(new_secs) = secs.checked_add(1) { | ||
| secs = new_secs; | ||
| } else { | ||
| return None; | ||
| } | ||
| let Some(new_secs) = secs.checked_add(1) else { return None }; | ||
| secs = new_secs; |
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 feel it is much harder to read the control flow in this case because we have hidden the return off to the right.
| } else { | ||
| return Err(FromUtf16Error(())); | ||
| } | ||
| let Ok(c) = c else { return Err(FromUtf16Error(())) }; |
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 also loses clarity due to let-else, IMO.
| let (ptr, layout) = if let Some(mem) = unsafe { self.current_memory(elem_layout) } { | ||
| mem | ||
| } else { | ||
| let Some((ptr, layout)) = (unsafe { self.current_memory(elem_layout) }) else { |
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 is obviously fine, to be clear.
Split off #148837.