1
Fork 0

librustc: Always parse macro!()/macro![] as expressions if not

followed by a semicolon.

This allows code like `vec![1i, 2, 3].len();` to work.

This breaks code that uses macros as statements without putting
semicolons after them, such as:

    fn main() {
        ...
        assert!(a == b)
        assert!(c == d)
        println(...);
    }

It also breaks code that uses macros as items without semicolons:

    local_data_key!(foo)

    fn main() {
        println("hello world")
    }

Add semicolons to fix this code. Those two examples can be fixed as
follows:

    fn main() {
        ...
        assert!(a == b);
        assert!(c == d);
        println(...);
    }

    local_data_key!(foo);

    fn main() {
        println("hello world")
    }

RFC #378.

Closes #18635.

[breaking-change]
This commit is contained in:
Patrick Walton 2014-11-14 09:18:10 -08:00 committed by Jorge Aparicio
parent c0b2885ee1
commit ddb2466f6a
222 changed files with 2330 additions and 2039 deletions

View file

@ -340,14 +340,17 @@ mod svh_visitor {
// expensive; a direct content-based hash on token
// trees might be faster. Implementing this is far
// easier in short term.
let macro_defn_as_string =
pprust::to_string(|pp_state| pp_state.print_mac(macro));
let macro_defn_as_string = pprust::to_string(|pp_state| {
pp_state.print_mac(macro, token::Paren)
});
macro_defn_as_string.hash(self.st);
} else {
// It is not possible to observe any kind of macro
// invocation at this stage except `macro_rules!`.
panic!("reached macro somehow: {}",
pprust::to_string(|pp_state| pp_state.print_mac(macro)));
pprust::to_string(|pp_state| {
pp_state.print_mac(macro, token::Paren)
}));
}
visit::walk_mac(self, macro);