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

Resolve the nested inner macros correctly #12404

Closed
edwardw opened this issue Feb 19, 2014 · 9 comments
Closed

Resolve the nested inner macros correctly #12404

edwardw opened this issue Feb 19, 2014 · 9 comments
Labels
A-syntaxext Area: Syntax extensions

Comments

@edwardw
Copy link
Contributor

edwardw commented Feb 19, 2014

Currently, the inner macro in a nested macro invocation is not properly resolved which prevents nested macro invocation from working. If we are to support such invocation, this issue ought to be fixed.

cc #11692. #9323 is also relevant with regard to the macro scope rules in general.


Example from #13876:

The expression println!(format!("test")) produces the following error:

<anon>:18:18: 18:24 error: macro undefined: 'format'
<anon>:18         println!(format!("test"))
                           ^~~~~~
<anon>:18:18: 18:33 error: format argument must be a string literal.
<anon>:18         println!(format!("test"))
                           ^~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
@sfackler
Copy link
Member

cc me

@huonw
Copy link
Member

huonw commented Feb 19, 2014

Could you give a code example of this to aid future triagers?

@edwardw
Copy link
Contributor Author

edwardw commented Feb 19, 2014

Certainly.

echo 'fn main() { print!(format!("BAM")); }' | rustc -

should compile but it doesn't right now. Note

echo 'fn main() { print!(concat!("foo", " ", "bar\n")); }' | rustc -

does work but only because concat! is one of the handful builtin macros defined in syntax::ext::base::syntax_expander_table.

@alexcrichton
Copy link
Member

I'm not sure that print!(format!("test")) should be valid because you'd have to execute the format string at compile-time (which can run arbitrary code).

The only reason that print!(concat!(..)) works is because special handler code was added. @jbclements also had concerns (#9740 (comment)) about expanding nested macros in terms of hygiene.

@huonw
Copy link
Member

huonw commented Feb 20, 2014

@alexcrichton it currently fails with a "undefined macro: format" error.

@jbclements
Copy link
Contributor

This would be an appropriate place for partial expansion, if we had it. Specifically: expand the argument until it's clear that it is or isn't a string.

@steveklabnik
Copy link
Member

Looks like this may be fixed:

hello.rs:2:14: 2:28 error: expected a literal
hello.rs:2     println!(format!("lol"));
                        ^~~~~~~~~~~~~~

@KalitaAlexey
Copy link
Contributor

Hi @steveklabnik,

It works. Why this issue still opened?

@Mark-Simulacrum
Copy link
Member

Yeah, I think that we've solved this.

flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 7, 2024
Added msrv to threadlocal initializer check

closes: rust-lang#12404
changelog:[`thread_local_initializer_can_be_made_const`]: Check for MSRV (>= 1.59) before processing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions
Projects
None yet
Development

No branches or pull requests

8 participants