Skip to content

cannot define a capturing macro in an expr passed to println! #31946

New issue

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

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

Already on GitHub? # to your account

Closed
durka opened this issue Feb 28, 2016 · 1 comment · Fixed by #40523
Closed

cannot define a capturing macro in an expr passed to println! #31946

durka opened this issue Feb 28, 2016 · 1 comment · Fixed by #40523
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@durka
Copy link
Contributor

durka commented Feb 28, 2016

This code

macro_rules! passthru {
    ($($t:tt)*) => { format_args!("{}", $($t)*) }
}

fn main() {
    passthru!({
        macro_rules! foo {
            ($name:expr) => { concat!("hello ", $name) }
        }
        foo!("rust")
    });
}

fails with a nonsense "unknown macro variable name". It works if the macro has no captures or if it's defined outside. And you can normally define a macro in an expression.

Somehow related to the format_args! expansion, but it doesn't occur without the intermediate passthru! macro (which represents println!, print!, or format!). And I can't see the expansion because it doesn't get that far.

@durka
Copy link
Contributor Author

durka commented Mar 14, 2017

This has been fixed, likely by @jseyfried. I think it needs a test though.

durka added a commit to durka/rust that referenced this issue Mar 14, 2017
Adds a test for issue rust-lang#31946 which was fixed a while ago.
@jseyfried jseyfried added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Mar 15, 2017
arielb1 pushed a commit to arielb1/rust that referenced this issue Mar 18, 2017
add test for nested macro def (rust-lang#31946)

Adds a test for issue rust-lang#31946 which was fixed in 1.12.0.

Closes rust-lang#31946.
arielb1 pushed a commit to arielb1/rust that referenced this issue Mar 19, 2017
add test for nested macro def (rust-lang#31946)

Adds a test for issue rust-lang#31946 which was fixed in 1.12.0.

Closes rust-lang#31946.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 20, 2017
add test for nested macro def (rust-lang#31946)

Adds a test for issue rust-lang#31946 which was fixed in 1.12.0.

Closes rust-lang#31946.
retep998 pushed a commit to durka/rust that referenced this issue Mar 21, 2017
Adds a test for issue rust-lang#31946 which was fixed a while ago.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 22, 2017
add test for nested macro def (rust-lang#31946)

Adds a test for issue rust-lang#31946 which was fixed in 1.12.0.

Closes rust-lang#31946.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 22, 2017
add test for nested macro def (rust-lang#31946)

Adds a test for issue rust-lang#31946 which was fixed in 1.12.0.

Closes rust-lang#31946.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants