diff --git a/crates/hir_def/src/macro_expansion_tests.rs b/crates/hir_def/src/macro_expansion_tests.rs index 0a9ab931572..d96af5c4070 100644 --- a/crates/hir_def/src/macro_expansion_tests.rs +++ b/crates/hir_def/src/macro_expansion_tests.rs @@ -65,6 +65,11 @@ fn check(ra_fixture: &str, mut expect: Expect) { format_to!(expn_text, "/* error: {} */", err); } if let Some((parse, _token_map)) = exp.value { + assert!( + parse.errors().is_empty(), + "parse errors in expansion: \n{:#?}", + parse.errors() + ); let pp = pretty_print_macro_expansion(parse.syntax_node()); let indent = IndentLevel::from_node(call.syntax()); let pp = reindent(indent, pp); diff --git a/crates/hir_def/src/macro_expansion_tests/mbe.rs b/crates/hir_def/src/macro_expansion_tests/mbe.rs index 7c9a19613b9..06ef8f35726 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe.rs @@ -165,17 +165,17 @@ fn test_match_group_pattern_with_multiple_defs() { check( r#" macro_rules! m { - ($($i:ident),*) => ( impl Bar { $(fn $i {})* } ); + ($($i:ident),*) => ( impl Bar { $(fn $i() {})* } ); } m! { foo, bar } "#, expect![[r#" macro_rules! m { - ($($i:ident),*) => ( impl Bar { $(fn $i {})* } ); + ($($i:ident),*) => ( impl Bar { $(fn $i() {})* } ); } impl Bar { - fn foo {} - fn bar {} + fn foo() {} + fn bar() {} } "#]], ); @@ -186,15 +186,15 @@ fn test_match_group_pattern_with_multiple_statement() { check( r#" macro_rules! m { - ($($i:ident),*) => ( fn baz { $($i ();)* } ); + ($($i:ident),*) => ( fn baz() { $($i ();)* } ); } m! { foo, bar } "#, expect![[r#" macro_rules! m { - ($($i:ident),*) => ( fn baz { $($i ();)* } ); + ($($i:ident),*) => ( fn baz() { $($i ();)* } ); } -fn baz { +fn baz() { foo(); bar(); } @@ -207,15 +207,15 @@ fn test_match_group_pattern_with_multiple_statement_without_semi() { check( r#" macro_rules! m { - ($($i:ident),*) => ( fn baz { $($i() );* } ); + ($($i:ident),*) => ( fn baz() { $($i() );* } ); } m! { foo, bar } "#, expect![[r#" macro_rules! m { - ($($i:ident),*) => ( fn baz { $($i() );* } ); + ($($i:ident),*) => ( fn baz() { $($i() );* } ); } -fn baz { +fn baz() { foo(); bar() } @@ -228,15 +228,15 @@ fn test_match_group_empty_fixed_token() { check( r#" macro_rules! m { - ($($i:ident)* #abc) => ( fn baz { $($i ();)* } ); + ($($i:ident)* #abc) => ( fn baz() { $($i ();)* } ); } m!{#abc} "#, expect![[r##" macro_rules! m { - ($($i:ident)* #abc) => ( fn baz { $($i ();)* } ); + ($($i:ident)* #abc) => ( fn baz() { $($i ();)* } ); } -fn baz {} +fn baz() {} "##]], ) } @@ -248,7 +248,7 @@ fn test_match_group_in_subtree() { macro_rules! m { (fn $name:ident { $($i:ident)* } ) => ( fn $name() { $($i ();)* } ); } -m! {fn baz { a b } } +m! { fn baz { a b } } "#, expect![[r#" macro_rules! m { diff --git a/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs b/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs index 11317cfa9d5..5bdabfc598b 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs @@ -8,18 +8,18 @@ use crate::macro_expansion_tests::check; fn unary_minus_is_a_literal() { check( r#" -macro_rules! m { ($x:literal) => (literal!()); ($x:tt) => (not_a_literal!()); } +macro_rules! m { ($x:literal) => (literal!();); ($x:tt) => (not_a_literal!();); } m!(92); m!(-92); m!(-9.2); m!(--92); "#, expect![[r#" -macro_rules! m { ($x:literal) => (literal!()); ($x:tt) => (not_a_literal!()); } -literal!() -literal!() -literal!() -/* error: leftover tokens */not_a_literal!() +macro_rules! m { ($x:literal) => (literal!();); ($x:tt) => (not_a_literal!();); } +literal!(); +literal!(); +literal!(); +/* error: leftover tokens */not_a_literal!(); "#]], ) } 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 4249c2507e9..d434c882449 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 @@ -16,7 +16,7 @@ macro_rules! m { ($($i:ident)*) => ($_); ($($true:ident)*) => ($true); ($($false:ident)*) => ($false); - ($) => ($); + ($) => (m!($);); } m!($); "#, @@ -29,9 +29,9 @@ macro_rules! m { ($($i:ident)*) => ($_); ($($true:ident)*) => ($true); ($($false:ident)*) => ($false); - ($) => ($); + ($) => (m!($);); } -$ +m!($); "#]], ) } diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index 132d300674d..24a099cb3cc 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs @@ -89,6 +89,9 @@ impl Parse { pub fn syntax_node(&self) -> SyntaxNode { SyntaxNode::new_root(self.green.clone()) } + pub fn errors(&self) -> &[SyntaxError] { + &*self.errors + } } impl Parse { @@ -100,10 +103,6 @@ impl Parse { T::cast(self.syntax_node()).unwrap() } - pub fn errors(&self) -> &[SyntaxError] { - &*self.errors - } - pub fn ok(self) -> Result>> { if self.errors.is_empty() { Ok(self.tree())