Skip to content

Commit ca90122

Browse files
committed
test(portkit): check the uniqueness of sym_static instances
1 parent dc55bd4 commit ca90122

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/r3_portkit/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
#![feature(const_fn_trait_bound)]
44
#![feature(generic_const_exprs)]
55
#![feature(adt_const_params)]
6+
#![feature(naked_functions)]
67
#![feature(core_panic)]
78
#![feature(decl_macro)]
9+
#![feature(asm_const)]
10+
#![feature(asm_sym)]
811
#![cfg_attr(
912
feature = "doc",
1013
doc(html_logo_url = "https://r3-os.github.io/r3/logo-small.svg")

src/r3_portkit/src/sym.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,28 @@ pub macro sym_static {
272272
}
273273
},
274274
}
275+
276+
#[cfg(test)]
277+
mod tests {
278+
use super::*;
279+
extern crate std;
280+
use std::{dbg, prelude::rust_2021::*};
281+
282+
trait Tr {
283+
sym_static!(static VAR: SymStatic<u32> = zeroed!());
284+
}
285+
286+
impl Tr for &'static u8 {}
287+
impl Tr for &'static u16 {}
288+
impl Tr for &'static u32 {}
289+
290+
#[test]
291+
fn uniqueness() {
292+
let var1 = dbg!(sym_static(<&'static u8>::VAR).as_ptr());
293+
let var2 = dbg!(sym_static(<&'static u16>::VAR).as_ptr());
294+
let var3 = dbg!(sym_static(<&'static u32>::VAR).as_ptr());
295+
assert_ne!(var1, var2);
296+
assert_ne!(var2, var3);
297+
assert_ne!(var1, var3);
298+
}
299+
}

0 commit comments

Comments
 (0)