From b6facc16d893c2e886401cb0743bb29700388293 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 4 Nov 2018 01:08:52 +0100 Subject: 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. --- cortex-m-rt/tests/compile-fail/duplicate-static.rs | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 cortex-m-rt/tests/compile-fail/duplicate-static.rs (limited to 'cortex-m-rt/tests/compile-fail/duplicate-static.rs') 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 +} -- cgit v1.2.3 From 1f08b692ab1ba37a09cbcdd73469225db5d67aad Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 22 Jan 2019 09:54:45 +0100 Subject: update cfail tests to make them pass with latest nightly --- cortex-m-rt/tests/compile-fail/duplicate-static.rs | 1 + cortex-m-rt/tests/compile-fail/interrupt-args.rs | 1 + cortex-m-rt/tests/compile-fail/interrupt-bad-signature-1.rs | 1 + cortex-m-rt/tests/compile-fail/interrupt-bad-signature-2.rs | 1 + cortex-m-rt/tests/compile-fail/interrupt-invalid.rs | 5 +++-- cortex-m-rt/tests/compile-fail/interrupt-soundness.rs | 1 + 6 files changed, 8 insertions(+), 2 deletions(-) (limited to 'cortex-m-rt/tests/compile-fail/duplicate-static.rs') diff --git a/cortex-m-rt/tests/compile-fail/duplicate-static.rs b/cortex-m-rt/tests/compile-fail/duplicate-static.rs index fccb65f..eeb884f 100644 --- a/cortex-m-rt/tests/compile-fail/duplicate-static.rs +++ b/cortex-m-rt/tests/compile-fail/duplicate-static.rs @@ -6,6 +6,7 @@ extern crate panic_halt; use cortex_m_rt::{entry, exception, interrupt}; +#[allow(non_camel_case_types)] enum interrupt { UART0, } diff --git a/cortex-m-rt/tests/compile-fail/interrupt-args.rs b/cortex-m-rt/tests/compile-fail/interrupt-args.rs index 9630ce1..1e06ec2 100644 --- a/cortex-m-rt/tests/compile-fail/interrupt-args.rs +++ b/cortex-m-rt/tests/compile-fail/interrupt-args.rs @@ -11,6 +11,7 @@ fn foo() -> ! { loop {} } +#[allow(non_camel_case_types)] enum interrupt { USART1, } diff --git a/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-1.rs index c7e25b3..bd5ff9f 100644 --- a/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-1.rs @@ -11,6 +11,7 @@ fn foo() -> ! { loop {} } +#[allow(non_camel_case_types)] enum interrupt { USART1, } diff --git a/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-2.rs index ed5cbd4..56db222 100644 --- a/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-2.rs @@ -11,6 +11,7 @@ fn foo() -> ! { loop {} } +#[allow(non_camel_case_types)] enum interrupt { USART1, } diff --git a/cortex-m-rt/tests/compile-fail/interrupt-invalid.rs b/cortex-m-rt/tests/compile-fail/interrupt-invalid.rs index 4e79e7d..9b1482a 100644 --- a/cortex-m-rt/tests/compile-fail/interrupt-invalid.rs +++ b/cortex-m-rt/tests/compile-fail/interrupt-invalid.rs @@ -11,11 +11,12 @@ fn foo() -> ! { loop {} } +#[allow(non_camel_case_types)] enum interrupt { USART1, } // NOTE this looks a bit better when using a device crate: // "no variant named `foo` found for type `stm32f30x::Interrupt` in the current scope" -#[interrupt] //~ ERROR no variant named `foo` found for type `interrupt` in the current scope -fn foo() {} +#[interrupt] +fn foo() {} //~ ERROR no variant named `foo` found for type `interrupt` in the current scope diff --git a/cortex-m-rt/tests/compile-fail/interrupt-soundness.rs b/cortex-m-rt/tests/compile-fail/interrupt-soundness.rs index b473a94..74e5e79 100644 --- a/cortex-m-rt/tests/compile-fail/interrupt-soundness.rs +++ b/cortex-m-rt/tests/compile-fail/interrupt-soundness.rs @@ -11,6 +11,7 @@ fn foo() -> ! { loop {} } +#[allow(non_camel_case_types)] enum interrupt { USART1, USART2, -- cgit v1.2.3