Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: macros cannot expand to foreign items #5668

Closed
jbclements opened this issue Apr 1, 2013 · 10 comments
Closed

error: macros cannot expand to foreign items #5668

jbclements opened this issue Apr 1, 2013 · 10 comments
Labels
A-syntaxext Area: Syntax extensions C-feature-request Category: A feature request, i.e: not implemented / a PR. P-low Low priority

Comments

@jbclements
Copy link
Contributor

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

@jbclements
Copy link
Contributor Author

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

macro_rules! f_decl {
    () => (fn f ();)
}

extern {
    f_decl!();

}

@catamorphism
Copy link
Contributor

Nominating for milestone 5, production-ready

@graydon
Copy link
Contributor

graydon commented Jul 25, 2013

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

@graydon
Copy link
Contributor

graydon commented Aug 15, 2013

accepted for feature-complete milestone

@pnkfelix
Copy link
Member

This need not block 1.0. Assigning P-low.

@huonw
Copy link
Member

huonw commented Mar 2, 2015

Triage bump (still an issue).

@julienw
Copy link

julienw commented Mar 1, 2016

still an issue.

@julienw
Copy link

julienw commented Mar 1, 2016

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)

@Mark-Simulacrum Mark-Simulacrum changed the title macros can't expand into items in foreign modules error: macros cannot expand to foreign items Apr 30, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 19, 2017
@steveklabnik
Copy link
Member

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

@petrochenkov
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions C-feature-request Category: A feature request, i.e: not implemented / a PR. P-low Low priority
Projects
None yet
Development

No branches or pull requests

10 participants