Browse Source

Hide "platform-intrinsic" from stable Rust

The Rust compiler validates the extern ABI while parsing the "extern"
keyword, so normal conditional compilation (`#[cfg(...)]`) isn't enough
to hide the ABI from Rust versions which don't know it.

I tried hiding the extern ABI using a macro, but the contents of an
"extern" block aren't a valid `item`, and I couldn't find any other
working way to pass the function declarations to the macro.

The solution which worked in the end was to use `include!`. This
prevents the compiler from even trying to parse the "extern" block
unless the nightly-only cargo feature "simd" is enabled.
pull/2/head
Cesar Eduardo Barros 9 years ago
parent
commit
4dbacf33dd
  1. 5
      src/lib.rs
  2. 2
      src/simdint.rs

5
src/lib.rs

@ -39,7 +39,10 @@ mod as_bytes;
mod bytes;
mod simdty;
#[cfg(feature = "simd")] mod simdint;
#[allow(dead_code)] mod simdint {
#[cfg(feature = "simd")]
include!("simdint.rs");
}
mod simd;
#[macro_use]

2
src/simdint.rs

@ -24,8 +24,6 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#![allow(dead_code)]
use simdty;
extern "platform-intrinsic" {

Loading…
Cancel
Save