-
-
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
Conversation
|
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.
library/alloc/src/string.rs
Outdated
| } 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.
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.
Would you be ok with the let...else if the return block was on its own line?
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.
basically yes.
| 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.
698ff18 to
0ab59e7
Compare
This comment has been minimized.
This comment has been minimized.
…f let ... else return` in std
0ab59e7 to
0488690
Compare
|
it's so weird to me that that matters. oh well. |
|
@bors r+ rollup |
…bilee
Use `let`...`else` instead of `match foo { ... _ => return };` and `if let ... else return` in std
Split off rust-lang#148837.
…bilee
Use `let`...`else` instead of `match foo { ... _ => return };` and `if let ... else return` in std
Split off rust-lang#148837.
Rollup of 12 pull requests Successful merges: - #147602 (Deduplicate higher-ranked lifetime capture errors in impl Trait) - #147725 (Remove -Zoom=panic) - #148294 (callconv: fix mips64 aggregate argument passing for C FFI) - #148491 ( Correctly provide suggestions when encountering `async fn` with a `dyn Trait` return type) - #149417 (tidy: Detect outdated workspaces in workspace list) - #149458 (Run clippy on cg_gcc in CI) - #149679 (Restrict spe_acc to PowerPC SPE targets) - #149781 (Don't suggest wrapping attr in unsafe if it may come from proc macro) - #149795 (Use `let`...`else` instead of `match foo { ... _ => return };` and `if let ... else return` in std) - #149816 (Make typo in field and name suggestions verbose) - #149824 (Add a regression test for issue 145748) - #149826 (compiletest: tidy up `adb_path`/`adb_test_dir` handling) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 10 pull requests Successful merges: - #147725 (Remove -Zoom=panic) - #148294 (callconv: fix mips64 aggregate argument passing for C FFI) - #148491 ( Correctly provide suggestions when encountering `async fn` with a `dyn Trait` return type) - #149458 (Run clippy on cg_gcc in CI) - #149679 (Restrict spe_acc to PowerPC SPE targets) - #149781 (Don't suggest wrapping attr in unsafe if it may come from proc macro) - #149795 (Use `let`...`else` instead of `match foo { ... _ => return };` and `if let ... else return` in std) - #149816 (Make typo in field and name suggestions verbose) - #149824 (Add a regression test for issue 145748) - #149826 (compiletest: tidy up `adb_path`/`adb_test_dir` handling) r? `@ghost` `@rustbot` modify labels: rollup
Split off #148837.