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

Gccrs gets confused by mutable reference binding in match expressions #3174

Open
1 task
liamnaddell opened this issue Sep 19, 2024 · 0 comments
Open
1 task

Comments

@liamnaddell
Copy link
Contributor

Summary

I was trying to take a look at constexpr folding, and came across this bug. This seems to be due to a lack of ref mut support, i.e. #2082 's TODO list.

Rustc compiles this code happily

Reproducer

I tried this code:

extern "C" {
    fn printf(s: *const i8, ...);
}

enum Option {
    Some(i32), None
}

impl Option {
    fn add(&mut self) {
        match *self {
            Option::Some(ref mut a) => {*a += 1},
            Option::None => {},
        }
    }
}

fn main() {
    unsafe {
        let mut a = Option::None;
        a.add();
        let _s = "%d\n\0";
        let _s = _s as *const str;
        let s = _s as *const i8;
        printf(s,a);
    }
}

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

  • Nightly

Godbolt link

No response

Actual behavior

The current behavior is...

main.rs:12:41: error: expected reference type got i32
   12 |             Option::Some(ref mut a) => {*a += 1},
      |                                         ^
main.rs:12:41: error: cannot apply operator ‘+=’ to types <tyty::error> and <integer>

Expected behavior

Rustc compiles the code

GCC Version

483ee3a

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

No branches or pull requests

1 participant