Skip to content

Attempted to access a nonexistent field [E0609] #3123

Closed
@MahadMuhammad

Description

@MahadMuhammad

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions