From bdb7ae5dd055e5ee4ab7b2e008f4299172a67709 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 9 Feb 2022 12:00:03 +0100 Subject: [PATCH] Rename syntax_node_to_token_tree_censored --- crates/hir_expand/src/db.rs | 10 ++++++---- crates/hir_expand/src/fixup.rs | 2 +- crates/mbe/src/lib.rs | 2 +- crates/mbe/src/syntax_bridge.rs | 5 ++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index eea02898d2..65799e0be5 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs @@ -151,8 +151,11 @@ pub fn expand_speculative( let censor = censor_for_macro_input(&loc, &speculative_args); let mut fixups = fixup::fixup_syntax(&speculative_args); fixups.replace.extend(censor.into_iter().map(|node| (node, Vec::new()))); - let (mut tt, spec_args_tmap) = - mbe::syntax_node_to_token_tree_censored(&speculative_args, fixups.replace, fixups.append); + let (mut tt, spec_args_tmap) = mbe::syntax_node_to_token_tree_with_modifications( + &speculative_args, + fixups.replace, + fixups.append, + ); let (attr_arg, token_id) = match loc.kind { MacroCallKind::Attr { invoc_attr_index, .. } => { @@ -303,11 +306,10 @@ fn macro_arg( let node = SyntaxNode::new_root(arg); let censor = censor_for_macro_input(&loc, &node); - // TODO only fixup for attribute macro input let mut fixups = fixup::fixup_syntax(&node); fixups.replace.extend(censor.into_iter().map(|node| (node, Vec::new()))); let (mut tt, tmap) = - mbe::syntax_node_to_token_tree_censored(&node, fixups.replace, fixups.append); + mbe::syntax_node_to_token_tree_with_modifications(&node, fixups.replace, fixups.append); if loc.def.is_proc_macro() { // proc macros expect their inputs without parentheses, MBEs expect it with them included diff --git a/crates/hir_expand/src/fixup.rs b/crates/hir_expand/src/fixup.rs index c98d20e456..f2d43f4d69 100644 --- a/crates/hir_expand/src/fixup.rs +++ b/crates/hir_expand/src/fixup.rs @@ -123,7 +123,7 @@ mod tests { let parsed = syntax::SourceFile::parse(ra_fixture); eprintln!("parse: {:#?}", parsed.syntax_node()); let fixups = super::fixup_syntax(&parsed.syntax_node()); - let (mut tt, tmap) = mbe::syntax_node_to_token_tree_censored( + let (mut tt, tmap) = mbe::syntax_node_to_token_tree_with_modifications( &parsed.syntax_node(), fixups.replace, fixups.append, diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index a35c22c2e1..07b7f4d1a5 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs @@ -30,7 +30,7 @@ pub use tt::{Delimiter, DelimiterKind, Punct}; pub use crate::{ syntax_bridge::{ parse_exprs_with_sep, parse_to_token_tree, syntax_node_to_token_tree, - syntax_node_to_token_tree_censored, token_tree_to_syntax_node, SyntheticToken, + syntax_node_to_token_tree_with_modifications, token_tree_to_syntax_node, SyntheticToken, SyntheticTokenId, }, token_map::TokenMap, diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index da7fdb74ee..78a37993f7 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs @@ -15,13 +15,12 @@ use crate::{to_parser_input::to_parser_input, tt_iter::TtIter, TokenMap}; /// Convert the syntax node to a `TokenTree` (what macro /// will consume). pub fn syntax_node_to_token_tree(node: &SyntaxNode) -> (tt::Subtree, TokenMap) { - syntax_node_to_token_tree_censored(node, Default::default(), Default::default()) + syntax_node_to_token_tree_with_modifications(node, Default::default(), Default::default()) } -// TODO rename /// Convert the syntax node to a `TokenTree` (what macro will consume) /// with the censored range excluded. -pub fn syntax_node_to_token_tree_censored( +pub fn syntax_node_to_token_tree_with_modifications( node: &SyntaxNode, replace: FxHashMap>, append: FxHashMap>,