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

Add a detailed note for missing comma typo w/ FRU syntax #104504

Merged
merged 1 commit into from
Nov 21, 2022

Conversation

compiler-errors
Copy link
Member

Thanks to @pierwill for working on this with me!

Fixes #104373, perhaps @alice-i-cecile can comment on the new error for the example provided on that issue -- feedback is welcome.

error[E0063]: missing field `defaulted` in initializer of `Outer`
  --> $DIR/multi-line-fru-suggestion.rs:14:5
   |
LL |     Outer {
   |     ^^^^^ missing `defaulted`
   |
note: this expression may have been misinterpreted as a `..` range expression
  --> $DIR/multi-line-fru-suggestion.rs:16:16
   |
LL |           inner: Inner {
   |  ________________^
LL | |             a: 1,
LL | |             b: 2,
LL | |         }
   | |_________^ this expression does not end in a comma...
LL |           ..Default::default()
   |           ^^^^^^^^^^^^^^^^^^^^ ... so this is interpreted as a `..` range expression, instead of functional record update syntax
help: to set the remaining fields from `Default::default()`, separate the last named field with a comma
   |
LL |         }, 
   |          +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0063`.

@rustbot
Copy link
Collaborator

rustbot commented Nov 16, 2022

r? @lcnr

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 16, 2022
@rustbot
Copy link
Collaborator

rustbot commented Nov 16, 2022

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki

@@ -0,0 +1,8 @@
hir_typeck_fru_note = this expression may have been misinterpreted as a `..` range expression
hir_typeck_fru_expr = this expression does not end in a comma...
hir_typeck_fru_expr2 = ... so this is interpreted as a `..` range expression, instead of functional record update syntax

Choose a reason for hiding this comment

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

"functional record update syntax" is pretty heavy on jargon (and this is an error beginners will regularly see). Google search for it turns up nothing unless you add Rust, in which case you get this RFC: https://rust-lang.github.io/rfcs/2528-type-changing-struct-update-syntax.html

Choose a reason for hiding this comment

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

Suggested change
hir_typeck_fru_expr2 = ... so this is interpreted as a `..` range expression, instead of functional record update syntax
hir_typeck_fru_expr2 = ... so this is interpreted as a `..` range expression, instead of functional record update syntax, used to set the remaining fields of a struct

Copy link
Member Author

Choose a reason for hiding this comment

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

This part of the error message is already pretty long, and it doesn't wrap well -- if you're against the jargon, I would rather remove everything after instead of.

Copy link
Member Author

@compiler-errors compiler-errors Nov 16, 2022

Choose a reason for hiding this comment

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

I'm also not too keen on the duplication of "used to set the remaining fields of a struct" between the note and the suggestion's "to set the remaining fields"

Choose a reason for hiding this comment

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

Hmm, I see your point! I think it's better left as is then.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe "struct update syntax"? I've heard that quite often when talking about FRU.

Applicability::MaybeIncorrect,
);
.ok()
.filter(|s| s.len() < 25 && !s.contains(|c: char| c.is_control()));

Choose a reason for hiding this comment

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

As someone new to this part of the codebase, this line is unclear to me. What's s, and why do we filter it like this? Why 25?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is to avoid rendering very long expressions in "to set the remaining fields in $EXPR"

Copy link
Member Author

Choose a reason for hiding this comment

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

25 is an arbitrary number.

Copy link
Member Author

Choose a reason for hiding this comment

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

And is_control is to avoid rendering something like:

to set the remaining fields in `a
.b`

Choose a reason for hiding this comment

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

Makes sense :) Perhaps leave a comment to this effect?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thing.

@estebank
Copy link
Contributor

r? @estebank
@bors r+

@bors
Copy link
Contributor

bors commented Nov 17, 2022

📌 Commit b85b47cfd6c17acf21c8e3d6de3f543f3dbef942 has been approved by estebank

It is now in the queue for this repository.

@rustbot rustbot assigned estebank and unassigned lcnr Nov 17, 2022
@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 Nov 17, 2022
@compiler-errors
Copy link
Member Author

@bors r- i still got some changes to make

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 17, 2022
@compiler-errors
Copy link
Member Author

@bors r=estebank

@bors
Copy link
Contributor

bors commented Nov 18, 2022

📌 Commit bb0cb9a has been approved by estebank

It is now in the queue for this repository.

@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 Nov 18, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 20, 2022
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#101310 (Clarify and restrict when `{Arc,Rc}::get_unchecked_mut` is allowed.)
 - rust-lang#104461 (Fix building of `aarch64-pc-windows-gnullvm`)
 - rust-lang#104487 (update ntapi dep to remove future-incompat warning)
 - rust-lang#104504 (Add a detailed note for missing comma typo w/ FRU syntax)
 - rust-lang#104581 (rustdoc: remove unused JS IIFE from main.js)
 - rust-lang#104632 (avoid non-strict-provenance casts in libcore tests)
 - rust-lang#104634 (move core::arch into separate file)
 - rust-lang#104641 (replace unusual grammar)
 - rust-lang#104643 (add examples to chunks remainder methods. )

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit fce077b into rust-lang:master Nov 21, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 21, 2022
@compiler-errors compiler-errors deleted the fru-syntax-note branch August 11, 2023 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Struct update syntax produces very confusing error messages when comma before .. is missed
7 participants