-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Comparison of static arrays #7012
Comments
This doesn't compile on incoming. Especially the types don't match, |
@Blei Hi Blei, my bad, I have fixed the code, could you please confirm this works on incomming? If it is fixed in incomming I will close. |
Hmm, this prints |
As some more information, I did some more checking, and this is almost certainly a bug in codegen. If you make the comparison a function, marked no-inline, then LLVM compresses it down to a single I'm also nominating this. |
The length is incorrectly set for vector slices in fields in static structs. struct signature<'self> {
pattern : &'self [u32]
}
struct signature2<'self> {
pattern : &'self str,
}
static test1: signature<'static> = signature {
pattern: &[0x243f6a88u32,0x85a308d3u32,0x13198a2eu32,0x03707344u32,0xa4093822u32,0x299f31d0u32],
};
static test2: signature2<'static> = signature2 {
pattern: "Hello!",
};
static test3: &'static [u32] = &[0x243f6a88u32,0x85a308d3u32,0x13198a2eu32,0x03707344u32,0xa4093822u32,0x299f31d0u32];
fn main() {
println(fmt!("Static &[u32] field:\t%2u", test1.pattern.len()));
println(fmt!("Static &str field:\t%2u", test2.pattern.len()));
println(fmt!("Static &[u32]:\t\t%2u", test3.len()));
} Results in
Corresponding llvm code:
|
Between the two of us, me and @dotdash have isolated this down to an auto-borrowing bug. Basically for this: static test : Foo<'static> = Foo {
field: &'static [1,2,3]
}; The One workaround (that will likely break when this is fixed) is to do this: static test : Foo<'static> = Foo {
field: [1,2,3]
} as the vector expression is still auto-borrowed. I ran up against my understanding of the compiler internals, but I narrowed it down to some wrong logic concerning the adjustments table. What, where or when this happens is beyond my knowledge, unfortunately. |
This seems similar to #5688. |
Unfortunately, this workaround isn't good enough for my purposes because it can not be uniformly applied. See the following example for details.
|
The code example in the original issue now works, flagging as needstest |
Fix ICE rust-lang#7012 changelog: none Fixes rust-lang#7012
Hello,
Just posting this to see if it is a bug. The expected behaviour would be that test==test1, therefore 'true' would be printed, however the below prints false. This was tested on windows running 0.6 release.
Edit: changed code, made sure types are correct, retested, returns false on 0.6
The text was updated successfully, but these errors were encountered: