-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Suggest return
ing tail expressions that match return type
#81769
Suggest return
ing tail expressions that match return type
#81769
Conversation
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
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.
small nits, otherwise LGTM
This comment has been minimized.
This comment has been minimized.
Some newcomers are confused by the behavior of tail expressions, interpreting that "leaving out the `;` makes it the return value". To help them go in the right direction, suggest using `return` instead when applicable.
When a tail expression isn't unit, we previously always suggested adding a trailing `;` to turn it into a statement. This suggestion isn't appropriate for any expression that doesn't have side-effects, as the user will have likely wanted to call something else or do something with the resulting value, instead of just discarding it.
5f3a1ce
to
86b3f3f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
88fd526
to
bb73759
Compare
This comment has been minimized.
This comment has been minimized.
bb73759
to
fc6c19e
Compare
@bors r=lcnr |
📌 Commit fc6c19e has been approved by |
…urn, r=lcnr Suggest `return`ing tail expressions that match return type Some newcomers are confused by the behavior of tail expressions, interpreting that "leaving out the `;` makes it the return value". To help them go in the right direction, suggest using `return` instead when applicable.
Rollup of 12 pull requests Successful merges: - rust-lang#79423 (Enable smart punctuation) - rust-lang#81154 (Improve design of `assert_len`) - rust-lang#81235 (Improve suggestion for tuple struct pattern matching errors.) - rust-lang#81769 (Suggest `return`ing tail expressions that match return type) - rust-lang#81837 (Slight perf improvement on char::to_ascii_lowercase) - rust-lang#81969 (Avoid `cfg_if` in `std::os`) - rust-lang#81984 (Make WASI's `hard_link` behavior match other platforms.) - rust-lang#82091 (use PlaceRef abstractions more consistently) - rust-lang#82128 (add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice) - rust-lang#82166 (add s390x-unknown-linux-musl target) - rust-lang#82234 (Remove query parameters when skipping search results) - rust-lang#82255 (Make `treat_err_as_bug` Option<NonZeroUsize>) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Erase late bound regions to avoid ICE Fixes rust-lang#82612, which is caused by rust-lang#81769. r? `@estebank`
or pattern matching way fn authenticate(name: String, password:String) |
@thedeveus sorry, I'm not sure I follow. Could you expand? |
This amends off of an existing test introduced in rust-lang#81769, if you think I should make a separate test I will.
Suggest `return`ing tail expressions in async functions This PR fixes rust-lang#92308. Previously, the suggestion to `return` tail expressions (introduced in rust-lang#81769) did not apply to `async` functions, as the suggestion checked whether the types were equal disregarding `impl Future<Output = T>` syntax sugar for `async` functions. This PR changes that in order to fix a potential papercut. I'm not sure if this is the "right" way to do this, so if there is a better way then please let me know. I amended an existing test introduced in rust-lang#81769 to add a regression test for this, if you think I should make a separate test I will.
Some newcomers are confused by the behavior of tail expressions,
interpreting that "leaving out the
;
makes it the return value".To help them go in the right direction, suggest using
return
insteadwhen applicable.