Skip to content

error: macros cannot expand to foreign items #5668

Closed

Description

@jbclements

I'm assuming this is supposed to be in the language, but not yet supported. I'm hoping to support it. Placeholder bug.

Activity

  1. jbclements commented on Apr 1, 2013

    @jbclements
    ContributorAuthor

    I should at least include some code. Here's some code:

    macro_rules! f_decl {
        () => (fn f ();)
    }
    
    extern {
        f_decl!();
    
    }
    
  2. catamorphism commented on May 24, 2013

    @catamorphism
    Contributor

    Nominating for milestone 5, production-ready

  3. graydon commented on Jul 25, 2013

    @graydon
    Contributor

    Visiting for triage. My nomination vote goes with "feature complete"; this is a proper (if minor) feature. Unless it's implemented-and-buggy currently?

  4. graydon commented on Aug 15, 2013

    @graydon
    Contributor

    accepted for feature-complete milestone

  5. pnkfelix commented on Feb 13, 2014

    @pnkfelix
    Contributor

    This need not block 1.0. Assigning P-low.

  6. huonw commented on Mar 2, 2015

    @huonw
    Contributor

    Triage bump (still an issue).

  7. julienw commented on Mar 1, 2016

    @julienw

    still an issue.

  8. julienw commented on Mar 1, 2016

    @julienw

    My own use case is I have a bunch of external functions like:

    extern {
        pub fn manager_node_is_listening_device(manager: *mut Manager, home_id: u32, node_id: u8) -> bool;
        pub fn manager_node_is_frequent_listening_device(manager: *mut Manager, home_id: u32, node_id: u8) -> bool;
        pub fn manager_node_is_beaming_device(manager: *mut Manager, home_id: u32, node_id: u8) -> bool;
    }

    and I wanted to be more DRY:

    macro_rules! node_getters {
        ( $($name: ident -> $t: ty),+ ) => {
            $(pub fn $name(manager: *mut Manager, home_id: u32, node_id: u8) -> $t;)*
        }
    }
    
    extern {
      node_getters! {
        manager_node_is_listening_device -> bool,
        manager_node_is_frequent_listening_device -> bool,
        manager_node_is_beaming_device -> bool
      }
    }

    (Note I have a bunch of more functions too)

  9. changed the title [-]macros can't expand into items in foreign modules[/-] [+]error: macros cannot expand to foreign items[/+] on Apr 30, 2017
  10. added
    C-feature-request
    on Jul 19, 2017
  11. steveklabnik commented on Sep 24, 2018

    @steveklabnik
    Contributor

    Triage: no comments in two years, and macro_rules is not being improved anymore. I'm going to close this.

  12. petrochenkov commented on Sep 24, 2018

    @petrochenkov
    Contributor

    Macros work in foreign blocks now, but they are not yet stable and gated by feature(macros_in_extern).

  13. added a commit that references this issue on Aug 21, 2026
  14. added 2 commits that reference this issue on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxextC-feature-requestP-low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions