Skip to content

Commit 9c362a6

Browse files
bors[bot]japaric
andcommitted
Merge #3
3: add an opt-out "const-fn" Cargo feature r=japaric a=japaric with the feature disabled this crate compiles on stable Co-authored-by: Jorge Aparicio <[email protected]>
2 parents e462b6a + 7cf4e9a commit 9c362a6

File tree

6 files changed

+89
-4
lines changed

6 files changed

+89
-4
lines changed

.travis.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
language: rust
2+
3+
matrix:
4+
include:
5+
- env: TARGET=x86_64-unknown-linux-gnu
6+
# - env: TARGET=thumbv6m-none-eabi
7+
# - env: TARGET=thumbv7m-none-eabi
8+
- env: TARGET=thumbv6m-none-eabi
9+
rust: nightly
10+
- env: TARGET=thumbv7m-none-eabi
11+
rust: nightly
12+
13+
before_install: set -e
14+
15+
install:
16+
- bash ci/install.sh
17+
18+
script:
19+
- bash ci/script.sh
20+
21+
after_script: set +e
22+
23+
cache: cargo
24+
25+
before_cache:
26+
# Travis can't cache files that are not readable by "others"
27+
- chmod -R a+r $HOME/.cargo
28+
29+
branches:
30+
only:
31+
- staging
32+
- trying
33+
34+
notifications:
35+
email:
36+
on_success: never

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ name = "bare-metal"
99
repository = "https://github.com/japaric/bare-metal"
1010
version = "0.1.1"
1111

12-
[dependencies]
12+
[features]
13+
default = ["const-fn"]
14+
const-fn = []

bors.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
status = [
2+
"continuous-integration/travis-ci/push",
3+
]

ci/install.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set -euxo pipefail
2+
3+
main() {
4+
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
5+
rustup target add $TARGET
6+
fi
7+
}
8+
9+
main

ci/script.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set -euxo pipefail
2+
3+
main() {
4+
cargo check --target $TARGET --no-default-features
5+
6+
if [ $TRAVIS_RUST_VERSION = nightly ]; then
7+
cargo check --target $TARGET
8+
fi
9+
}
10+
11+
main

src/lib.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#![deny(missing_docs)]
44
#![deny(warnings)]
5-
#![feature(const_fn,const_unsafe_cell_new)]
5+
#![cfg_attr(feature = "const-fn", feature(const_fn, const_unsafe_cell_new))]
66
#![no_std]
77

88
use core::cell::UnsafeCell;
@@ -20,8 +20,21 @@ impl<T> Peripheral<T> {
2020
/// Creates a new peripheral
2121
///
2222
/// `address` is the base address of the register block
23+
#[cfg(feature = "const-fn")]
2324
pub const unsafe fn new(address: usize) -> Self {
24-
Peripheral { address: address as *mut T }
25+
Peripheral {
26+
address: address as *mut T,
27+
}
28+
}
29+
30+
/// Creates a new peripheral
31+
///
32+
/// `address` is the base address of the register block
33+
#[cfg(not(feature = "const-fn"))]
34+
pub unsafe fn new(address: usize) -> Self {
35+
Peripheral {
36+
address: address as *mut T,
37+
}
2538
}
2639

2740
/// Borrows the peripheral for the duration of a critical section
@@ -59,8 +72,19 @@ pub struct Mutex<T> {
5972

6073
impl<T> Mutex<T> {
6174
/// Creates a new mutex
75+
#[cfg(feature = "const-fn")]
6276
pub const fn new(value: T) -> Self {
63-
Mutex { inner: UnsafeCell::new(value) }
77+
Mutex {
78+
inner: UnsafeCell::new(value),
79+
}
80+
}
81+
82+
/// Creates a new mutex
83+
#[cfg(not(feature = "const-fn"))]
84+
pub fn new(value: T) -> Self {
85+
Mutex {
86+
inner: UnsafeCell::new(value),
87+
}
6488
}
6589
}
6690

0 commit comments

Comments
 (0)