Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed CPU target specifications because their feature mappings could not be kept consistent as rustc's feature database changed.
### Fixed
- Disabling the `std` feature now makes the crate `no_std`.
- Fixed handling of `'static` and `'_` lifetimes in multiversioned function signatures.

## [0.8.0] - 2024-12-07
### Changed
Expand Down
3 changes: 3 additions & 0 deletions multiversion-macros/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ struct LifetimeRenamer;

impl VisitMut for LifetimeRenamer {
fn visit_lifetime_mut(&mut self, i: &mut Lifetime) {
if i.ident == "static" || i.ident == "_" {
return;
}
i.ident = Ident::new(&format!("__mv_inner_{}", i.ident), i.ident.span());
}
}
Expand Down
54 changes: 36 additions & 18 deletions multiversion/tests/generics.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
#![cfg_attr(
all(feature = "nightly", target_arch = "arm"),
feature(arm_target_feature, stdarch_arm_feature_detection)
)]
#![cfg_attr(
all(feature = "nightly", any(target_arch = "mips", target_arch = "mips64")),
feature(mips_target_feature, stdarch_mips_feature_detection)
)]
#![cfg_attr(
all(
feature = "nightly",
any(target_arch = "powerpc", target_arch = "powerpc64")
),
feature(powerpc_target_feature, stdarch_powerpc_feature_detection)
)]
#![cfg_attr(
all(
feature = "nightly",
any(target_arch = "riscv32", target_arch = "riscv64")
),
feature(riscv_target_feature, stdarch_riscv_feature_detection)
)]
#![allow(clippy::needless_lifetimes)]

#[rustversion::since(1.51)]
#[multiversion::multiversion(targets(
"x86_64+avx2+avx",
"x86_64+avx",
"x86+avx2+avx",
"x86+avx",
"x86+sse"
))]
#[multiversion::multiversion(targets = "simd")]
fn pass<'a>(x: &'a i32) -> &'a i32 {
x
}

#[rustversion::since(1.51)]
#[multiversion::multiversion(targets(
"x86_64+avx2+avx",
"x86_64+avx",
"x86+avx2+avx",
"x86+avx",
"x86+sse"
))]
#[multiversion::multiversion(targets = "simd")]
fn static_lifetime() -> &'static [u8] {
"hello".as_bytes()
}

#[multiversion::multiversion(targets = "simd")]
fn placeholder_lifetime(value: &'_ [u8]) -> usize {
value.len()
}

#[multiversion::multiversion(targets = "simd")]
fn double<'a, T: Copy + std::ops::AddAssign, const N: usize>(x: &'a mut [T; N]) -> &'a mut T {
assert!(!x.is_empty());
for v in x.iter_mut() {
Expand All @@ -29,7 +47,6 @@ fn double<'a, T: Copy + std::ops::AddAssign, const N: usize>(x: &'a mut [T; N])
}

mod test {
#[rustversion::since(1.51)]
#[test]
fn generics() {
let mut x = [0u32, 2u32, 4u32];
Expand All @@ -40,10 +57,11 @@ mod test {
assert_eq!(y, [2u64, 4u64, 8u64]);
}

#[rustversion::since(1.51)]
#[test]
fn lifetimes() {
let a = 42;
assert_eq!(super::pass(&a), &a);
assert_eq!(super::static_lifetime(), b"hello");
assert_eq!(super::placeholder_lifetime(b"hello"), 5);
}
}