-
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
Make "missing field" error message more natural #82287
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. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Looks like there's currently no test for the case with >3 missing fields. Would be good to add one.
There is such tests, like in |
Right, forget my comment. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5576aab
to
4009d8a
Compare
This comment has been minimized.
This comment has been minimized.
Thanks! |
3869d38
to
447ce27
Compare
@bors r=petrochenkov |
@r00ster91: 🔑 Insufficient privileges: Not in reviewers |
@bors r=me |
@bors r=petrochenkov |
📌 Commit 447ce27 has been approved by |
Rollup of 9 pull requests Successful merges: - rust-lang#82098 (Add internal `collect_into_array[_unchecked]` to remove duplicate code) - rust-lang#82228 (Provide NonZero_c_* integers) - rust-lang#82287 (Make "missing field" error message more natural) - rust-lang#82351 (Use the first paragraph, instead of cookie-cutter text, for rustdoc descriptions) - rust-lang#82353 (rustdoc: Remove unnecessary `Cell` around `param_env`) - rust-lang#82367 (remove redundant option/result wrapping of return values) - rust-lang#82372 (improve UnsafeCell docs) - rust-lang#82379 (Fix sizes of repr(C) enums on hexagon) - rust-lang#82382 (rustdoc: Remove `fake_def_ids` RefCell) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This error is now:
I thought it looked nicer and more natural this way. Also, if there is >3 fields missing, there is an "and" as well ("missing `x`, `y`, `z` and 1 other field"), but for <=3 there is not. As such it improves consistency too.
As for the implementation, originally I ended up with a chunky
push_str
algorithm but then I figured I could just do the formatting manually since it's just 3 field names at maximum. It is comparatively readable.As a sidenote, one thing I was wondering about is, isn't there more cases where you have a list of things like field names? Maybe this whole thing can at some point later be made into a more general function to be used in multiple areas.