Commit 0cabf09
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>2 files changed
+60
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
138 | 139 | | |
139 | 140 | | |
| 141 | + | |
140 | 142 | | |
141 | 143 | | |
142 | 144 | | |
| |||
405 | 407 | | |
406 | 408 | | |
407 | 409 | | |
408 | | - | |
409 | 410 | | |
410 | 411 | | |
411 | 412 | | |
| |||
446 | 447 | | |
447 | 448 | | |
448 | 449 | | |
449 | | - | |
| 450 | + | |
450 | 451 | | |
451 | 452 | | |
452 | 453 | | |
453 | 454 | | |
454 | 455 | | |
455 | 456 | | |
| 457 | + | |
456 | 458 | | |
457 | 459 | | |
| 460 | + | |
458 | 461 | | |
459 | 462 | | |
460 | 463 | | |
| |||
603 | 606 | | |
604 | 607 | | |
605 | 608 | | |
606 | | - | |
| 609 | + | |
607 | 610 | | |
608 | 611 | | |
609 | 612 | | |
610 | 613 | | |
611 | 614 | | |
612 | 615 | | |
| 616 | + | |
613 | 617 | | |
614 | 618 | | |
| 619 | + | |
615 | 620 | | |
616 | 621 | | |
617 | 622 | | |
| |||
776 | 781 | | |
777 | 782 | | |
778 | 783 | | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
0 commit comments