rust/tests/target/macros.rs
Eli Friedman 1c235de97d Fix crash speculatively parsing macro arguments as expressions.
The problem is essentially that if we try to parse a token tree using a
CodeMap different from the one the tree was originally parsed with,
spans become nonsense. Since CodeMaps can't be cloned, we're basically
forced to use the original ParseSess for additional parsing.

Ideally, rustfmt would be a bit more clever and figure out how to parse
macro arguments based on the definition of the macro itself, rather than
just guessing that a particular token sequence looks like an expression,
but this is good enough for now.

Fixes #538.
2015-10-27 23:41:32 -07:00

36 lines
679 B
Rust

itemmacro!(this, is.not() .formatted(yet));
fn main() {
foo!();
bar!(a, b, c);
baz!(1 + 2 + 3, quux.kaas());
quux!(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB);
kaas!(// comments
a, // post macro
b /* another */);
trailingcomma!( a , b , c , );
noexpr!( i am not an expression, OK? );
vec![a, b, c];
vec![AAAAAA, AAAAAA, AAAAAA, AAAAAA, AAAAAA, AAAAAA, AAAAAA, AAAAAA, AAAAAA, BBBBB, 5,
100 - 30, 1.33, b, b, b];
vec![a /* comment */];
foo(makro!(1, 3));
hamkaas!{ () };
macrowithbraces! {dont, format, me}
x!(fn);
}