Add ok-wrapping to catch blocks, per RFC#49371
Conversation
src/librustc/hir/lowering.rs
Outdated
There was a problem hiding this comment.
this seems ok; this has to do with #[foo] attributes
src/librustc/hir/lowering.rs
Outdated
There was a problem hiding this comment.
I think you want to call this.next_id() here
src/librustc/hir/lowering.rs
Outdated
There was a problem hiding this comment.
this would be where we report errors regarding this () expression; the block seems ok, but we might want to .. just use the closing brace }?
There was a problem hiding this comment.
we probably also want to give it the "desugaring" span
There was a problem hiding this comment.
How about we make a macro for this instead?
#[cfg(stage0)]
macro_rules do_catch {
($t:expr) = { (|| $t)() }
}
#[cfg(not(stage0))]
macro_rules do_catch {
($t:expr) = { do catch { $t } }
}
There was a problem hiding this comment.
And this way it can have ok-wrapping! 👍
src/librustc_mir/util/pretty.rs
Outdated
src/librustc_mir/util/pretty.rs
Outdated
|
first round of comments =) sorry for the delay. Cursed All Hands! |
|
Ok, it looks like this is working now. Thanks for the pointers! I added a UI test so you can see how the spans come out in type errors; if you would like them to be different please let me know how to do that -- this is my first time in this end of the compiler 🙂 |
|
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
nikomatsakis
left a comment
There was a problem hiding this comment.
Left some thoughts about span
src/test/run-pass/catch-expr.rs
Outdated
There was a problem hiding this comment.
Yeah, I filed #49356 about this. (Edit: Which I put in the comment; duh.) It feels to me like it ought to work, since the type needed here is completely determined by the context.
There was a problem hiding this comment.
I can imagine why it fails, we might be able to improve it.
There was a problem hiding this comment.
Hmm, this is ungreat. Not sure what span would be best, maybe @estebank has thoughts. I think maybe just pointing to the end-brace would be good?:
error[E0271]: type mismatch resolving `<std::option::Option<i32> as std::ops::Try>::Ok == ()`
--> $DIR/catch-block-type-error.rs:22:35
|
LL | };
| ^ expected i32, found ()
|
= note: expected type `i32`
found type `()`
Also, the "type mismatch" line is kind of a mess, but that's separate I guess and maybe hard to fix -- we might be able to use the "extra info" from the span to help.
There was a problem hiding this comment.
@scottmcm If you like how this looks I can give you a tip for how to achieve it =)
There was a problem hiding this comment.
In general I think multi-line spans are to be avoided at basically any cost.
There was a problem hiding this comment.
That seems plausible, though note that the multi-line span happens today for blocks:
error[E0308]: mismatched types
--> src/main.rs:2:19
|
2 | let x: i32 = {
| ___________________^
3 | | println!("asdf");
4 | | 3;
5 | | println!("asdf");
6 | | };
| |_____^ expected i32, found ()
|
= note: expected type `i32`
found type `()`I haven't looked into span futzing yet, so I don't know my unknowns. A few quick pointers would be great, or if you wanted to use me as a tester for a rustc book page...
There was a problem hiding this comment.
note that the multi-line span happens today for blocks
yes, but that doesn't make it good =)
I haven't looked into span futzing yet, so I don't know my unknowns
I believe that the end_point function is what you want
There was a problem hiding this comment.
Thanks! That did the trick. And huzzah for hosted compiler docs 🎉
0757abb to
9911de8
Compare
|
@bors r+ |
|
📌 Commit 9911de8 has been approved by |
|
☔ The latest upstream changes (presumably #48914) made this pull request unmergeable. Please resolve the merge conflicts. |
9911de8 to
311ff5b
Compare
|
Rebased; please re-r+. |
|
@bors r+ |
|
📌 Commit 311ff5b has been approved by |
|
@bors delegate=scottmcm (For future rebases) |
|
✌️ @scottmcm can now approve this pull request |
Add ok-wrapping to catch blocks, per RFC
Updates the `catch{}` lowering to wrap the result in `Try::from_ok`.
r? @nikomatsakis
Fixes #41414
Fixes #43818
|
☀️ Test successful - status-appveyor, status-travis |
Updates the
catch{}lowering to wrap the result inTry::from_ok.r? @nikomatsakis
Fixes #41414
Fixes #43818