Macros like cfg_if don't seem to be expanding, even with macro expansion option enabled.
It's most noticeable in std::os and crates like libc or other FFI crates that make heavy use of cfg_if and similar macros.
Fixed with #2664. Note that now we just expand
cfg_if! {
if #[cfg(unix)] {
fn foo() { /* unix specific functionality */ }
} else if #[cfg(target_pointer_width = "32")] {
fn foo() { /* non-unix, 32-bit functionality */ }
} else {
fn foo() { /* fallback implementation */ }
}
}
to something like this:
#[cfg(all(unix, not(any())))]
fn foo() { /* unix specific functionality */ }
#[cfg(all(target_pointer_width = "32", not(any(unix))))]
fn foo() { /* non-unix, 32-bit functionality */ }
#[cfg(all( not(any(unix,target_pointer_width = "32"))))]
fn foo() { /* fallback implementation */ }
Then we need to finish and land #2166 to make cfg_if! work as expected
@vlad20012 after fixing #2664 it seems there is still seems to be a problem related to cfg_if! expansion remaining.
This affects for example libc::c_char.
Macros in modules which were declared inside the cfg_if! do not resolve.
For example in libc-0.2.40/src/unix/mod.rs contains cfg_if! macro invocations which are not expanded.
And on linux c_char seems to be defined in libc-0.2.40/src/unix/notbsd/linux/other/b64/x86_64.rs
Which is several layery of cfg_if! deep...
My guess is that this is related to RsModulesIndex not containing the mod
This might be because there is no stub for the mod.
During macro expansion inside the nested file we cannot find the module parent and thus cannot find the macro declaration.
In files affected by this, also Ctrl+U fails which also uses RsModulesIndex.
Not sure if this should be made into a separate issue or solved with this one.
Hmm, we totally can't index macro expansions. I spent a lot of time to analyze the problem and find possible solutions (but in the case of impls, produced by macros). And the only solution is to write new indexes from a scratch. And I going to do it soon.
Most helpful comment
Fixed with #2664. Note that now we just expand
to something like this:
Then we need to finish and land #2166 to make
cfg_if!work as expected