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

Add #![feature(const_fn_union)] when needed #51

Closed
wants to merge 1 commit into from

Conversation

whentze
Copy link

@whentze whentze commented Aug 14, 2018

This crate currently fails to compile on the newest nightly when using the "const-fn" feature because unions in const fns now require a feature flag. This change adds the feature flag when using that feature.

This crate currently fails to compile on the newest nightly when using the "const-fn" feature because unions in const fns now require a feature flag. This change adds the feature flag when using that feature.
@XOSplicer
Copy link
Contributor

XOSplicer commented Aug 15, 2018

Hi, great spotting.
However bors seems to fail to build this PR on rustc 1.30.0-nightly (67390c0c3 2018-08-14) with target x86_64-unknown-linux-gnu when the tests for the full feature set are build.

XOSplicer#5
https://travis-ci.org/XOSplicer/heapless/jobs/416256820

The error seems to be in the static initialization.
Sadly I currently have no idea how to fix this.
Any suggestions are welcome.

EDIT:
This issue has already been filed in rust.
rust-lang/rust#53325
A solution could be explicit type annotaion in all union assingments.
The main problem seems to be in the __core::mem::uninitialized, which is just const a substitute for core::mem::uninitialized and uses an uninitialized union to create uninitialized memory. The function is used in vec::Vec::new() which the other data structures base on.
A possible work around would be to to initialize the memory, which is clearely not needed.
But uninitialized memory is unsafe as heck anyway, so I see why the compiler might complain about this union initialization.

Verified working nightly version, which does not have this problem: nightly-2018-07-13, rustc 1.29.0-nightly (64f7de921 2018-07-12)

Build log:

+'[' nightly = nightly ']'
+cargo test --target x86_64-unknown-linux-gnu
   Compiling heapless v0.3.6 (file:///home/travis/build/XOSplicer/heapless)
error[E0080]: this static likely exhibits undefined behavior
   --> src/linear_map.rs:456:9
    |
456 |         static mut _L: LinearMap<i32, i32, U8>= LinearMap::new();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered undefined bytes at .buffer.buffer.value.data.parent1.parent1.parent1.data.0
    |
    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error[E0080]: this static likely exhibits undefined behavior
   --> src/string.rs:530:9
    |
530 |         static mut _S: String<U8> = String::new();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered undefined bytes at .vec.buffer.value.data.parent1.parent1.parent1.data
    |
    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error[E0080]: this static likely exhibits undefined behavior
   --> src/vec.rs:520:9
    |
520 |         static mut _V: Vec<i32, U4> = Vec::new();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered undefined bytes at .buffer.value.data.parent1.parent1.data
    |
    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error[E0080]: this static likely exhibits undefined behavior
   --> src/binary_heap.rs:439:9
    |
439 |         static mut _B: BinaryHeap<i32, U16, Min> = BinaryHeap::new();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered undefined bytes at .data.buffer.value.data.parent1.parent1.parent1.parent1.data
    m|
    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error[E0080]: this static likely exhibits undefined behavior
   --> src/ring_buffer/mod.rs:512:9
    |
512 |         static mut _R: RingBuffer<i32, U4> = RingBuffer::new();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered undefined bytes at .buffer.value.data.parent1.parent1.data
    |
    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error[E0080]: this static likely exhibits undefined behavior
  --> src/__core.rs:30:9
   |
30 |         static mut I: i32 = unsafe { __core::mem::uninitialized() };
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered undefined bytes
   |
   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0080`.
error: Could not compile `heapless`.

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

Successfully merging this pull request may close these issues.

2 participants