This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
2 changed files
with
60 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
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