Skip to content

Commit cfd08cd

Browse files
bors[bot]japaric
andcommitted
Merge #9
9: borrows should not outlive the Mutex r=japaric a=japaric closes #6 Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 39e2201 + 45a8a56 commit cfd08cd

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

ci/script.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ main() {
66
if [ $TRAVIS_RUST_VERSION = nightly ]; then
77
cargo check --target $TARGET --features const-fn
88
fi
9+
10+
if [ $TARGET = x86_64-unknown-linux-gnu ]; then
11+
cargo test
12+
fi
913
}
1014

1115
main

src/lib.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
33
#![deny(missing_docs)]
44
#![deny(warnings)]
5-
#![cfg_attr(feature = "const-fn", feature(const_fn, const_unsafe_cell_new))]
5+
#![cfg_attr(
6+
feature = "const-fn",
7+
feature(const_fn, const_unsafe_cell_new)
8+
)]
69
#![no_std]
710

811
use core::cell::UnsafeCell;
@@ -90,11 +93,20 @@ impl<T> Mutex<T> {
9093

9194
impl<T> Mutex<T> {
9295
/// Borrows the data for the duration of the critical section
93-
pub fn borrow<'cs>(&self, _cs: &'cs CriticalSection) -> &'cs T {
96+
pub fn borrow<'cs>(&'cs self, _cs: &'cs CriticalSection) -> &'cs T {
9497
unsafe { &*self.inner.get() }
9598
}
9699
}
97100

101+
/// ``` compile_fail
102+
/// fn bad(cs: &bare_metal::CriticalSection) -> &u32 {
103+
/// let x = bare_metal::Mutex::new(42u32);
104+
/// x.borrow(cs)
105+
/// }
106+
/// ```
107+
#[allow(dead_code)]
108+
const GH_6: () = ();
109+
98110
/// Interrupt number
99111
pub unsafe trait Nr {
100112
/// Returns the number associated with an interrupt
@@ -104,8 +116,4 @@ pub unsafe trait Nr {
104116
// NOTE A `Mutex` can be used as a channel so the protected data must be `Send`
105117
// to prevent sending non-Sendable stuff (e.g. access tokens) across different
106118
// execution contexts (e.g. interrupts)
107-
unsafe impl<T> Sync for Mutex<T>
108-
where
109-
T: Send,
110-
{
111-
}
119+
unsafe impl<T> Sync for Mutex<T> where T: Send {}

0 commit comments

Comments
 (0)