-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
149: reject duplicate `static mut` variables r=therealprof a=japaric 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. Co-authored-by: Jorge Aparicio <[email protected]>
- Loading branch information
Showing
2 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |