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

Try to recover more from struct field parse error #127426

Conversation

chenyukang
Copy link
Member

@chenyukang chenyukang commented Jul 6, 2024

Partially fixes #126344

I tried to recover more from parsing struct field error, instead of skipping the whole struct, we may continue to parse the other fields, this can help to reduce some noises when there is only one struct field is not parsed correctly, we will not report unknown field for all the other fields.

But this PR can not remove all later diagnostics from the struct, I'm not sure whether is worth to solve it, I think the main noise comes from too many fields are ignored, while the left one is trivial.

r? @estebank

@rustbot rustbot added 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 Jul 6, 2024
@chenyukang
Copy link
Member Author

chenyukang commented Jul 6, 2024

I tested on some local projects, the typical change is like this:

Current:

 mini-redis git:(master) ✗ cargo build      
   Compiling mini-redis v0.4.1 (/Users/yukang/code/playground/mini-redis)
error: struct fields are separated by `,`
  --> src/server.rs:29:26
   |
18 | struct Listener {
   |        -------- while parsing this struct
...
29 |     listener: TcpListener;
   |                          ^ help: replace `;` with `,`

error[E0609]: no field `limit_connections` on type `&mut Listener`
   --> src/server.rs:229:18
    |
229 |                 .limit_connections
    |                  ^^^^^^^^^^^^^^^^^ unknown field
    |
    = note: available field is: `db_holder`

error[E0609]: no field `notify_shutdown` on type `&mut Listener`
   --> src/server.rs:250:46
    |
250 |                 shutdown: Shutdown::new(self.notify_shutdown.subscribe()),
    |                                              ^^^^^^^^^^^^^^^ unknown field
    |
    = note: available field is: `db_holder`

error[E0609]: no field `shutdown_complete_tx` on type `&mut Listener`
   --> src/server.rs:254:42
    |
254 |                 _shutdown_complete: self.shutdown_complete_tx.clone(),
    |                                          ^^^^^^^^^^^^^^^^^^^^ unknown field
    |
    = note: available field is: `db_holder`

error[E0609]: no field `listener` on type `&mut Listener`
   --> src/server.rs:285:24
    |
285 |             match self.listener.accept().await {
    |                        ^^^^^^^^ unknown field
    |
    = note: available field is: `db_holder`

For more information about this error, try `rustc --explain E0609`.
error: could not compile `mini-redis` (lib) due to 5 previous errors

With fix:

mini-redis git:(master) ✗ cargo +dev2 build
   Compiling mini-redis v0.4.1 (/Users/yukang/code/playground/mini-redis)
error: struct fields are separated by `,`
  --> src/server.rs:29:26
   |
18 | struct Listener {
   |        -------- while parsing this struct
...
29 |     listener: TcpListener;
   |                          ^ help: replace `;` with `,`

error[E0609]: no field `listener` on type `&mut Listener`
   --> src/server.rs:285:24
    |
285 |             match self.listener.accept().await {
    |                        ^^^^^^^^ unknown field
    |
    = note: available fields are: `db_holder`, `limit_connections`, `notify_shutdown`, `shutdown_complete_tx`

For more information about this error, try `rustc --explain E0609`.
error: could not compile `mini-redis` (lib) due to 2 previous errors

@chenyukang chenyukang changed the title Try recover more from struct field parse error Try to recover more from struct field parse error Jul 6, 2024
@chenyukang
Copy link
Member Author

Got a better solution

@chenyukang chenyukang closed this Jul 10, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 10, 2024
…ice, r=<try>

Avoid no field error and ice no recovered struct variant

Fixes rust-lang#126744
Fixes rust-lang#126344, a more general fix compared with rust-lang#127426

r? `@oli-obk`

From `@compiler-errors` 's comment rust-lang#127502 (comment)
Seems most of the ADTs don't have taint, so maybe it's not proper to change `TyCtxt::type_of` query.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 11, 2024
…ice, r=compiler-errors

Avoid "no field" error and ICE on recovered ADT variant

Fixes rust-lang#126744
Fixes rust-lang#126344, a more general fix compared with rust-lang#127426

r? `@oli-obk`

From `@compiler-errors` 's comment rust-lang#127502 (comment)
Seems most of the ADTs don't have taint, so maybe it's not proper to change `TyCtxt::type_of` query.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

struct fields are reported as unknown if their type is syntactically invalid.
3 participants