diff --git a/Cargo.toml b/Cargo.toml index c4b6892..8885abf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,8 @@ description = "Compile-time assertions to ensure that invariants are met." [badges] travis-ci = { repository = "nvzqz/static-assertions-rs" } + +[features] +# For testing +const_fn = [] +nightly = ["const_fn"] diff --git a/tests/const.rs b/tests/const.rs index ceb8045..845dfb6 100644 --- a/tests/const.rs +++ b/tests/const.rs @@ -1,5 +1,7 @@ #![no_std] +#![cfg_attr(feature = "const_fn", feature(const_fn))] + #[macro_use] extern crate static_assertions; @@ -10,3 +12,29 @@ fn const_assert() { const_assert!(FIVE * 2 == 10); const_assert!(FIVE > 2); } + +#[cfg(feature = "const_fn")] +#[test] +fn const_fn() { + const VALUE: usize = 4; + + const fn value() -> usize { + VALUE + } + + const_assert!(value() == VALUE); +} + +#[cfg(feature = "nightly")] +#[test] +fn assoc_const() { + const FOUR: usize = 4; + trait Assoc { const VAL: usize; } + struct Concrete; + + impl Assoc for Concrete { + const VAL: usize = FOUR; + } + + const_assert!(Concrete::VAL == FOUR); +}