-
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
Fix unreachable_code warnings for try{} block ok-wrapped expressions #64581
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/librustc_typeck/check/expr.rs
Outdated
// so we want avoid generating it. | ||
// Ditto for the autogenerated `Try::from_ok(())` at the end of e.g. `try { return; }`. | ||
let (is_try_block_ok_wrapped_expr, is_try_block_generated_expr) = match expr.node { | ||
ExprKind::Call(_, ref args) if expr.span.is_desugaring(DesugaringKind::TryBlock) => { |
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 code is rather brittle. I wonder if it would be better to just ok-wrap the whole try-block rather than the final expression.
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.
Well I tried that (desugaring try {...}
to { Try::from_ok({...}) }
) and the resulting code is indeed simpler (didn't push yet). The downside is that type errors now refer to the whole block and not to the tail expression (e.g. here). Thoughts?
r? @Centril |
Will schedule some time over the weekend to review this some more. :) |
This comment has been minimized.
This comment has been minimized.
b7b1475
to
988ee46
Compare
This comment has been minimized.
This comment has been minimized.
988ee46
to
58eacaa
Compare
@Centril hope you'll find some time to look at this! |
Sorry about the delay. Finally got around to this. It looks good, thanks! @bors r+ |
📌 Commit 58eacaa has been approved by |
…ode, r=Centril Fix unreachable_code warnings for try{} block ok-wrapped expressions Fixes rust-lang#54165 and fixes rust-lang#63324.
Failed in #64951 (comment), @bors r- (Will need to rebase to make |
58eacaa
to
75fdb95
Compare
@bors r+ |
📌 Commit 75fdb95 has been approved by |
…ode, r=Centril Fix unreachable_code warnings for try{} block ok-wrapped expressions Fixes rust-lang#54165 and fixes rust-lang#63324.
Rollup of 13 pull requests Successful merges: - #64581 (Fix unreachable_code warnings for try{} block ok-wrapped expressions) - #64850 (Remove inlines from DepNode code) - #64914 (regression test for 64453 borrow check error.) - #64922 (Use PlaceBuilder to avoid a lot of slice -> vec -> slice convertions) - #64948 (Improve sidebar styling to make its integration easier) - #64961 (Make comment about dummy type a bit more clear) - #64967 (Don't mark borrows of zero-sized arrays as indirectly mutable) - #64973 (Fix typo while setting `compile-flags` in test) - #64980 (Enable support for `IndirectlyMutableLocals` in `rustc_peek` ) - #64989 (Fix ICE #64964) - #64991 ([const-prop] Correctly handle locals that can't be propagated) - #64995 (Remove rustdoc warning) - #64997 (rustc book: nitpick SLP vectorization) Failed merges: r? @ghost
Fixes #54165 and fixes #63324.