Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/hir_def/src/macro_expansion_tests/mbe/meta_syntax.rs | 61 | ||||
| -rw-r--r-- | crates/hir_def/src/macro_expansion_tests/mbe/regression.rs | 21 | ||||
| -rw-r--r-- | crates/mbe/src/tests.rs | 9 | ||||
| -rw-r--r-- | crates/mbe/src/tests/expand.rs | 79 |
4 files changed, 82 insertions, 88 deletions
diff --git a/crates/hir_def/src/macro_expansion_tests/mbe/meta_syntax.rs b/crates/hir_def/src/macro_expansion_tests/mbe/meta_syntax.rs index d434c88244..dd5effa368 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe/meta_syntax.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe/meta_syntax.rs @@ -77,3 +77,64 @@ macro_rules! f3 { ($i:_) => () } "#]], ) } + +#[test] +fn test_rustc_issue_57597() { + // <https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-57597.rs> + check( + r#" +macro_rules! m0 { ($($($i:ident)?)+) => {}; } +macro_rules! m1 { ($($($i:ident)?)*) => {}; } +macro_rules! m2 { ($($($i:ident)?)?) => {}; } +macro_rules! m3 { ($($($($i:ident)?)?)?) => {}; } +macro_rules! m4 { ($($($($i:ident)*)?)?) => {}; } +macro_rules! m5 { ($($($($i:ident)?)*)?) => {}; } +macro_rules! m6 { ($($($($i:ident)?)?)*) => {}; } +macro_rules! m7 { ($($($($i:ident)*)*)?) => {}; } +macro_rules! m8 { ($($($($i:ident)?)*)*) => {}; } +macro_rules! m9 { ($($($($i:ident)?)*)+) => {}; } +macro_rules! mA { ($($($($i:ident)+)?)*) => {}; } +macro_rules! mB { ($($($($i:ident)+)*)?) => {}; } + +m0!(); +m1!(); +m2!(); +m3!(); +m4!(); +m5!(); +m6!(); +m7!(); +m8!(); +m9!(); +mA!(); +mB!(); + "#, + expect![[r#" +macro_rules! m0 { ($($($i:ident)?)+) => {}; } +macro_rules! m1 { ($($($i:ident)?)*) => {}; } +macro_rules! m2 { ($($($i:ident)?)?) => {}; } +macro_rules! m3 { ($($($($i:ident)?)?)?) => {}; } +macro_rules! m4 { ($($($($i:ident)*)?)?) => {}; } +macro_rules! m5 { ($($($($i:ident)?)*)?) => {}; } +macro_rules! m6 { ($($($($i:ident)?)?)*) => {}; } +macro_rules! m7 { ($($($($i:ident)*)*)?) => {}; } +macro_rules! m8 { ($($($($i:ident)?)*)*) => {}; } +macro_rules! m9 { ($($($($i:ident)?)*)+) => {}; } +macro_rules! mA { ($($($($i:ident)+)?)*) => {}; } +macro_rules! mB { ($($($($i:ident)+)*)?) => {}; } + +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ +/* error: invalid macro definition: empty token tree in repetition */ + "#]], + ); +} diff --git a/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs b/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs index 5e23ca88fa..563fe50588 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs @@ -879,3 +879,24 @@ pub fn new() { "#]], ); } + +#[test] +fn test_no_space_after_semi_colon() { + check( + r#" +macro_rules! with_std { + ($($i:item)*) => ($(#[cfg(feature = "std")]$i)*) +} + +with_std! {mod m;mod f;} +"#, + expect![[r##" +macro_rules! with_std { + ($($i:item)*) => ($(#[cfg(feature = "std")]$i)*) +} + +#[cfg(feature = "std")] mod m; +#[cfg(feature = "std")] mod f; +"##]], + ) +} diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs index 64d80baa3e..78e24a37e6 100644 --- a/crates/mbe/src/tests.rs +++ b/crates/mbe/src/tests.rs @@ -141,15 +141,6 @@ pub(crate) fn parse_macro(ra_fixture: &str) -> MacroFixture { MacroFixture { rules } } -pub(crate) fn parse_macro_error(ra_fixture: &str) -> ParseError { - let definition_tt = parse_macro_rules_to_tt(ra_fixture); - - match MacroRules::parse(&definition_tt) { - Ok(_) => panic!("Expect error"), - Err(err) => err, - } -} - pub(crate) fn parse_to_token_tree_by_syntax(ra_fixture: &str) -> tt::Subtree { let source_file = ast::SourceFile::parse(ra_fixture).ok().unwrap(); let tt = syntax_node_to_token_tree(source_file.syntax()).0; diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs index ffb24709f2..8a23a0be53 100644 --- a/crates/mbe/src/tests/expand.rs +++ b/crates/mbe/src/tests/expand.rs @@ -1,6 +1,5 @@ use ::parser::ParserEntryPoint; use syntax::{SyntaxKind::IDENT, T}; -use test_utils::assert_eq_text; use super::*; @@ -98,84 +97,6 @@ fn test_attr_to_token_tree() { ); } - -#[test] -fn test_no_space_after_semi_colon() { - let expanded = parse_macro( - r#" - macro_rules! with_std { ($($i:item)*) => ($(#[cfg(feature = "std")]$i)*) } - "#, - ) - .expand_items(r#"with_std! {mod m;mod f;}"#); - - let dump = format!("{:#?}", expanded); - assert_eq_text!( - r###"[email protected] - [email protected] "#" - [email protected] "[" - [email protected] "cfg" - [email protected] "(" - [email protected] "feature" - [email protected] "=" - [email protected] "\"std\"" - [email protected] ")" - [email protected] "]" - [email protected] "mod" - [email protected] "m" - [email protected] ";" - [email protected] "#" - [email protected] "[" - [email protected] "cfg" - [email protected] "(" - [email protected] "feature" - [email protected] "=" - [email protected] "\"std\"" - [email protected] ")" - [email protected] "]" - [email protected] "mod" - [email protected] "f" - [email protected] ";""###, - dump.trim() - ); -} - -// https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-57597.rs -#[test] -fn test_rustc_issue_57597() { - fn test_error(fixture: &str) { - assert_eq!(parse_macro_error(fixture), ParseError::RepetitionEmptyTokenTree); - } - - test_error("macro_rules! foo { ($($($i:ident)?)+) => {}; }"); - test_error("macro_rules! foo { ($($($i:ident)?)*) => {}; }"); - test_error("macro_rules! foo { ($($($i:ident)?)?) => {}; }"); - test_error("macro_rules! foo { ($($($($i:ident)?)?)?) => {}; }"); - test_error("macro_rules! foo { ($($($($i:ident)*)?)?) => {}; }"); - test_error("macro_rules! foo { ($($($($i:ident)?)*)?) => {}; }"); - test_error("macro_rules! foo { ($($($($i:ident)?)?)*) => {}; }"); - test_error("macro_rules! foo { ($($($($i:ident)*)*)?) => {}; }"); - test_error("macro_rules! foo { ($($($($i:ident)?)*)*) => {}; }"); - test_error("macro_rules! foo { ($($($($i:ident)?)*)+) => {}; }"); - test_error("macro_rules! foo { ($($($($i:ident)+)?)*) => {}; }"); - test_error("macro_rules! foo { ($($($($i:ident)+)*)?) => {}; }"); -} - #[test] fn test_expand_bad_literal() { parse_macro( |