We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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"),
ref v @ MyStruct(_) if *v == CONSTANT => println!("it compiles"),
The first version, matching directly the CONSTANT would be easier to read and understand.
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 !
The text was updated successfully, but these errors were encountered:
This is because const eval doesn't handle adjustments at all. I suppose this can wait until MIRI.
Sorry, something went wrong.
duplicate of #27918.
No branches or pull requests
Hi,
I tried to match constant strings inside a struct and wasn't able to compile the following code:
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 !
The text was updated successfully, but these errors were encountered: