aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-05-29 07:40:39 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-05-29 07:40:39 +0100
commit7a1cae59acf72f821343b2ba10ef69fb92a5b952 (patch)
tree26e606ccd132a24e9bc89cf174e4adadf60c5992 /crates/ra_mbe
parentb0d84cb8faefedde7ace4ff152a2a13408e79e5d (diff)
parent80a17251473bd6213a4c8a51ea7f732394d173c5 (diff)
Merge #1337
1337: Move syntax errors our of syntax tree r=matklad a=matklad I am not really sure if it's a good idea, but `SyntaxError` do not really belong to a `SyntaxTree`. So let's just store them on the side? Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r--crates/ra_mbe/src/mbe_expander.rs4
-rw-r--r--crates/ra_mbe/src/mbe_parser.rs2
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs9
-rw-r--r--crates/ra_mbe/src/tests.rs163
4 files changed, 89 insertions, 89 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs
index 7fff8deff..a0bd0c5f8 100644
--- a/crates/ra_mbe/src/mbe_expander.rs
+++ b/crates/ra_mbe/src/mbe_expander.rs
@@ -597,7 +597,7 @@ mod tests {
597 } 597 }
598 598
599 fn create_rules(macro_definition: &str) -> crate::MacroRules { 599 fn create_rules(macro_definition: &str) -> crate::MacroRules {
600 let source_file = ast::SourceFile::parse(macro_definition); 600 let source_file = ast::SourceFile::parse(macro_definition).ok().unwrap();
601 let macro_definition = 601 let macro_definition =
602 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); 602 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
603 603
@@ -609,7 +609,7 @@ mod tests {
609 rules: &crate::MacroRules, 609 rules: &crate::MacroRules,
610 invocation: &str, 610 invocation: &str,
611 ) -> Result<tt::Subtree, ExpandError> { 611 ) -> Result<tt::Subtree, ExpandError> {
612 let source_file = ast::SourceFile::parse(invocation); 612 let source_file = ast::SourceFile::parse(invocation).ok().unwrap();
613 let macro_invocation = 613 let macro_invocation =
614 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); 614 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
615 615
diff --git a/crates/ra_mbe/src/mbe_parser.rs b/crates/ra_mbe/src/mbe_parser.rs
index 797c70bc7..d8fe293c7 100644
--- a/crates/ra_mbe/src/mbe_parser.rs
+++ b/crates/ra_mbe/src/mbe_parser.rs
@@ -175,7 +175,7 @@ mod tests {
175 } 175 }
176 176
177 fn create_rules(macro_definition: &str) -> Result<crate::MacroRules, ParseError> { 177 fn create_rules(macro_definition: &str) -> Result<crate::MacroRules, ParseError> {
178 let source_file = ast::SourceFile::parse(macro_definition); 178 let source_file = ast::SourceFile::parse(macro_definition).ok().unwrap();
179 let macro_definition = 179 let macro_definition =
180 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); 180 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
181 181
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index c0a3fec35..dce82f33d 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -56,8 +56,9 @@ where
56 if tree_sink.roots.len() != 1 { 56 if tree_sink.roots.len() != 1 {
57 return Err(ExpandError::ConversionError); 57 return Err(ExpandError::ConversionError);
58 } 58 }
59 59 //FIXME: would be cool to report errors
60 Ok(tree_sink.inner.finish()) 60 let (tree, _errors) = tree_sink.inner.finish();
61 Ok(tree)
61} 62}
62 63
63/// Parses the token tree (result of macro expansion) to an expression 64/// Parses the token tree (result of macro expansion) to an expression
@@ -383,7 +384,7 @@ mod tests {
383 } 384 }
384 "#, 385 "#,
385 ); 386 );
386 let expansion = expand(&rules, "literals!(foo)"); 387 let expansion = expand(&rules, "literals!(foo);");
387 let buffer = tt::buffer::TokenBuffer::new(&[expansion.clone().into()]); 388 let buffer = tt::buffer::TokenBuffer::new(&[expansion.clone().into()]);
388 let mut tt_src = SubtreeTokenSource::new(&buffer); 389 let mut tt_src = SubtreeTokenSource::new(&buffer);
389 let mut tokens = vec![]; 390 let mut tokens = vec![];
@@ -422,7 +423,7 @@ mod tests {
422 } 423 }
423 "#, 424 "#,
424 ); 425 );
425 let expansion = expand(&rules, "stmts!()"); 426 let expansion = expand(&rules, "stmts!();");
426 assert!(token_tree_to_expr(&expansion).is_err()); 427 assert!(token_tree_to_expr(&expansion).is_err());
427 } 428 }
428} 429}
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs
index e3a5ceecf..1db35cd8d 100644
--- a/crates/ra_mbe/src/tests.rs
+++ b/crates/ra_mbe/src/tests.rs
@@ -29,11 +29,11 @@ macro_rules! impl_froms {
29impl_froms!(TokenTree: Leaf, Subtree); 29impl_froms!(TokenTree: Leaf, Subtree);
30"#; 30"#;
31 31
32 let source_file = ast::SourceFile::parse(macro_definition); 32 let source_file = ast::SourceFile::parse(macro_definition).ok().unwrap();
33 let macro_definition = 33 let macro_definition =
34 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); 34 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
35 35
36 let source_file = ast::SourceFile::parse(macro_invocation); 36 let source_file = ast::SourceFile::parse(macro_invocation).ok().unwrap();
37 let macro_invocation = 37 let macro_invocation =
38 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); 38 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
39 39
@@ -49,7 +49,7 @@ impl_froms!(TokenTree: Leaf, Subtree);
49} 49}
50 50
51pub(crate) fn create_rules(macro_definition: &str) -> MacroRules { 51pub(crate) fn create_rules(macro_definition: &str) -> MacroRules {
52 let source_file = ast::SourceFile::parse(macro_definition); 52 let source_file = ast::SourceFile::parse(macro_definition).ok().unwrap();
53 let macro_definition = 53 let macro_definition =
54 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); 54 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
55 55
@@ -58,7 +58,7 @@ pub(crate) fn create_rules(macro_definition: &str) -> MacroRules {
58} 58}
59 59
60pub(crate) fn expand(rules: &MacroRules, invocation: &str) -> tt::Subtree { 60pub(crate) fn expand(rules: &MacroRules, invocation: &str) -> tt::Subtree {
61 let source_file = ast::SourceFile::parse(invocation); 61 let source_file = ast::SourceFile::parse(invocation).ok().unwrap();
62 let macro_invocation = 62 let macro_invocation =
63 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); 63 source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap();
64 64
@@ -95,7 +95,7 @@ pub(crate) fn expand_to_expr(
95pub(crate) fn text_to_tokentree(text: &str) -> tt::Subtree { 95pub(crate) fn text_to_tokentree(text: &str) -> tt::Subtree {
96 // wrap the given text to a macro call 96 // wrap the given text to a macro call
97 let wrapped = format!("wrap_macro!( {} )", text); 97 let wrapped = format!("wrap_macro!( {} )", text);
98 let wrapped = ast::SourceFile::parse(&wrapped); 98 let wrapped = ast::SourceFile::parse(&wrapped).tree;
99 let wrapped = wrapped.syntax().descendants().find_map(ast::TokenTree::cast).unwrap(); 99 let wrapped = wrapped.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
100 let mut wrapped = ast_to_token_tree(wrapped).unwrap().0; 100 let mut wrapped = ast_to_token_tree(wrapped).unwrap().0;
101 wrapped.delimiter = tt::Delimiter::None; 101 wrapped.delimiter = tt::Delimiter::None;
@@ -294,7 +294,7 @@ fn test_match_group_pattern_with_multiple_defs() {
294 macro_rules! foo { 294 macro_rules! foo {
295 ($ ($ i:ident),*) => ( struct Bar { $ ( 295 ($ ($ i:ident),*) => ( struct Bar { $ (
296 fn $ i {} 296 fn $ i {}
297 )*} ); 297 )*} );
298 } 298 }
299"#, 299"#,
300 ); 300 );
@@ -314,7 +314,7 @@ fn test_match_group_pattern_with_multiple_statement() {
314 macro_rules! foo { 314 macro_rules! foo {
315 ($ ($ i:ident),*) => ( fn baz { $ ( 315 ($ ($ i:ident),*) => ( fn baz { $ (
316 $ i (); 316 $ i ();
317 )*} ); 317 )*} );
318 } 318 }
319"#, 319"#,
320 ); 320 );
@@ -329,7 +329,7 @@ fn test_match_group_pattern_with_multiple_statement_without_semi() {
329 macro_rules! foo { 329 macro_rules! foo {
330 ($ ($ i:ident),*) => ( fn baz { $ ( 330 ($ ($ i:ident),*) => ( fn baz { $ (
331 $i() 331 $i()
332 );*} ); 332 );*} );
333 } 333 }
334"#, 334"#,
335 ); 335 );
@@ -344,7 +344,7 @@ fn test_match_group_empty_fixed_token() {
344 macro_rules! foo { 344 macro_rules! foo {
345 ($ ($ i:ident)* #abc) => ( fn baz { $ ( 345 ($ ($ i:ident)* #abc) => ( fn baz { $ (
346 $ i (); 346 $ i ();
347 )*} ); 347 )*} );
348 } 348 }
349"#, 349"#,
350 ); 350 );
@@ -356,10 +356,10 @@ fn test_match_group_empty_fixed_token() {
356fn test_match_group_in_subtree() { 356fn test_match_group_in_subtree() {
357 let rules = create_rules( 357 let rules = create_rules(
358 r#" 358 r#"
359 macro_rules! foo { 359 macro_rules! foo {
360 (fn $name:ident {$($i:ident)*} ) => ( fn $name() { $ ( 360 (fn $name:ident {$($i:ident)*} ) => ( fn $name() { $ (
361 $ i (); 361 $ i ();
362 )*} ); 362 )*} );
363 }"#, 363 }"#,
364 ); 364 );
365 365
@@ -370,15 +370,15 @@ fn test_match_group_in_subtree() {
370fn test_match_group_with_multichar_sep() { 370fn test_match_group_with_multichar_sep() {
371 let rules = create_rules( 371 let rules = create_rules(
372 r#" 372 r#"
373 macro_rules! foo { 373 macro_rules! foo {
374 (fn $name:ident {$($i:literal)*} ) => ( fn $name() -> bool { $($i)&&*} ); 374 (fn $name:ident {$($i:literal)*} ) => ( fn $name() -> bool { $($i)&&*} );
375 }"#, 375 }"#,
376 ); 376 );
377 377
378 assert_expansion( 378 assert_expansion(
379 MacroKind::Items, 379 MacroKind::Items,
380 &rules, 380 &rules,
381 "foo! (fn baz {true true} )", 381 "foo! (fn baz {true true} );",
382 "fn baz () -> bool {true &&true}", 382 "fn baz () -> bool {true &&true}",
383 ); 383 );
384} 384}
@@ -387,24 +387,24 @@ fn test_match_group_with_multichar_sep() {
387fn test_match_group_zero_match() { 387fn test_match_group_zero_match() {
388 let rules = create_rules( 388 let rules = create_rules(
389 r#" 389 r#"
390 macro_rules! foo { 390 macro_rules! foo {
391 ( $($i:ident)* ) => (); 391 ( $($i:ident)* ) => ();
392 }"#, 392 }"#,
393 ); 393 );
394 394
395 assert_expansion(MacroKind::Items, &rules, "foo! ()", ""); 395 assert_expansion(MacroKind::Items, &rules, "foo! ();", "");
396} 396}
397 397
398#[test] 398#[test]
399fn test_match_group_in_group() { 399fn test_match_group_in_group() {
400 let rules = create_rules( 400 let rules = create_rules(
401 r#" 401 r#"
402 macro_rules! foo { 402 macro_rules! foo {
403 { $( ( $($i:ident)* ) )* } => ( $( ( $($i)* ) )* ); 403 { $( ( $($i:ident)* ) )* } => ( $( ( $($i)* ) )* );
404 }"#, 404 }"#,
405 ); 405 );
406 406
407 assert_expansion(MacroKind::Items, &rules, "foo! ( (a b) )", "(a b)"); 407 assert_expansion(MacroKind::Items, &rules, "foo! ( (a b) );", "(a b)");
408} 408}
409 409
410#[test] 410#[test]
@@ -418,7 +418,7 @@ fn test_expand_to_item_list() {
418 } 418 }
419 ", 419 ",
420 ); 420 );
421 let expansion = expand(&rules, "structs!(Foo, Bar)"); 421 let expansion = expand(&rules, "structs!(Foo, Bar);");
422 let tree = token_tree_to_macro_items(&expansion); 422 let tree = token_tree_to_macro_items(&expansion);
423 assert_eq!( 423 assert_eq!(
424 tree.unwrap().syntax().debug_dump().trim(), 424 tree.unwrap().syntax().debug_dump().trim(),
@@ -490,7 +490,7 @@ fn test_expand_literals_to_token_tree() {
490 } 490 }
491 "#, 491 "#,
492 ); 492 );
493 let expansion = expand(&rules, "literals!(foo)"); 493 let expansion = expand(&rules, "literals!(foo);");
494 let stm_tokens = &to_subtree(&expansion.token_trees[0]).token_trees; 494 let stm_tokens = &to_subtree(&expansion.token_trees[0]).token_trees;
495 495
496 // [let] [a] [=] ['c'] [;] 496 // [let] [a] [=] ['c'] [;]
@@ -586,7 +586,7 @@ fn test_match_literal() {
586 } 586 }
587"#, 587"#,
588 ); 588 );
589 assert_expansion(MacroKind::Items, &rules, "foo! ['(']", "fn foo () {}"); 589 assert_expansion(MacroKind::Items, &rules, "foo! ['('];", "fn foo () {}");
590} 590}
591 591
592// The following tests are port from intellij-rust directly 592// The following tests are port from intellij-rust directly
@@ -651,7 +651,7 @@ fn test_expr() {
651 r#" 651 r#"
652 macro_rules! foo { 652 macro_rules! foo {
653 ($ i:expr) => { 653 ($ i:expr) => {
654 fn bar() { $ i; } 654 fn bar() { $ i; }
655 } 655 }
656 } 656 }
657"#, 657"#,
@@ -671,7 +671,7 @@ fn test_expr_order() {
671 r#" 671 r#"
672 macro_rules! foo { 672 macro_rules! foo {
673 ($ i:expr) => { 673 ($ i:expr) => {
674 fn bar() { $ i * 2; } 674 fn bar() { $ i * 2; }
675 } 675 }
676 } 676 }
677"#, 677"#,
@@ -725,7 +725,7 @@ fn test_last_expr() {
725 assert_expansion( 725 assert_expansion(
726 MacroKind::Items, 726 MacroKind::Items,
727 &rules, 727 &rules,
728 "vec!(1,2,3)", 728 "vec!(1,2,3);",
729 "{let mut v = Vec :: new () ; v . push (1) ; v . push (2) ; v . push (3) ; v}", 729 "{let mut v = Vec :: new () ; v . push (1) ; v . push (2) ; v . push (3) ; v}",
730 ); 730 );
731} 731}
@@ -896,13 +896,13 @@ fn test_meta_doc_comments() {
896 assert_expansion( 896 assert_expansion(
897 MacroKind::Items, 897 MacroKind::Items,
898 &rules, 898 &rules,
899 r#"foo! { 899 r#"foo! {
900 /// Single Line Doc 1 900 /// Single Line Doc 1
901 /** 901 /**
902 MultiLines Doc 902 MultiLines Doc
903 */ 903 */
904 }"#, 904 }"#,
905 "# [doc = \" Single Line Doc 1\"] # [doc = \" \\\\n MultiLines Doc\\\\n \"] fn bar () {}", 905 "# [doc = \" Single Line Doc 1\"] # [doc = \"\\\\n MultiLines Doc\\\\n \"] fn bar () {}",
906 ); 906 );
907} 907}
908 908
@@ -950,7 +950,7 @@ fn test_literal() {
950 } 950 }
951"#, 951"#,
952 ); 952 );
953 assert_expansion(MacroKind::Items, &rules, r#"foo!(u8 0)"#, r#"const VALUE : u8 = 0 ;"#); 953 assert_expansion(MacroKind::Items, &rules, r#"foo!(u8 0);"#, r#"const VALUE : u8 = 0 ;"#);
954} 954}
955 955
956#[test] 956#[test]
@@ -984,7 +984,7 @@ macro_rules! foo {
984 bar!($a); 984 bar!($a);
985 fn $b() -> u8 {$c} 985 fn $b() -> u8 {$c}
986 } 986 }
987} 987}
988"#, 988"#,
989 ); 989 );
990 assert_expansion( 990 assert_expansion(
@@ -1017,12 +1017,12 @@ fn test_vec() {
1017 assert_expansion( 1017 assert_expansion(
1018 MacroKind::Items, 1018 MacroKind::Items,
1019 &rules, 1019 &rules,
1020 r#"vec![1u32,2]"#, 1020 r#"vec![1u32,2];"#,
1021 r#"{let mut v = Vec :: new () ; v . push (1u32) ; v . push (2) ; v}"#, 1021 r#"{let mut v = Vec :: new () ; v . push (1u32) ; v . push (2) ; v}"#,
1022 ); 1022 );
1023 1023
1024 assert_eq!( 1024 assert_eq!(
1025 expand_to_expr(&rules, r#"vec![1u32,2]"#).syntax().debug_dump().trim(), 1025 expand_to_expr(&rules, r#"vec![1u32,2];"#).syntax().debug_dump().trim(),
1026 r#"BLOCK_EXPR@[0; 45) 1026 r#"BLOCK_EXPR@[0; 45)
1027 BLOCK@[0; 45) 1027 BLOCK@[0; 45)
1028 L_CURLY@[0; 1) "{" 1028 L_CURLY@[0; 1) "{"
@@ -1119,7 +1119,7 @@ macro_rules! STRUCT {
1119 // from https://github.com/retep998/winapi-rs/blob/a7ef2bca086aae76cf6c4ce4c2552988ed9798ad/src/shared/d3d9caps.rs 1119 // from https://github.com/retep998/winapi-rs/blob/a7ef2bca086aae76cf6c4ce4c2552988ed9798ad/src/shared/d3d9caps.rs
1120 assert_expansion(MacroKind::Items, &rules, r#"STRUCT!{struct D3DVSHADERCAPS2_0 {Caps: u8,}}"#, 1120 assert_expansion(MacroKind::Items, &rules, r#"STRUCT!{struct D3DVSHADERCAPS2_0 {Caps: u8,}}"#,
1121 "# [repr (C)] # [derive (Copy)] pub struct D3DVSHADERCAPS2_0 {pub Caps : u8 ,} impl Clone for D3DVSHADERCAPS2_0 {# [inline] fn clone (& self) -> D3DVSHADERCAPS2_0 {* self}} # [cfg (feature = \"impl-default\")] impl Default for D3DVSHADERCAPS2_0 {# [inline] fn default () -> D3DVSHADERCAPS2_0 {unsafe {$crate :: _core :: mem :: zeroed ()}}}"); 1121 "# [repr (C)] # [derive (Copy)] pub struct D3DVSHADERCAPS2_0 {pub Caps : u8 ,} impl Clone for D3DVSHADERCAPS2_0 {# [inline] fn clone (& self) -> D3DVSHADERCAPS2_0 {* self}} # [cfg (feature = \"impl-default\")] impl Default for D3DVSHADERCAPS2_0 {# [inline] fn default () -> D3DVSHADERCAPS2_0 {unsafe {$crate :: _core :: mem :: zeroed ()}}}");
1122 assert_expansion(MacroKind::Items, &rules, r#"STRUCT!{#[cfg_attr(target_arch = "x86", repr(packed))] struct D3DCONTENTPROTECTIONCAPS {Caps : u8 ,}}"#, 1122 assert_expansion(MacroKind::Items, &rules, r#"STRUCT!{#[cfg_attr(target_arch = "x86", repr(packed))] struct D3DCONTENTPROTECTIONCAPS {Caps : u8 ,}}"#,
1123 "# [repr (C)] # [derive (Copy)] # [cfg_attr (target_arch = \"x86\" , repr (packed))] pub struct D3DCONTENTPROTECTIONCAPS {pub Caps : u8 ,} impl Clone for D3DCONTENTPROTECTIONCAPS {# [inline] fn clone (& self) -> D3DCONTENTPROTECTIONCAPS {* self}} # [cfg (feature = \"impl-default\")] impl Default for D3DCONTENTPROTECTIONCAPS {# [inline] fn default () -> D3DCONTENTPROTECTIONCAPS {unsafe {$crate :: _core :: mem :: zeroed ()}}}"); 1123 "# [repr (C)] # [derive (Copy)] # [cfg_attr (target_arch = \"x86\" , repr (packed))] pub struct D3DCONTENTPROTECTIONCAPS {pub Caps : u8 ,} impl Clone for D3DCONTENTPROTECTIONCAPS {# [inline] fn clone (& self) -> D3DCONTENTPROTECTIONCAPS {* self}} # [cfg (feature = \"impl-default\")] impl Default for D3DCONTENTPROTECTIONCAPS {# [inline] fn default () -> D3DCONTENTPROTECTIONCAPS {unsafe {$crate :: _core :: mem :: zeroed ()}}}");
1124} 1124}
1125 1125
@@ -1136,11 +1136,11 @@ macro_rules! int_base {
1136 } 1136 }
1137 } 1137 }
1138 } 1138 }
1139} 1139}
1140"#, 1140"#,
1141 ); 1141 );
1142 1142
1143 assert_expansion(MacroKind::Items, &rules, r#" int_base!{Binary for isize as usize -> Binary}"#, 1143 assert_expansion(MacroKind::Items, &rules, r#" int_base!{Binary for isize as usize -> Binary}"#,
1144 "# [stable (feature = \"rust1\" , since = \"1.0.0\")] impl fmt ::Binary for isize {fn fmt (& self , f : & mut fmt :: Formatter < \'_ >) -> fmt :: Result {Binary . fmt_int (* self as usize , f)}}" 1144 "# [stable (feature = \"rust1\" , since = \"1.0.0\")] impl fmt ::Binary for isize {fn fmt (& self , f : & mut fmt :: Formatter < \'_ >) -> fmt :: Result {Binary . fmt_int (* self as usize , f)}}"
1145 ); 1145 );
1146} 1146}
@@ -1150,7 +1150,7 @@ fn test_generate_pattern_iterators() {
1150 // from https://github.com/rust-lang/rust/blob/316a391dcb7d66dc25f1f9a4ec9d368ef7615005/src/libcore/str/mod.rs 1150 // from https://github.com/rust-lang/rust/blob/316a391dcb7d66dc25f1f9a4ec9d368ef7615005/src/libcore/str/mod.rs
1151 let rules = create_rules( 1151 let rules = create_rules(
1152 r#" 1152 r#"
1153macro_rules! generate_pattern_iterators { 1153macro_rules! generate_pattern_iterators {
1154 { double ended; with $(#[$common_stability_attribute:meta])*, 1154 { double ended; with $(#[$common_stability_attribute:meta])*,
1155 $forward_iterator:ident, 1155 $forward_iterator:ident,
1156 $reverse_iterator:ident, $iterty:ty 1156 $reverse_iterator:ident, $iterty:ty
@@ -1161,7 +1161,7 @@ macro_rules! generate_pattern_iterators {
1161"#, 1161"#,
1162 ); 1162 );
1163 1163
1164 assert_expansion(MacroKind::Items, &rules, r#"generate_pattern_iterators ! ( double ended ; with # [ stable ( feature = "rust1" , since = "1.0.0" ) ] , Split , RSplit , & 'a str )"#, 1164 assert_expansion(MacroKind::Items, &rules, r#"generate_pattern_iterators ! ( double ended ; with # [ stable ( feature = "rust1" , since = "1.0.0" ) ] , Split , RSplit , & 'a str );"#,
1165 "fn foo () {}"); 1165 "fn foo () {}");
1166} 1166}
1167 1167
@@ -1170,7 +1170,7 @@ fn test_impl_fn_for_zst() {
1170 // from https://github.com/rust-lang/rust/blob/5d20ff4d2718c820632b38c1e49d4de648a9810b/src/libcore/internal_macros.rs 1170 // from https://github.com/rust-lang/rust/blob/5d20ff4d2718c820632b38c1e49d4de648a9810b/src/libcore/internal_macros.rs
1171 let rules = create_rules( 1171 let rules = create_rules(
1172 r#" 1172 r#"
1173macro_rules! impl_fn_for_zst { 1173macro_rules! impl_fn_for_zst {
1174 { $( $( #[$attr: meta] )* 1174 { $( $( #[$attr: meta] )*
1175 struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn = 1175 struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn =
1176 |$( $arg: ident: $ArgTy: ty ),*| -> $ReturnTy: ty 1176 |$( $arg: ident: $ArgTy: ty ),*| -> $ReturnTy: ty
@@ -1208,27 +1208,26 @@ $body: block; )+
1208 )+ 1208 )+
1209} 1209}
1210 } 1210 }
1211}
1212"#, 1211"#,
1213 ); 1212 );
1214 1213
1215 assert_expansion(MacroKind::Items, &rules, r#" 1214 assert_expansion(MacroKind::Items, &rules, r#"
1216impl_fn_for_zst ! { 1215impl_fn_for_zst ! {
1217 # [ derive ( Clone ) ] 1216 # [ derive ( Clone ) ]
1218 struct CharEscapeDebugContinue impl Fn = | c : char | -> char :: EscapeDebug { 1217 struct CharEscapeDebugContinue impl Fn = | c : char | -> char :: EscapeDebug {
1219 c . escape_debug_ext ( false ) 1218 c . escape_debug_ext ( false )
1220 } ; 1219 } ;
1221 1220
1222 # [ derive ( Clone ) ] 1221 # [ derive ( Clone ) ]
1223 struct CharEscapeUnicode impl Fn = | c : char | -> char :: EscapeUnicode { 1222 struct CharEscapeUnicode impl Fn = | c : char | -> char :: EscapeUnicode {
1224 c . escape_unicode ( ) 1223 c . escape_unicode ( )
1225 } ; 1224 } ;
1226 # [ derive ( Clone ) ] 1225 # [ derive ( Clone ) ]
1227 struct CharEscapeDefault impl Fn = | c : char | -> char :: EscapeDefault { 1226 struct CharEscapeDefault impl Fn = | c : char | -> char :: EscapeDefault {
1228 c . escape_default ( ) 1227 c . escape_default ( )
1229 } ; 1228 } ;
1230 } 1229 }
1231"#, 1230"#,
1232 "# [derive (Clone)] struct CharEscapeDebugContinue ; impl Fn < (char ,) > for CharEscapeDebugContinue {# [inline] extern \"rust-call\" fn call (& self , (c ,) : (char ,)) -> char :: EscapeDebug {{c . escape_debug_ext (false)}}} impl FnMut < (char ,) > for CharEscapeDebugContinue {# [inline] extern \"rust-call\" fn call_mut (& mut self , (c ,) : (char ,)) -> char :: EscapeDebug {Fn :: call (&* self , (c ,))}} impl FnOnce < (char ,) > for CharEscapeDebugContinue {type Output = char :: EscapeDebug ; # [inline] extern \"rust-call\" fn call_once (self , (c ,) : (char ,)) -> char :: EscapeDebug {Fn :: call (& self , (c ,))}} # [derive (Clone)] struct CharEscapeUnicode ; impl Fn < (char ,) > for CharEscapeUnicode {# [inline] extern \"rust-call\" fn call (& self , (c ,) : (char ,)) -> char :: EscapeUnicode {{c . escape_unicode ()}}} impl FnMut < (char ,) > for CharEscapeUnicode {# [inline] extern \"rust-call\" fn call_mut (& mut self , (c ,) : (char ,)) -> char :: EscapeUnicode {Fn :: call (&* self , (c ,))}} impl FnOnce < (char ,) > for CharEscapeUnicode {type Output = char :: EscapeUnicode ; # [inline] extern \"rust-call\" fn call_once (self , (c ,) : (char ,)) -> char :: EscapeUnicode {Fn :: call (& self , (c ,))}} # [derive (Clone)] struct CharEscapeDefault ; impl Fn < (char ,) > for CharEscapeDefault {# [inline] extern \"rust-call\" fn call (& self , (c ,) : (char ,)) -> char :: EscapeDefault {{c . escape_default ()}}} impl FnMut < (char ,) > for CharEscapeDefault {# [inline] extern \"rust-call\" fn call_mut (& mut self , (c ,) : (char ,)) -> char :: EscapeDefault {Fn :: call (&* self , (c ,))}} impl FnOnce < (char ,) > for CharEscapeDefault {type Output = char :: EscapeDefault ; # [inline] extern \"rust-call\" fn call_once (self , (c ,) : (char ,)) -> char :: EscapeDefault {Fn :: call (& self , (c ,))}}"); 1231 "# [derive (Clone)] struct CharEscapeDebugContinue ; impl Fn < (char ,) > for CharEscapeDebugContinue {# [inline] extern \"rust-call\" fn call (& self , (c ,) : (char ,)) -> char :: EscapeDebug {{c . escape_debug_ext (false)}}} impl FnMut < (char ,) > for CharEscapeDebugContinue {# [inline] extern \"rust-call\" fn call_mut (& mut self , (c ,) : (char ,)) -> char :: EscapeDebug {Fn :: call (&* self , (c ,))}} impl FnOnce < (char ,) > for CharEscapeDebugContinue {type Output = char :: EscapeDebug ; # [inline] extern \"rust-call\" fn call_once (self , (c ,) : (char ,)) -> char :: EscapeDebug {Fn :: call (& self , (c ,))}} # [derive (Clone)] struct CharEscapeUnicode ; impl Fn < (char ,) > for CharEscapeUnicode {# [inline] extern \"rust-call\" fn call (& self , (c ,) : (char ,)) -> char :: EscapeUnicode {{c . escape_unicode ()}}} impl FnMut < (char ,) > for CharEscapeUnicode {# [inline] extern \"rust-call\" fn call_mut (& mut self , (c ,) : (char ,)) -> char :: EscapeUnicode {Fn :: call (&* self , (c ,))}} impl FnOnce < (char ,) > for CharEscapeUnicode {type Output = char :: EscapeUnicode ; # [inline] extern \"rust-call\" fn call_once (self , (c ,) : (char ,)) -> char :: EscapeUnicode {Fn :: call (& self , (c ,))}} # [derive (Clone)] struct CharEscapeDefault ; impl Fn < (char ,) > for CharEscapeDefault {# [inline] extern \"rust-call\" fn call (& self , (c ,) : (char ,)) -> char :: EscapeDefault {{c . escape_default ()}}} impl FnMut < (char ,) > for CharEscapeDefault {# [inline] extern \"rust-call\" fn call_mut (& mut self , (c ,) : (char ,)) -> char :: EscapeDefault {Fn :: call (&* self , (c ,))}} impl FnOnce < (char ,) > for CharEscapeDefault {type Output = char :: EscapeDefault ; # [inline] extern \"rust-call\" fn call_once (self , (c ,) : (char ,)) -> char :: EscapeDefault {Fn :: call (& self , (c ,))}}");
1233} 1232}
1234 1233
@@ -1263,7 +1262,7 @@ fn test_cfg_if_items() {
1263"#, 1262"#,
1264 ); 1263 );
1265 1264
1266 assert_expansion(MacroKind::Items, &rules, r#"__cfg_if_items ! { ( rustdoc , ) ; ( ( ) ( # [ cfg ( any ( target_os = "redox" , unix ) ) ] # [ stable ( feature = "rust1" , since = "1.0.0" ) ] pub use sys :: ext as unix ; # [ cfg ( windows ) ] # [ stable ( feature = "rust1" , since = "1.0.0" ) ] pub use sys :: ext as windows ; # [ cfg ( any ( target_os = "linux" , target_os = "l4re" ) ) ] pub mod linux ; ) ) , }"#, 1265 assert_expansion(MacroKind::Items, &rules, r#"__cfg_if_items ! { ( rustdoc , ) ; ( ( ) ( # [ cfg ( any ( target_os = "redox" , unix ) ) ] # [ stable ( feature = "rust1" , since = "1.0.0" ) ] pub use sys :: ext as unix ; # [ cfg ( windows ) ] # [ stable ( feature = "rust1" , since = "1.0.0" ) ] pub use sys :: ext as windows ; # [ cfg ( any ( target_os = "linux" , target_os = "l4re" ) ) ] pub mod linux ; ) ) , }"#,
1267 "__cfg_if_items ! {(rustdoc ,) ;}"); 1266 "__cfg_if_items ! {(rustdoc ,) ;}");
1268} 1267}
1269 1268
@@ -1294,23 +1293,23 @@ fn test_cfg_if_main() {
1294 ); 1293 );
1295 1294
1296 assert_expansion(MacroKind::Items, &rules, r#" 1295 assert_expansion(MacroKind::Items, &rules, r#"
1297cfg_if ! { 1296cfg_if ! {
1298 if # [ cfg ( target_env = "msvc" ) ] { 1297 if # [ cfg ( target_env = "msvc" ) ] {
1299 // no extra unwinder support needed 1298 // no extra unwinder support needed
1300 } else if # [ cfg ( all ( target_arch = "wasm32" , not ( target_os = "emscripten" ) ) ) ] { 1299 } else if # [ cfg ( all ( target_arch = "wasm32" , not ( target_os = "emscripten" ) ) ) ] {
1301 // no unwinder on the system! 1300 // no unwinder on the system!
1302 } else { 1301 } else {
1303 mod libunwind ; 1302 mod libunwind ;
1304 pub use libunwind :: * ; 1303 pub use libunwind :: * ;
1305 } 1304 }
1306 } 1305 }
1307"#, 1306"#,
1308 "__cfg_if_items ! {() ; ((target_env = \"msvc\") ()) , ((all (target_arch = \"wasm32\" , not (target_os = \"emscripten\"))) ()) , (() (mod libunwind ; pub use libunwind :: * ;)) ,}"); 1307 "__cfg_if_items ! {() ; ((target_env = \"msvc\") ()) , ((all (target_arch = \"wasm32\" , not (target_os = \"emscripten\"))) ()) , (() (mod libunwind ; pub use libunwind :: * ;)) ,}");
1309 1308
1310 assert_expansion(MacroKind::Items, &rules, r#" 1309 assert_expansion(MacroKind::Items, &rules, r#"
1311cfg_if ! { @ __apply cfg ( all ( not ( any ( not ( any ( target_os = "solaris" , target_os = "illumos" ) ) ) ) ) ) , } 1310cfg_if ! { @ __apply cfg ( all ( not ( any ( not ( any ( target_os = "solaris" , target_os = "illumos" ) ) ) ) ) ) , }
1312"#, 1311"#,
1313 "" 1312 ""
1314 ); 1313 );
1315} 1314}
1316 1315
@@ -1329,16 +1328,16 @@ macro_rules! arbitrary {
1329 $logic 1328 $logic
1330 } 1329 }
1331 } 1330 }
1332 }; 1331 };
1333 1332
1334}"#, 1333}"#,
1335 ); 1334 );
1336 1335
1337 assert_expansion(MacroKind::Items, &rules, r#"arbitrary ! ( [ A : Arbitrary ] 1336 assert_expansion(MacroKind::Items, &rules, r#"arbitrary ! ( [ A : Arbitrary ]
1338 Vec < A > , 1337 Vec < A > ,
1339 VecStrategy < A :: Strategy > , 1338 VecStrategy < A :: Strategy > ,
1340 RangedParams1 < A :: Parameters > ; 1339 RangedParams1 < A :: Parameters > ;
1341 args => { let product_unpack ! [ range , a ] = args ; vec ( any_with :: < A > ( a ) , range ) } 1340 args => { let product_unpack ! [ range , a ] = args ; vec ( any_with :: < A > ( a ) , range ) }
1342 ) ;"#, 1341 ) ;"#,
1343 "impl <A : Arbitrary > $crate :: arbitrary :: Arbitrary for Vec < A > {type Parameters = RangedParams1 < A :: Parameters > ; type Strategy = VecStrategy < A :: Strategy > ; fn arbitrary_with (args : Self :: Parameters) -> Self :: Strategy {{let product_unpack ! [range , a] = args ; vec (any_with :: < A > (a) , range)}}}"); 1342 "impl <A : Arbitrary > $crate :: arbitrary :: Arbitrary for Vec < A > {type Parameters = RangedParams1 < A :: Parameters > ; type Strategy = VecStrategy < A :: Strategy > ; fn arbitrary_with (args : Self :: Parameters) -> Self :: Strategy {{let product_unpack ! [range , a] = args ; vec (any_with :: < A > (a) , range)}}}");
1344} 1343}
@@ -1350,7 +1349,7 @@ fn test_old_ridl() {
1350 let rules = create_rules( 1349 let rules = create_rules(
1351 r#" 1350 r#"
1352#[macro_export] 1351#[macro_export]
1353macro_rules! RIDL { 1352macro_rules! RIDL {
1354 (interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident) 1353 (interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident)
1355 {$( 1354 {$(
1356 fn $method:ident(&mut self $(,$p:ident : $t:ty)*) -> $rtr:ty 1355 fn $method:ident(&mut self $(,$p:ident : $t:ty)*) -> $rtr:ty
@@ -1360,7 +1359,7 @@ macro_rules! RIDL {
1360 $(pub unsafe fn $method(&mut self) -> $rtr { 1359 $(pub unsafe fn $method(&mut self) -> $rtr {
1361 ((*self.lpVtbl).$method)(self $(,$p)*) 1360 ((*self.lpVtbl).$method)(self $(,$p)*)
1362 })+ 1361 })+
1363 } 1362 }
1364 }; 1363 };
1365}"#, 1364}"#,
1366 ); 1365 );
@@ -1388,11 +1387,11 @@ macro_rules! quick_error {
1388 quick_error!(ENUM_DEFINITION [enum $name $( #[$meta] )*] 1387 quick_error!(ENUM_DEFINITION [enum $name $( #[$meta] )*]
1389 body [] 1388 body []
1390 queue [$( 1389 queue [$(
1391 $( #[$imeta] )* 1390 $( #[$imeta] )*
1392 => 1391 =>
1393 $iitem: $imode [$( $ivar: $ityp ),*] 1392 $iitem: $imode [$( $ivar: $ityp ),*]
1394 )*] 1393 )*]
1395 ); 1394 );
1396}; 1395};
1397 1396
1398} 1397}
@@ -1403,7 +1402,7 @@ macro_rules! quick_error {
1403 &rules, 1402 &rules,
1404 r#" 1403 r#"
1405quick_error ! (SORT [enum Wrapped # [derive (Debug)]] items [ 1404quick_error ! (SORT [enum Wrapped # [derive (Debug)]] items [
1406 => One : UNIT [] {} 1405 => One : UNIT [] {}
1407 => Two : TUPLE [s :String] {display ("two: {}" , s) from ()} 1406 => Two : TUPLE [s :String] {display ("two: {}" , s) from ()}
1408 ] buf [] queue []) ; 1407 ] buf [] queue []) ;
1409"#, 1408"#,