-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Improve ?
error messages per RFC 1859
#35946
Comments
Now that it's part of the language, we can even print |
Yeah, that's exactly what I was hoping. |
Carrier trait. |
@nagisa can you elaborate? Do we have to wait on this kind of diagnostic until the Carrier stuff shakes out? |
@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 |
Maybe we can just put a |
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 error This error message seems to be guiding me towards implementing |
This is what you can get with rustc_on_unimplemented:
Bikeshed on wording. |
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::<()>() // error that 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 |
Until rust-lang/rust#35946 is fixed, so that the error message is clearer than not implementing the Carrier trait.
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 |
@durka seems good so far! |
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 |
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?). |
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 |
@bluss thanks! That definitely looks better :) I assume if you use
With this implementation, would it still be possible to add this note?
|
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 |
Implement CompilerDesugaringKind enum This is the first step outlined in #35946. I think that the variants of `CompilerDesugaringKind` should be changed, I didn't know what the official names for `...` and `<-` are. I'm not to sure how tests for the compiler work, but I would imagine that tests should be added such that `Symbol::intern(s) == CompilerDesugaringKind::from(s).as_symbol()` for valid `s`.
@huntiep regarding your question from #43984:
I think the thing you need to do is to create a second desugaring code, maybe something like |
@huntiep feel free to ping me on IRC. |
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? |
Well, looking through the RFC, there are a few things not covered. These are the heading:
|
@arielb1 mentioned in the |
I already opened #44755 for the mentoring instructions |
Fixes rust-lang#42725 or at least, this is the best we can really do. rust-lang#35946 is tracking better errors already, so that should cover the other part of it.
…avus Mention the name of ? in Result's docs Fixes rust-lang#42725 or at least, this is the best we can really do. rust-lang#35946 is tracking better errors already, so that should cover the other part of it.
|
@estebank what are the "errors cannot be interconverted case"? (See my earlier summary) |
The case where
When a return type is specified, we don't get suggestions:
|
OK, I updated the head comment to link to your post. |
We now point only at the |
Of the three cases, the first one is now:
and the third one is
|
The first case is unchanged. Only improvement I can think of would be to point at The current output for the second case is:
And for the third:
Note the suggestion to use Overall I feel quite happy with the current state and feel we can close this after pointing at the return type when having the implicit conversion failure. |
…-op, r=petrochenkov Point at the return type on `.into()` failure caused by `?` Fix rust-lang#35946.
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.
UPDATE 2: to close this ticket we need to improve the output of a single case left to point at the return type to explain where
usize
is coming from.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
()
?The text was updated successfully, but these errors were encountered: