aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-rt/examples
diff options
context:
space:
mode:
authorGravatar bors[bot] <bors[bot]@users.noreply.github.com> 2018-12-15 16:14:06 +0000
committerGravatar bors[bot] <bors[bot]@users.noreply.github.com> 2018-12-15 16:14:06 +0000
commit0cabf09a7ac11962b57a75e52a6cc0c5aa2709a8 (patch)
tree8565f0edc28016ea1acc1f14dd63591d21c3fe32 /cortex-m-rt/examples
parentc7e6e5f78203b55b0094bd26d78e17c9c9d155a2 (diff)
parentc69ff66f4c1d353be5d683ca8c131a04e997e4ed (diff)
downloadcortex-m-0cabf09a7ac11962b57a75e52a6cc0c5aa2709a8.tar.gz
cortex-m-0cabf09a7ac11962b57a75e52a6cc0c5aa2709a8.tar.zst
cortex-m-0cabf09a7ac11962b57a75e52a6cc0c5aa2709a8.zip
Merge #159
159: static mut transform: forward `#[cfg]` r=therealprof a=japaric as reported in japaric/cortex-m-rtfm#110 the following code fails to compile ``` rust #[entry] fn main() -> ! { #[cfg(something)] static mut FOO: u32 = 0; //~ ERROR cannot find value `FOO` in this scope } ``` the issue is that the expansion of the static looks like this: ``` rust let FOO = unsafe { #[cfg(never)] static mut FOO: u32 = 0; &mut FOO }; ``` so when the `#[cfg]` evals to false the static is gone but the `let FOO` is not removed. this PR forwards `#[cfg]` attributes to the `let` expression and fixes the error ``` rust #[cfg(never)] // <- added let FOO = unsafe { #[cfg(never)] static mut FOO: u32 = 0; &mut FOO }; ``` Co-authored-by: Jorge Aparicio <jorge@japaric.io>
Diffstat (limited to 'cortex-m-rt/examples')
-rw-r--r--cortex-m-rt/examples/cfg-static.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/cortex-m-rt/examples/cfg-static.rs b/cortex-m-rt/examples/cfg-static.rs
new file mode 100644
index 0000000..2ffee13
--- /dev/null
+++ b/cortex-m-rt/examples/cfg-static.rs
@@ -0,0 +1,25 @@
+//! using `#[cfg]` on `static` shouldn't cause compile errors
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt as rt;
+extern crate panic_halt;
+
+use rt::{entry, exception};
+
+#[entry]
+fn main() -> ! {
+ #[cfg(never)]
+ static mut COUNT: u32 = 0;
+
+ loop {}
+}
+
+#[exception]
+fn SysTick() {
+ #[cfg(never)]
+ static mut FOO: u32 = 0;
+}