aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-rt/tests/compile-fail/non-static-resource.rs
blob: a6037283300a59d2c8c0589a838b36dfe21ed3b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! Tests that no `&'static mut` to static mutable resources can be obtained, which would be
//! unsound.
//!
//! Regression test for https://github.com/rust-embedded/cortex-m-rt/issues/212

#![no_std]
#![no_main]

extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m_rt::{entry, exception, interrupt, ExceptionFrame};

#[allow(non_camel_case_types)]
enum interrupt {
    UART0,
}

#[exception]
fn SVCall() {
    static mut STAT: u8 = 0;

    let _stat: &'static mut u8 = STAT;
    //~^ ERROR lifetime of reference outlives lifetime of borrowed content
}

#[interrupt]
fn UART0() {
    static mut STAT: u8 = 0;

    let _stat: &'static mut u8 = STAT;
    //~^ ERROR lifetime of reference outlives lifetime of borrowed content
}

#[entry]
fn you_died_of_dis_entry() -> ! {
    static mut STAT: u8 = 0;

    // Allowed. This is sound for the entry point since it is only ever called once, and it makes
    // resources far more useful.
    let _stat: &'static mut u8 = STAT;

    loop {}
}