Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImprove `?` error messages per RFC 1859 #35946
Comments
steveklabnik
added
the
A-diagnostics
label
Aug 23, 2016
This comment has been minimized.
This comment has been minimized.
|
Now that it's part of the language, we can even print |
This comment has been minimized.
This comment has been minimized.
|
Yeah, that's exactly what I was hoping. |
This comment has been minimized.
This comment has been minimized.
Carrier trait. |
This comment has been minimized.
This comment has been minimized.
|
@nagisa can you elaborate? Do we have to wait on this kind of diagnostic until the Carrier stuff shakes out? |
This comment has been minimized.
This comment has been minimized.
|
@durka I mean that such diagnostic will make no sense once we implement and accept the carrier trait. First, because then you’ll be able to use Implementing such special cased diagnostic now would 100% result in it being forgotten until somebody comes along and complains that diagnostic about |
This comment has been minimized.
This comment has been minimized.
|
Maybe we can just put a |
This comment has been minimized.
This comment has been minimized.
|
As of error[E0277]: the trait bound `(): std::ops::Carrier` is not satisfied
--> src/main.rs:6:13
|
6 | let f = File::open("hello.txt")?;
| ^^^^^^^^^^^^^^^^^^^^^^^^ trait `(): std::ops::Carrier` not satisfied
|
= note: required by `std::ops::Carrier::from_error`
error: aborting due to previous errorThis error message seems to be guiding me towards implementing |
This comment has been minimized.
This comment has been minimized.
|
This is what you can get with rustc_on_unimplemented:
Bikeshed on wording. |
This was referenced Oct 11, 2016
This comment has been minimized.
This comment has been minimized.
I am not sure if this is good enough. I've long been unsatisfied with i.e., here, we talk about return types, but if I wrote some code like: fn foo<T: Carrier>() { .. .}
foo::<()>() // errorthat error message would make any sense to me. These two things are of course related, since giving a "maybe wrong" message high prominence feels bad. That said, in this particular case, since Note that this is valuable even once |
carols10cents
added a commit
to rust-lang/book
that referenced
this issue
Oct 12, 2016
This comment has been minimized.
This comment has been minimized.
|
Here's what I have so far: fn does_not_return_result() -> i32 {
try!(Ok(42));
}
Need to inhibit that second note. Next step is to actually figure out whether the error came from |
This comment has been minimized.
This comment has been minimized.
|
@durka seems good so far! |
steveklabnik
added
I-papercut
T-compiler
labels
Nov 10, 2016
nrc
referenced this issue
Nov 13, 2016
Open
Tracking issue for `?` operator and `try` blocks (RFC 243, `question_mark` & `try_blocks` features) #31436
This was referenced Nov 29, 2016
This comment has been minimized.
This comment has been minimized.
|
Hi @durka, what do you have so far where? I don't see a PR linked to this issue at all :-/ Is there anyone I could bother to get you the help you need to finish this? I'd really love for this to get fixed before the new version of the book comes out, and for all the new rustaceans who are hitting this in the meantime <3 <3 <3 |
This comment has been minimized.
This comment has been minimized.
|
Hey @carols10cents, I don't really have anything working unfortunately. I'd like to pick it up again, I'll need some help though. I think that #38301 will change things anyway (@bluss why was that closed? is the design work that came out of ongoing somewhere?). |
This comment has been minimized.
This comment has been minimized.
|
It may look like I did something significant but I didn't think so. This rust-lang/rfcs/issues/1718 is the main thread, and niko proposed another variant of the formulation (which I confirmed compiles and works in rustc). It does change slightly for the better, it doesn't have a carrier trait anymore. fn does_not_return_result() -> i32 {
Ok(42)?
}
error[E0308]: mismatched types
--> test3.rs:2:5
|
2 | Ok(42)?;
| ^^^^^^^ expected i32, found enum `std::result::Result`
|
= note: expected type `i32`
= note: found type `std::result::Result<_, _>`
error[E0308]: mismatched types
--> test3.rs:1:36
|
1 | fn does_not_return_result() -> i32 {
| ____________________________________^ starting here...
2 | | Ok(42)?;
3 | | }
| |_^ ...ending here: expected i32, found ()
|
= note: expected type `i32`
= note: found type `()`
help: consider removing this semicolon:
--> test3.rs:2:12
|
2 | Ok(42)?;
| ^
error: aborting due to 2 previous errors
Edited, without the semicolon is maybe better: error[E0308]: mismatched types
--> test3.rs:2:5
|
2 | Ok(42)?
| ^^^^^^^ expected i32, found enum `std::result::Result`
|
= note: expected type `i32`
= note: found type `std::result::Result<_, _>`
error: aborting due to previous error |
This comment has been minimized.
This comment has been minimized.
|
@bluss thanks! That definitely looks better :) I assume if you use
With this implementation, would it still be possible to add this note?
|
carols10cents
referenced this issue
Jan 19, 2017
Merged
extend `?` to operate over other types #1859
steveklabnik
referenced this issue
Feb 19, 2017
Closed
Mention function return type explictly in errors #39909
This comment has been minimized.
This comment has been minimized.
ChrisJefferson
commented
Feb 19, 2017
|
I just wanted to mentio one more option, as a beginner rust user. I would find it helpful if the error message mentioned something like |
gypsydave5
referenced this issue
Feb 25, 2017
Merged
Fixes missing end to Ch09 02 on mdBook version #476
steveklabnik
removed
the
T-compiler
label
Mar 9, 2017
nodakai
marked this as
a duplicate of
#32175
Jul 16, 2017
Mark-Simulacrum
added
the
C-enhancement
label
Jul 26, 2017
This comment has been minimized.
This comment has been minimized.
|
Current output on nightly after #43001:
|
Mark-Simulacrum
removed
the
I-papercut
label
Jul 28, 2017
This comment has been minimized.
This comment has been minimized.
|
In order to really implement the full semantics described by RFC 1859, I think we will need to do something better than #43001. In #42526, we discussed that before we really start adding impls of Right now, the way that
I think this is roughly the idea. Happy to provide more details where needed. But ping on IRC or gitter if you don't get a response though, as it's easy to lose track of GH notifications. I think that to start it would be good to target this precise case I outlined, and I would probably do it in a few steps PRs (each of which could be a separate PR):
Once we get that working, we can cover the other cases described in the RFC. |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
changed the title
Question mark in main or other functions returning non-Results
Improve `?` error messages per RFC 1859
Jul 29, 2017
nikomatsakis
added
the
E-mentor
label
Jul 29, 2017
bors
added a commit
that referenced
this issue
Aug 17, 2017
bors
added a commit
that referenced
this issue
Aug 18, 2017
This comment has been minimized.
This comment has been minimized.
|
@huntiep regarding your question from #43984:
I think the thing you need to do is to create a second desugaring code, maybe something like |
This comment has been minimized.
This comment has been minimized.
|
@huntiep feel free to ping me on IRC. |
nikomatsakis
referenced this issue
Aug 31, 2017
Merged
More general `on_unimplemented`, with uses in `Try` #44191
This comment has been minimized.
This comment has been minimized.
|
So, between @huntiep and @arielb1, we now have a lot of progress on this topic. See for example the try-operator-on-main test case (output). Notably, we now say one of the following:
I think we can close this issue, right? |
This comment has been minimized.
This comment has been minimized.
|
Well, looking through the RFC, there are a few things not covered. These are the heading:
|
nikomatsakis
added
E-needs-mentor
and removed
E-mentor
labels
Sep 25, 2017
This comment has been minimized.
This comment has been minimized.
|
@arielb1 mentioned in the |
This comment has been minimized.
This comment has been minimized.
|
I already opened #44755 for the mentoring instructions |
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Dec 1, 2017
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Dec 5, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Dec 6, 2017
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
@estebank what are the "errors cannot be interconverted case"? (See my earlier summary) |
This comment has been minimized.
This comment has been minimized.
The case where
When a return type is specified, we don't get suggestions:
|
This comment has been minimized.
This comment has been minimized.
|
OK, I updated the head comment to link to your post. |
steveklabnik commentedAug 23, 2016
•
edited by nikomatsakis
RFC 1859 laid out specific error messages for the
?operator, but currently they are not implemented (and instead the compiler's internal desugaring is revealed).UPDATE: Many parts of this are done, but not all. Here is a post with examples that are not yet great.
Original text:
try!in main has long been an issue, to the point of trying to adjust the language to support it: rust-lang/rfcs#1176I was trying out
?today, and hit this error:That's the only line, inside of a
main()function. Even though I know about this pitfall, and have been using Rust for a long time, I asked a question about it on IRC.Can we print a better diagnostic here that points out it's the return type of the function that's looking for
()?