Skip to content

Extend rustc_on_implemented to improve more ? error messages #85596

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

Merged
merged 1 commit into from
May 24, 2021

Conversation

scottmcm
Copy link
Member

_Self could match the generic definition; this adds that functionality for matching the generic definition of type parameters too.

Your advice welcome on the wording of all these messages, and which things belong in the message/label/note.

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2021
@scottmcm scottmcm changed the title Extend rustc_on_implemented to improve a ?-on-ControlFlow error message Extend rustc_on_implemented to improve more ? error messages May 23, 2021
@scottmcm scottmcm force-pushed the more-on-unimplemented branch from ca45e7e to b6d1cf1 Compare May 23, 2021 08:48
@scottmcm scottmcm force-pushed the more-on-unimplemented branch from b6d1cf1 to 8be6799 Compare May 23, 2021 14:18
--> $DIR/bad-interconversion.rs:22:22
|
LL | / fn result_to_option() -> Option<u16> {
LL | | Some(Err("hello")?)
| | ^ this `?` produces `Result<Infallible, &str>`, which is incompatible with `Option<u16>`
| | ^ use `.ok()?` if you want to discard the `Result<Infallible, &str>` error information
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be clearer if we mentioned something like if you want to discard the Result::Err(&str) or something along those lines 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the residual being "coloured" with the Try type does make it harder to put in this error message nicely. I guess it would be less bad with just Result<!, &str>, but Infallible is long enough to be distracting. 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more worried about confusing newcomers than anything else, anyone that already knows about Result, Option and .ok() wouldn't be confused regardless of wording, but someone who doesn't yet have a good grasp of what an enum even or that hasn't internalized Result::Err is the error information might be helped with things being more spelled out. Either way, I'm ok with the current wording.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been looking at the quadratic growth of the on-unimplemented attribute here and been wondering if it should turn into custom code for it at some point. If at some point in the future you get inspired with a great idea for how these error should look, feel free to assign me an issue. (Or, of course, just do it yourself if that's easier that answering my inevitable noob questions 😅)

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented May 24, 2021

📌 Commit 8be6799 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 24, 2021
@bors
Copy link
Collaborator

bors commented May 24, 2021

⌛ Testing commit 8be6799 with merge ef0ec30...

@bors
Copy link
Collaborator

bors commented May 24, 2021

☀️ Test successful - checks-actions
Approved by: estebank
Pushing ef0ec30 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 24, 2021
@bors bors merged commit ef0ec30 into rust-lang:master May 24, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 24, 2021
@scottmcm scottmcm deleted the more-on-unimplemented branch May 24, 2021 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants