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

60ed5e7
Opened by Stepan Koltsov at 2014-01-08 04:33:25

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");
}
  1. This is presumably a consequence of hygiene (for locals), not sure about globals.

    cc @paulstansifer @jbclements

    Huon Wilson at 2014-01-08 03:08:22

  2. Yes, this is exactly the expected behavior. Can I close this as not-a-bug?

    John Clements at 2014-01-08 04:32:19

  3. Closing according to @jbclements

    Alex Crichton at 2014-01-08 04:33:25