Skip to content

Failed to properly expand third-party macros #20309

@filips123

Description

@filips123

It appears that Rust Analyzer fails to completely expand some macros from third-party crates.

Trying to expand src/components/runtime.rs:145:23 in VSCode with "rust-analyzer: Expand macro recursively at caret" produces the following file:

// Recursive expansion of cfg_if! macro
// =====================================

#[cfg(all(all(platform_windows,target_arch = "x86"),not(any())))]
const_format::pmr::__AssertStr {
    x:{
        use const_format::__cf_osRcTFl4A;
        const_format::pmr::__concatcp_impl!{
            (BASE_DOWNLOAD_URL),("win"),
        }
    }
}.x #[cfg(all(all(platform_windows,target_arch = "x86_64"),not(any(all(platform_windows,target_arch = "x86")))))]
const_format::pmr::__AssertStr {
    x:{
        use const_format::__cf_osRcTFl4A;
        const_format::pmr::__concatcp_impl!{
            (BASE_DOWNLOAD_URL),("win64"),
        }
    }
}.x #[cfg(all(all(platform_windows,target_arch = "aarch64"),not(any(all(platform_windows,target_arch = "x86"),all(platform_windows,target_arch = "x86_64")))))]
const_format::pmr::__AssertStr {
    x:{
        use const_format::__cf_osRcTFl4A;
        const_format::pmr::__concatcp_impl!{
            (BASE_DOWNLOAD_URL),("win64-aarch64"),
        }
    }
}.x #[cfg(all(all(platform_linux,target_arch = "x86"),not(any(all(platform_windows,target_arch = "x86"),all(platform_windows,target_arch = "x86_64"),all(platform_windows,target_arch = "aarch64")))))]
const_format::pmr::__AssertStr {
    x:{
        use const_format::__cf_osRcTFl4A;
        const_format::pmr::__concatcp_impl!{
            (BASE_DOWNLOAD_URL),("linux"),
        }
    }
}.x #[cfg(all(all(platform_linux,target_arch = "x86_64"),not(any(all(platform_windows,target_arch = "x86"),all(platform_windows,target_arch = "x86_64"),all(platform_windows,target_arch = "aarch64"),all(platform_linux,target_arch = "x86")))))]
const_format::pmr::__AssertStr {
    x:{
        use const_format::__cf_osRcTFl4A;
        ({
            #[doc(hidden)]
            #[allow(unused_mut,non_snake_case)]
            const CONCATP_NHPMWYD3NJA: &[__cf_osRcTFl4A::pmr::PArgument] = {
                let fmt = __cf_osRcTFl4A::pmr::FormattingFlags::NEW;
                &[__cf_osRcTFl4A::pmr::PConvWrapper(BASE_DOWNLOAD_URL).to_pargument_display(fmt),__cf_osRcTFl4A::pmr::PConvWrapper("linux64").to_pargument_display(fmt)]
            };
            {
                #[doc(hidden)]
                const ARR_LEN:usize = const_format::pmr::PArgument::calc_len(CONCATP_NHPMWYD3NJA);
                #[doc(hidden)]
                const CONCAT_ARR: &const_format::pmr::LenAndArray<[u8;
                ARR_LEN]>  =  &const_format::pmr::__priv_concatenate(CONCATP_NHPMWYD3NJA);
                #[doc(hidden)]
                #[allow(clippy::transmute_ptr_to_ptr)]
                const CONCAT_STR: &str = unsafe {
                    let slice = const_format::pmr::transmute::<&[u8;
                    ARR_LEN], &[u8;
                    CONCAT_ARR.len]>(&CONCAT_ARR.array);
                    {
                        let bytes: &'static[const_format::pmr::u8] = slice;
                        let string: &'static const_format::pmr::str = {
                            const_format::__hidden_utils::PtrToRef {
                                ptr:bytes as *const [const_format::pmr::u8]as *const str,
                            }.reff
                        };
                        string
                    }
                };
                CONCAT_STR
            }
        })
    }
}.x #[cfg(all(all(platform_linux,target_arch = "aarch64"),not(any(all(platform_windows,target_arch = "x86"),all(platform_windows,target_arch = "x86_64"),all(platform_windows,target_arch = "aarch64"),all(platform_linux,target_arch = "x86"),all(platform_linux,target_arch = "x86_64")))))]
const_format::pmr::__AssertStr {
    x:{
        use const_format::__cf_osRcTFl4A;
        const_format::pmr::__concatcp_impl!{
            (BASE_DOWNLOAD_URL),("linux64-aarch64"),
        }
    }
}.x #[cfg(all(platform_macos,not(any(all(platform_windows,target_arch = "x86"),all(platform_windows,target_arch = "x86_64"),all(platform_windows,target_arch = "aarch64"),all(platform_linux,target_arch = "x86"),all(platform_linux,target_arch = "x86_64"),all(platform_linux,target_arch = "aarch64")))))]
const_format::pmr::__AssertStr {
    x:{
        use const_format::__cf_osRcTFl4A;
        const_format::pmr::__concatcp_impl!{
            (BASE_DOWNLOAD_URL),("osx"),
        }
    }
}.x #[cfg(all(not(any(all(platform_windows,target_arch = "x86"),all(platform_windows,target_arch = "x86_64"),all(platform_windows,target_arch = "aarch64"),all(platform_linux,target_arch = "x86"),all(platform_linux,target_arch = "x86_64"),all(platform_linux,target_arch = "aarch64"),platform_macos))))]
{
    #[cold]
    #[track_caller]
    #[inline(never)]
    #[rustc_const_panic_str]
    #[rustc_do_not_const_check]
    const fn panic_cold_display<T:core::fmt::Display>(arg: &T) ->  !{
        core::panicking::panic_display(arg)
    }
    panic_cold_display(&UNSUPPORTED_PLATFORM_ERROR);
};

There is still const_format::pmr::__concatcp_impl! in the expanded code, so seems it wasn't fully expanded.

Similarly, expanding build.rs:26:29 creates the following output:

// Recursive expansion of cfg_aliases! macro
// ==========================================

macro_rules! __cfg_aliases_matcher__ {
    (platform_windows) => {
        cfg_aliases::cfg_aliases!(@parser target_os = "windows")
    };
    (platform_linux) => {
        cfg_aliases::cfg_aliases!(@parser target_os = "linux")
    };
    (platform_macos) => {
        cfg_aliases::cfg_aliases!(@parser target_os = "macos")
    };
    (platform_bsd) => {
        cfg_aliases::cfg_aliases!(@parser any(target_os = "dragonfly",target_os = "freebsd",target_os = "openbsd",target_os = "netbsd"))
    };
    ($e:ident) => {
        cfg_aliases::cfg_aliases!(@cfg_is_set$e)
    };
}
{
    std::io::_print(std::format_args_nl!("cargo:rustc-check-cfg=cfg({})",stringify!(platform_windows)));
};
if std::env::var(alloc::__export::must_use({
    alloc::fmt::format(alloc::__export::format_args!("CARGO_CFG_{}", &stringify!(target_os).to_uppercase().replace("-","_")))
})).unwrap_or("".to_owned()).split(",").find(|x|x== &"windows").is_some(){
    {
        std::io::_print(std::format_args_nl!("cargo:rustc-cfg={}",stringify!(platform_windows)));
    };
}{
    std::io::_print(std::format_args_nl!("cargo:rustc-check-cfg=cfg({})",stringify!(platform_linux)));
};
if std::env::var(alloc::__export::must_use({
    alloc::fmt::format(alloc::__export::format_args!("CARGO_CFG_{}", &stringify!(target_os).to_uppercase().replace("-","_")))
})).unwrap_or("".to_owned()).split(",").find(|x|x== &"linux").is_some(){
    {
        std::io::_print(std::format_args_nl!("cargo:rustc-cfg={}",stringify!(platform_linux)));
    };
}{
    std::io::_print(std::format_args_nl!("cargo:rustc-check-cfg=cfg({})",stringify!(platform_macos)));
};
if std::env::var(alloc::__export::must_use({
    alloc::fmt::format(alloc::__export::format_args!("CARGO_CFG_{}", &stringify!(target_os).to_uppercase().replace("-","_")))
})).unwrap_or("".to_owned()).split(",").find(|x|x== &"macos").is_some(){
    {
        std::io::_print(std::format_args_nl!("cargo:rustc-cfg={}",stringify!(platform_macos)));
    };
}{
    std::io::_print(std::format_args_nl!("cargo:rustc-check-cfg=cfg({})",stringify!(platform_bsd)));
};
if cfg_aliases::cfg_aliases!(@parser_clause any[][ = "dragonfly",target_os = "freebsd",target_os = "openbsd",target_os = "netbsd"]target_os);
{
    {
        std::io::_print(std::format_args_nl!("cargo:rustc-cfg={}",stringify!(platform_bsd)));
    };
}

Where there are unexpanded references to cfg_aliases::cfg_aliases!.

When doing this in VSCode, there are no errors. However, when running Github's CodeQL Analysis for Rust (which uses Rust Analyzer for macro expansion), it fails with the following errors:

  [2025-07-18 19:21:49] [build-stdout] [2025-07-18 19:21:49] [build-stdout]  WARN /home/runner/work/PWAsForFirefox/PWAsForFirefox/native/build.rs:26:29: macro expansion failed: the macro '$crate::cfg_aliases' expands to ERROR but a Expr was expected

  [2025-07-18 19:21:55] [build-stdout] [2025-07-18 19:21:55] [build-stdout]  WARN /home/runner/work/PWAsForFirefox/PWAsForFirefox/native/src/components/runtime.rs:145:23: macro expansion failed: could not resolve macro '$crate::pmr::__concatcp_impl'
  [2025-07-18 19:21:55] [build-stdout] [2025-07-18 19:21:55] [build-stdout]  WARN /home/runner/work/PWAsForFirefox/PWAsForFirefox/native/src/components/runtime.rs:143:23: macro expansion failed: could not resolve macro '$crate::pmr::__concatcp_impl'
  [2025-07-18 19:21:55] [build-stdout] [2025-07-18 19:21:55] [build-stdout]  WARN /home/runner/work/PWAsForFirefox/PWAsForFirefox/native/src/components/runtime.rs:139:23: macro expansion failed: could not resolve macro '$crate::pmr::__concatcp_impl'
  [2025-07-18 19:21:55] [build-stdout] [2025-07-18 19:21:55] [build-stdout]  WARN /home/runner/work/PWAsForFirefox/PWAsForFirefox/native/src/components/runtime.rs:137:23: macro expansion failed: could not resolve macro '$crate::pmr::__concatcp_impl'
  [2025-07-18 19:21:55] [build-stdout] [2025-07-18 19:21:55] [build-stdout]  WARN /home/runner/work/PWAsForFirefox/PWAsForFirefox/native/src/components/runtime.rs:135:23: macro expansion failed: could not resolve macro '$crate::pmr::__concatcp_impl'
  [2025-07-18 19:21:55] [build-stdout] [2025-07-18 19:21:55] [build-stdout]  WARN /home/runner/work/PWAsForFirefox/PWAsForFirefox/native/src/components/runtime.rs:133:23: macro expansion failed: could not resolve macro '$crate::pmr::__concatcp_impl'

I reported it to GitHub here, and it seems it might be the problem with Rust Analyzer.

rust-analyzer version: 0.3.2547-standalone

rustc version: 1.88.0 (6b00bc388 2025-06-23)

editor or extension: VSCode, CodeQL

relevant settings: Default

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions