diff --git a/crates/hir_def/src/macro_expansion_tests.rs b/crates/hir_def/src/macro_expansion_tests.rs index d96af5c4070..60c9fd7d0a5 100644 --- a/crates/hir_def/src/macro_expansion_tests.rs +++ b/crates/hir_def/src/macro_expansion_tests.rs @@ -123,6 +123,9 @@ fn pretty_print_macro_expansion(expn: SyntaxNode) -> String { (IDENT | LIFETIME_IDENT, IDENT | LIFETIME_IDENT) => " ", (IDENT, _) if curr_kind.is_keyword() => " ", (_, IDENT) if prev_kind.is_keyword() => " ", + (T![>], IDENT) => " ", + (T![>], _) if curr_kind.is_keyword() => " ", + (T![->], _) | (_, T![->]) => " ", _ => "", }; @@ -133,8 +136,9 @@ fn pretty_print_macro_expansion(expn: SyntaxNode) -> String { } res.push_str(space); - if space == "\n" && curr_kind != T!['}'] { - res.push_str(&" ".repeat(indent_level)); + if space == "\n" { + let level = if curr_kind == T!['}'] { indent_level - 1 } else { indent_level }; + res.push_str(&" ".repeat(level)); } prev_kind = curr_kind; format_to!(res, "{}", token) diff --git a/crates/hir_def/src/macro_expansion_tests/mbe.rs b/crates/hir_def/src/macro_expansion_tests/mbe.rs index 06ef8f35726..c7442bade6e 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe.rs @@ -9,6 +9,45 @@ use crate::macro_expansion_tests::check; +#[test] +fn mbe_smoke_test() { + check( + r#" +macro_rules! impl_froms { + ($e:ident: $($v:ident),*) => { + $( + impl From<$v> for $e { + fn from(it: $v) -> $e { $e::$v(it) } + } + )* + } +} +impl_froms!(TokenTree: Leaf, Subtree); +"#, + expect![[r#" +macro_rules! impl_froms { + ($e:ident: $($v:ident),*) => { + $( + impl From<$v> for $e { + fn from(it: $v) -> $e { $e::$v(it) } + } + )* + } +} +impl From for TokenTree { + fn from(it:Leaf) -> TokenTree { + TokenTree::Leaf(it) + } +} +impl From for TokenTree { + fn from(it:Subtree) -> TokenTree { + TokenTree::Subtree(it) + } +} +"#]], + ); +} + #[test] fn expansion_does_not_parse_as_expression() { check( diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs index 85a51588ebe..d0eb49455b7 100644 --- a/crates/mbe/src/tests/expand.rs +++ b/crates/mbe/src/tests/expand.rs @@ -71,102 +71,6 @@ macro_rules! foobar { assert_eq!(get_text(tt::TokenId(13), T!['{']), "{"); } -#[test] -fn test_convert_tt() { - parse_macro(r#" -macro_rules! impl_froms { - ($e:ident: $($v:ident),*) => { - $( - impl From<$v> for $e { - fn from(it: $v) -> $e { - $e::$v(it) - } - } - )* - } -} -"#) - .assert_expand_tt( - "impl_froms!(TokenTree: Leaf, Subtree);", - "impl From for TokenTree {fn from (it : Leaf) -> TokenTree {TokenTree ::Leaf (it)}} \ - impl From for TokenTree {fn from (it : Subtree) -> TokenTree {TokenTree ::Subtree (it)}}" - ); -} - -#[test] -fn test_convert_tt2() { - parse_macro( - r#" -macro_rules! impl_froms { - ($e:ident: $($v:ident),*) => { - $( - impl From<$v> for $e { - fn from(it: $v) -> $e { - $e::$v(it) - } - } - )* - } -} -"#, - ) - .assert_expand( - "impl_froms!(TokenTree: Leaf, Subtree);", - r#" -SUBTREE $ - IDENT impl 20 - IDENT From 21 - PUNCH < [joint] 22 - IDENT Leaf 53 - PUNCH > [alone] 25 - IDENT for 26 - IDENT TokenTree 51 - SUBTREE {} 29 - IDENT fn 30 - IDENT from 31 - SUBTREE () 32 - IDENT it 33 - PUNCH : [alone] 34 - IDENT Leaf 53 - PUNCH - [joint] 37 - PUNCH > [alone] 38 - IDENT TokenTree 51 - SUBTREE {} 41 - IDENT TokenTree 51 - PUNCH : [joint] 44 - PUNCH : [joint] 45 - IDENT Leaf 53 - SUBTREE () 48 - IDENT it 49 - IDENT impl 20 - IDENT From 21 - PUNCH < [joint] 22 - IDENT Subtree 55 - PUNCH > [alone] 25 - IDENT for 26 - IDENT TokenTree 51 - SUBTREE {} 29 - IDENT fn 30 - IDENT from 31 - SUBTREE () 32 - IDENT it 33 - PUNCH : [alone] 34 - IDENT Subtree 55 - PUNCH - [joint] 37 - PUNCH > [alone] 38 - IDENT TokenTree 51 - SUBTREE {} 41 - IDENT TokenTree 51 - PUNCH : [joint] 44 - PUNCH : [joint] 45 - IDENT Subtree 55 - SUBTREE () 48 - IDENT it 49 -"#, - ); -} - - #[test] fn test_match_group_with_multichar_sep() { parse_macro(