multiversion icon indicating copy to clipboard operation
multiversion copied to clipboard

Multiversion has unexpected token using inline const expression with missing semi-colon

Open sammysheep opened this issue 1 year ago • 0 comments

With the inline const expression feature introduced in 1.79, I noticed that omitting a semi-colon after the const {} block interacts poorly with multiversion v0.7.4. On nightly, Rust will happily compile the version without the semi-colon--albeit this could be considered badly written Rust--so it caught me off guard when my const { assert!() } + mulltiversion made the function vanish.

Minimal error

use multiversion::multiversion;

// Unexpected token
#[multiversion(targets = "simd")]
pub fn x() -> u32 {
    const {
        2;
    }
    0
}

// Cannot find function `x` in this scope
pub fn y() -> u32 {
    x() + 1
}

// Compiles
pub fn x_again() -> u32 {
    const {
        2;
    }
    0
}

// Compiles
#[multiversion(targets = "simd")]
pub fn x_one_more_time() -> u32 {
    const {
        2;
    };
    0
}

// Compiles
#[multiversion(targets = "simd")]
pub fn abc() -> u32 {
    0
}

// Compiles
pub fn def() -> u32 {
    abc() + 1
}

Systems tested

  • rustc 1.83.0-nightly (6c6d21008 2024-09-22), M2 Ultra
  • rustc 1.83.0-nightly (28e8f01c2 2024-09-17), Intel Xeon

sammysheep avatar Sep 23 '24 13:09 sammysheep