diff options
author | 2018-11-04 01:08:52 +0100 | |
---|---|---|
committer | 2018-11-04 01:08:52 +0100 | |
commit | b6facc16d893c2e886401cb0743bb29700388293 (patch) | |
tree | 177290bf54b326717157b43568006a42b16387d7 /cortex-m-rt/tests/compile-fail/duplicate-static.rs | |
parent | 2f890d87b1945f1f901355b94375d2531fa71f7c (diff) | |
download | cortex-m-b6facc16d893c2e886401cb0743bb29700388293.tar.gz cortex-m-b6facc16d893c2e886401cb0743bb29700388293.tar.zst cortex-m-b6facc16d893c2e886401cb0743bb29700388293.zip |
reject duplicate `static mut` variables
after #140 landed the entry, exception and interrupt attributes started
accepting code like this:
``` rust
#[entry]
fn main() -> ! {
static mut FOO: u32 = 0;
static mut FOO: i32 = 0;
}
```
because that code expands into:
``` rust
fn main() -> ! {
let FOO: &'static mut u32 = unsafe {
static mut FOO: u32 = 0;
&mut FOO
};
// shadows previous variable
let FOO: &'static mut u32 = unsafe {
static mut FOO: i32 = 0;
&mut FOO
};
}
```
this commit adds a check that rejects `static mut`s with duplicated names to
these three attributes.
Diffstat (limited to 'cortex-m-rt/tests/compile-fail/duplicate-static.rs')
-rw-r--r-- | cortex-m-rt/tests/compile-fail/duplicate-static.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/cortex-m-rt/tests/compile-fail/duplicate-static.rs b/cortex-m-rt/tests/compile-fail/duplicate-static.rs new file mode 100644 index 0000000..fccb65f --- /dev/null +++ b/cortex-m-rt/tests/compile-fail/duplicate-static.rs @@ -0,0 +1,31 @@ +#![no_main] +#![no_std] + +extern crate cortex_m_rt; +extern crate panic_halt; + +use cortex_m_rt::{entry, exception, interrupt}; + +enum interrupt { + UART0, +} + +#[entry] +fn foo() -> ! { + static mut X: u32 = 0; + static mut X: i32 = 0; //~ ERROR the name `X` is defined multiple times + + loop {} +} + +#[exception] +fn SVCall() { + static mut X: u32 = 0; + static mut X: i32 = 0; //~ ERROR the name `X` is defined multiple times +} + +#[interrupt] +fn UART0() { + static mut X: u32 = 0; + static mut X: i32 = 0; //~ ERROR the name `X` is defined multiple times +} |