Skip to content
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

Merged
merged 1 commit into from
Feb 22, 2021

Conversation

wooster0
Copy link
Contributor

struct A {
    x: i32,
    y: i32,
    z: i32,
}

fn main() {
    A { };
}
error[E0063]: missing fields `x`, `y`, `z` in initializer of `A`
 --> src/main.rs:8:5
  |
8 |     A { };
  |     ^ missing `x`, `y`, `z`

This error is now:

error[E0063]: missing fields `x`, `y` and `z` in initializer of `A`
 --> src/main.rs:8:5
  |
8 |     A { };
  |     ^ missing `x`, `y` and `z`

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.

@rust-highfive
Copy link
Collaborator

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 19, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@LingMan LingMan left a 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.

compiler/rustc_typeck/src/check/expr.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/check/expr.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/check/expr.rs Outdated Show resolved Hide resolved
@wooster0
Copy link
Contributor Author

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 src/test/ui/error-codes/E0063.rs and src/test/ui/error-codes/E0063.stderr. They didn't show up because I didn't need to change them.

@LingMan
Copy link
Contributor

LingMan commented Feb 19, 2021

They didn't show up because I didn't need to change them.

Right, forget my comment.

compiler/rustc_typeck/src/check/expr.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/check/expr.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 19, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

Thanks!
r=me after squashing commits.

@wooster0
Copy link
Contributor Author

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Feb 20, 2021

@r00ster91: 🔑 Insufficient privileges: Not in reviewers

@wooster0
Copy link
Contributor Author

@bors r=me

@Mark-Simulacrum
Copy link
Member

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Feb 20, 2021

📌 Commit 447ce27 has been approved by petrochenkov

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 20, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2021
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
@bors bors merged commit 20c1fa1 into rust-lang:master Feb 22, 2021
@rustbot rustbot added this to the 1.52.0 milestone Feb 22, 2021
@wooster0 wooster0 deleted the field_name_and branch September 24, 2021 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

8 participants