Rust-GCC / gccrs

GCC Front-End for Rust
https://rust-gcc.github.io/
GNU General Public License v2.0
2.4k stars 154 forks source link

Assigning structs to variables #3104

Open liamnaddell opened 3 months ago

liamnaddell commented 3 months ago

Summary

gccrs lets you assign structs to variables, when rustc emits "expected value, found struct ..."

Reproducer

I tried this code:

struct A {
    a: u32,
}

fn main() {
    let a = A {a: 4};
    let b = A;
    a.a = 2;
}

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

Godbolt link

No response

Actual behavior

The current behavior is...

The code compiles.

Expected behavior

I expected to see...

error[E0423]: expected value, found struct `A`
 --> main.rs:7:13
  |
1 | / struct A {
2 | |     a: u32,
3 | | }
  | |_- `A` defined here
...
7 |       let b = A;

GCC Version

commit-hash: c83b22a6932240194879ea7d9e783a4c0daf1b79

philberty commented 1 month ago

Interesting issue this because in my head i thought it would just be like C:

struct test {
    int a;
    int b;
};

void test()
{
    struct test x = { .a = 1, .b = 2};
    struct test y = x;
}

Hmmm not sure if this is something we should just be doing at the code-generation level or a new lint pass.

liamnaddell commented 1 month ago

Interesting issue this because in my head i thought it would just be like C:

struct test {
    int a;
    int b;
};

void test()
{
    struct test x = { .a = 1, .b = 2};
    struct test y = x;
}

Hmmm not sure if this is something we should just be doing at the code-generation level or a new lint pass.

the example here is different than what I showed in the issue description, I think

liamnaddell commented 1 month ago

I think the C equivalent would be

struct test {
    int a;
    int b;
};

void test()
{
    struct test x = { .a = 1, .b = 2};
    struct test y = struct test;
}
dkm commented 1 month ago

You should probably also get an error because a is not mutable...

dkm commented 1 month ago

Here's a reproducer link:https://rust.godbolt.org/z/TKqKnMMs4

philberty commented 1 month ago

I am such an idiot i misread this

liamnaddell commented 1 month ago

I am such an idiot i misread this

I made the exact same mistake when writing the code. It was only after compiling with rustc that I realized