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

struct fields are reported as unknown if their type is syntactically invalid. #126344

Closed
lolbinarycat opened this issue Jun 12, 2024 · 2 comments · Fixed by #127575
Closed

struct fields are reported as unknown if their type is syntactically invalid. #126344

lolbinarycat opened this issue Jun 12, 2024 · 2 comments · Fixed by #127575
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lolbinarycat
Copy link
Contributor

Code

struct Wrong {
    x: 1,
}

fn oops(w: &Wrong) {
    w.x;
}

Current output

Compiling playground v0.0.1 (/playground)
error: expected type, found `1`
 --> src/lib.rs:2:8
  |
1 | struct Wrong {
  |        ----- while parsing this struct
2 |     x: 1,
  |        ^ expected type

error[E0609]: no field `x` on type `&Wrong`
 --> src/lib.rs:6:7
  |
6 |     w.x;
  |       ^ unknown field

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

Desired output

Compiling playground v0.0.1 (/playground)
error: expected type, found `1`
 --> src/lib.rs:2:8
  |
1 | struct Wrong {
  |        ----- while parsing this struct
2 |     x: 1,
  |        ^ expected type

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

Rationale and extra context

this can lead to an unmanageably large number of errors if there is a syntactic error in a struct that is used frequently throughout a crate, potentially even thousands of lines.

Other cases

No response

Rust Version

rustc 1.80.0-nightly (debd22da6 2024-05-29)
binary: rustc
commit-hash: debd22da66cfa97c74040ebf68e420672ac8560e
commit-date: 2024-05-29
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Anything else?

No response

@lolbinarycat lolbinarycat added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 12, 2024
@lolbinarycat
Copy link
Contributor Author

this also happens when struct fields are delimited with ;, which the compiler detects, but still explodes over.

@lolbinarycat
Copy link
Contributor Author

perhaps if a struct is syntactically invalid, we should refrain from outputting errors about its fields.

@chenyukang chenyukang self-assigned this Jul 3, 2024
chenyukang added a commit to chenyukang/rust that referenced this issue Jul 9, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue 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 bors closed this as completed in 8c39ac9 Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants