Closed
Description
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 !