Skip to content

include!(...) does not see local variables #11390

@stepancheg

Description

@stepancheg

Code included with include!(...) macro does not see local variables.

To reproduce you need two files: included.rs and main.rs:

included.rs:

zzz

main.rs:

fn main() {
    let zzz = 1;
    let www = include!("included.rs");
}

Error is:

$ rustc ./main.rs
main.rs:3:15: 3:39 error: unresolved name `zzz`.
main.rs:3     let www = include!("included.rs");
                        ^~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /rust/src/libsyntax/diagnostic.rs:75
task '<main>' failed at 'explicit failure', /rust/src/librustc/lib.rs:440

Though it works well when zzz is global variable:

static zzz: int = 1;

fn main() {
    let www = include!("included.rs");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxextArea: Syntax extensions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions