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

Broken MIR, bad field access when matching constants #41808

Closed
cpichard opened this issue May 7, 2017 · 2 comments
Closed

Broken MIR, bad field access when matching constants #41808

cpichard opened this issue May 7, 2017 · 2 comments
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@cpichard
Copy link

cpichard commented May 7, 2017

Hi,
I tried to match constant strings inside a struct and wasn't able to compile the following code:

use std::ffi::*;

#[derive(PartialEq, Eq)]
pub struct MyStruct<'a>(&'a [u8]);

pub const CONSTANT: MyStruct<'static> =
    MyStruct(b"ConstantString\0");

fn main() {
    let cstr = CString::new("ConstantString").unwrap();
    match MyStruct(cstr.to_bytes_with_nul()) {
        CONSTANT => println!("compilation error here"),
        _ => println!("not found"),
    }
}

The compiler returns an internal compilation error.

I managed to compile using:
ref v @ MyStruct(_) if *v == CONSTANT => println!("it compiles"),

The first version, matching directly the CONSTANT would be easier to read and understand.

META

rustc 1.17.0 (56124ba 2017-04-24)
binary: rustc
commit-hash: 56124ba
commit-date: 2017-04-24
host: x86_64-apple-darwin
release: 1.17.0
LLVM version: 3.9

Thanks !

@arielb1
Copy link
Contributor

arielb1 commented May 7, 2017

This is because const eval doesn't handle adjustments at all. I suppose this can wait until MIRI.

@nagisa nagisa added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html labels May 8, 2017
@arielb1
Copy link
Contributor

arielb1 commented May 15, 2017

duplicate of #27918.

@arielb1 arielb1 closed this as completed May 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants