diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index c7c06c7fd6..f185aecb71 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -599,7 +599,8 @@ mod tests { let macro_definition = source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); - let (definition_tt, _) = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap(); + let (definition_tt, _) = + ast_to_token_tree(¯o_definition.token_tree().unwrap()).unwrap(); crate::MacroRules::parse(&definition_tt).unwrap() } @@ -611,7 +612,8 @@ mod tests { let macro_invocation = source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); - let (invocation_tt, _) = ast_to_token_tree(macro_invocation.token_tree().unwrap()).unwrap(); + let (invocation_tt, _) = + ast_to_token_tree(¯o_invocation.token_tree().unwrap()).unwrap(); expand_rule(&rules.rules[0], &invocation_tt) } diff --git a/crates/ra_mbe/src/mbe_parser.rs b/crates/ra_mbe/src/mbe_parser.rs index cddb4a7b4c..954b84d9d7 100644 --- a/crates/ra_mbe/src/mbe_parser.rs +++ b/crates/ra_mbe/src/mbe_parser.rs @@ -179,7 +179,8 @@ mod tests { let macro_definition = source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); - let (definition_tt, _) = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap(); + let (definition_tt, _) = + ast_to_token_tree(¯o_definition.token_tree().unwrap()).unwrap(); parse(&definition_tt) } diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index bfc351f81a..64ed6a517d 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -2,7 +2,7 @@ use crate::subtree_source::SubtreeTokenSource; use crate::ExpandError; use ra_parser::{ParseError, TreeSink}; use ra_syntax::{ - ast, AstNode, Parse, SmolStr, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxNode, + ast, AstNode, AstToken, Parse, SmolStr, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxNode, SyntaxTreeBuilder, TextRange, TextUnit, T, }; use tt::buffer::{Cursor, TokenBuffer}; @@ -116,8 +116,6 @@ impl TokenMap { /// and strips the ending `*/` /// And then quote the string, which is needed to convert to `tt::Literal` fn doc_comment_text(comment: &ast::Comment) -> SmolStr { - use ast::AstToken; - let prefix_len = comment.prefix().len(); let mut text = &comment.text()[prefix_len..]; @@ -132,9 +130,8 @@ fn doc_comment_text(comment: &ast::Comment) -> SmolStr { text.into() } -fn convert_doc_comment<'a>(token: &ra_syntax::SyntaxToken<'a>) -> Option> { - use ast::AstToken; - let comment = ast::Comment::cast(*token)?; +fn convert_doc_comment(token: &ra_syntax::SyntaxToken) -> Option> { + let comment = ast::Comment::cast(token.clone())?; let doc = comment.kind().doc?; // Make `doc="\" Comments\"" @@ -245,7 +242,7 @@ fn convert_tt( } } SyntaxElement::Node(node) => { - let child = convert_tt(token_map, global_offset, node)?.into(); + let child = convert_tt(token_map, global_offset, &node)?.into(); token_trees.push(child); } }; diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index 419b2c099c..38a31109d9 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs @@ -37,8 +37,8 @@ impl_froms!(TokenTree: Leaf, Subtree); let macro_invocation = source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); - let (definition_tt, _) = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap(); - let (invocation_tt, _) = ast_to_token_tree(macro_invocation.token_tree().unwrap()).unwrap(); + let (definition_tt, _) = ast_to_token_tree(¯o_definition.token_tree().unwrap()).unwrap(); + let (invocation_tt, _) = ast_to_token_tree(¯o_invocation.token_tree().unwrap()).unwrap(); let rules = crate::MacroRules::parse(&definition_tt).unwrap(); let expansion = rules.expand(&invocation_tt).unwrap(); assert_eq!( @@ -53,7 +53,7 @@ pub(crate) fn create_rules(macro_definition: &str) -> MacroRules { let macro_definition = source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); - let (definition_tt, _) = ast_to_token_tree(macro_definition.token_tree().unwrap()).unwrap(); + let (definition_tt, _) = ast_to_token_tree(¯o_definition.token_tree().unwrap()).unwrap(); crate::MacroRules::parse(&definition_tt).unwrap() } @@ -62,34 +62,25 @@ pub(crate) fn expand(rules: &MacroRules, invocation: &str) -> tt::Subtree { let macro_invocation = source_file.syntax().descendants().find_map(ast::MacroCall::cast).unwrap(); - let (invocation_tt, _) = ast_to_token_tree(macro_invocation.token_tree().unwrap()).unwrap(); + let (invocation_tt, _) = ast_to_token_tree(¯o_invocation.token_tree().unwrap()).unwrap(); rules.expand(&invocation_tt).unwrap() } -pub(crate) fn expand_to_items( - rules: &MacroRules, - invocation: &str, -) -> ra_syntax::TreeArc { +pub(crate) fn expand_to_items(rules: &MacroRules, invocation: &str) -> ast::MacroItems { let expanded = expand(rules, invocation); - token_tree_to_macro_items(&expanded).unwrap().tree().to_owned() + token_tree_to_macro_items(&expanded).unwrap().tree() } #[allow(unused)] -pub(crate) fn expand_to_stmts( - rules: &MacroRules, - invocation: &str, -) -> ra_syntax::TreeArc { +pub(crate) fn expand_to_stmts(rules: &MacroRules, invocation: &str) -> ast::MacroStmts { let expanded = expand(rules, invocation); - token_tree_to_macro_stmts(&expanded).unwrap().tree().to_owned() + token_tree_to_macro_stmts(&expanded).unwrap().tree() } -pub(crate) fn expand_to_expr( - rules: &MacroRules, - invocation: &str, -) -> ra_syntax::TreeArc { +pub(crate) fn expand_to_expr(rules: &MacroRules, invocation: &str) -> ast::Expr { let expanded = expand(rules, invocation); - token_tree_to_expr(&expanded).unwrap().tree().to_owned() + token_tree_to_expr(&expanded).unwrap().tree() } pub(crate) fn text_to_tokentree(text: &str) -> tt::Subtree { @@ -97,7 +88,7 @@ pub(crate) fn text_to_tokentree(text: &str) -> tt::Subtree { let wrapped = format!("wrap_macro!( {} )", text); let wrapped = ast::SourceFile::parse(&wrapped); let wrapped = wrapped.tree().syntax().descendants().find_map(ast::TokenTree::cast).unwrap(); - let mut wrapped = ast_to_token_tree(wrapped).unwrap().0; + let mut wrapped = ast_to_token_tree(&wrapped).unwrap().0; wrapped.delimiter = tt::Delimiter::None; wrapped @@ -164,8 +155,8 @@ pub(crate) fn assert_expansion( let (expanded_tree, expected_tree) = match kind { MacroKind::Items => { - let expanded_tree = token_tree_to_macro_items(&expanded).unwrap().tree().to_owned(); - let expected_tree = token_tree_to_macro_items(&expected).unwrap().tree().to_owned(); + let expanded_tree = token_tree_to_macro_items(&expanded).unwrap().tree(); + let expected_tree = token_tree_to_macro_items(&expected).unwrap().tree(); ( debug_dump_ignore_spaces(expanded_tree.syntax()).trim().to_string(), @@ -174,8 +165,8 @@ pub(crate) fn assert_expansion( } MacroKind::Stmts => { - let expanded_tree = token_tree_to_macro_stmts(&expanded).unwrap().tree().to_owned(); - let expected_tree = token_tree_to_macro_stmts(&expected).unwrap().tree().to_owned(); + let expanded_tree = token_tree_to_macro_stmts(&expanded).unwrap().tree(); + let expected_tree = token_tree_to_macro_stmts(&expected).unwrap().tree(); ( debug_dump_ignore_spaces(expanded_tree.syntax()).trim().to_string(), @@ -419,7 +410,7 @@ fn test_expand_to_item_list() { ", ); let expansion = expand(&rules, "structs!(Foo, Bar);"); - let tree = token_tree_to_macro_items(&expansion).unwrap().tree().to_owned(); + let tree = token_tree_to_macro_items(&expansion).unwrap().tree(); assert_eq!( tree.syntax().debug_dump().trim(), r#" @@ -537,7 +528,7 @@ fn test_tt_to_stmts() { ); let expanded = expand(&rules, "foo!{}"); - let stmts = token_tree_to_macro_stmts(&expanded).unwrap().tree().to_owned(); + let stmts = token_tree_to_macro_stmts(&expanded).unwrap().tree(); assert_eq!( stmts.syntax().debug_dump().trim(),