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

Include Macro does not work properly: non-item macro in item position: include #17941

Closed
mitsuhiko opened this issue Oct 11, 2014 · 2 comments
Closed
Labels
A-syntaxext Area: Syntax extensions

Comments

@mitsuhiko
Copy link
Contributor

test.rs:

include!("test.inc")

fn main() {
    println!("{}", foo());
}

test.inc:

fn foo() -> int {
    return 42;
}

Compiler error:

test.inc:1:1: 1:3 error: expected identifier, found keyword `fn`
test.inc:1 fn foo() -> int {
           ^~
test.rs:1:1: 1:8 error: non-item macro in item position: include
test.rs:1 include!("test.inc")
          ^~~~~~~
error: aborting due to 2 previous errors
@eddyb
Copy link
Member

eddyb commented Oct 11, 2014

The way it is implemented, it handles only expressions.
It should use a MacResult type capable of producing any AST node from an arbitrary token reader.

@huonw huonw added the A-syntaxext Area: Syntax extensions label Oct 11, 2014
@alexcrichton
Copy link
Member

This appears to have been fixed in the meantime, yay!

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 29, 2024
…Veykril

Preliminary work for rust-lang#17940

I split the PR as requested, and made small commits.
lnicola pushed a commit to lnicola/rust that referenced this issue Aug 29, 2024
feat: Create an assist to convert closure to freestanding fn

The assist converts all captures to parameters.

Closes rust-lang#17920.

This was more work than I though, since it has to handle a bunch of edge cases...

Based on rust-lang#17941. Needs to merge it first.
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

4 participants