Skip to content

Attempted to access a nonexistent field [E0609] #3123

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

Closed
1 task
MahadMuhammad opened this issue Aug 8, 2024 · 0 comments · Fixed by #3131
Closed
1 task

Attempted to access a nonexistent field [E0609] #3123

MahadMuhammad opened this issue Aug 8, 2024 · 0 comments · Fixed by #3131

Comments

@MahadMuhammad
Copy link
Contributor

MahadMuhammad commented Aug 8, 2024

Attempted to access a nonexistent field in a struct - E0609

Reproducer

I tried modified code from https://github.com/rust-lang/rustlings/blob/main/exercises/04_primitive_types/primitive_types6.rs and https://doc.rust-lang.org/error_codes/E0609.html:

#![allow(unused)]
fn main() {
    struct StructWithFields {
        x: u32,
    }

    let s = StructWithFields { x: 0 };
    s.foo; // error: no field `foo` on type `StructWithFields`

    let numbers = (1, 2, 3);
    numbers.3;
}

Does the code make use of any (1.49) nightly feature ?

  • Nightly

Godbolt

Actual behavior

The current behavior is, gccrs doesn't emit E0609 error code

<source>:8:5: error: unknown field [foo] for type [StructWithFields{StructWithFields {x:u32}}]
    8 |     s.foo; // error: no field `foo` on type `StructWithFields`
      |     ^
<source>:11:5: error: unknown field at index 3
   11 |     numbers.3;
      |     ^~~~~~~
Compiler returned: 1

Expected behavior

I expected to see gccrs emit E0609 error code

error[E0609]: no field `foo` on type `StructWithFields`
 --> <source>:8:7
  |
8 |     s.foo; // error: no field `foo` on type `StructWithFields`
  |       ^^^ unknown field
  |
  = note: available field is: `x`

error[E0609]: no field `3` on type `({integer}, {integer}, {integer})`
  --> <source>:11:13
   |
11 |     numbers.3;
   |             ^ unknown field

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0609`.
Compiler returned: 1

GCC Version

be1e78b

Addresses #2553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant