From 3abcdc03ba335fb3487c62547f61746e4a199fe6 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 4 Apr 2021 01:46:45 +0200 Subject: Make `ast_to_token_tree` infallible It could never return `None`, so reflect that in the return type --- crates/hir_expand/src/builtin_macro.rs | 2 +- crates/hir_expand/src/db.rs | 14 ++++---------- crates/hir_expand/src/eager.rs | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) (limited to 'crates/hir_expand/src') diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index 3aa3d8997..75ec4196b 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs @@ -584,7 +584,7 @@ mod tests { }; let args = macro_call.token_tree().unwrap(); - let parsed_args = mbe::ast_to_token_tree(&args).unwrap().0; + let parsed_args = mbe::ast_to_token_tree(&args).0; let call_id = AstId::new(file_id.into(), ast_id_map.ast_id(¯o_call)); let arg_id = db.intern_eager_expansion({ diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index c0ab70b60..10fe60821 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs @@ -119,7 +119,7 @@ pub fn expand_hypothetical( token_to_map: syntax::SyntaxToken, ) -> Option<(SyntaxNode, syntax::SyntaxToken)> { let macro_file = MacroFile { macro_call_id: actual_macro_call }; - let (tt, tmap_1) = mbe::syntax_node_to_token_tree(hypothetical_args.syntax()).unwrap(); + let (tt, tmap_1) = mbe::syntax_node_to_token_tree(hypothetical_args.syntax()); let range = token_to_map.text_range().checked_sub(hypothetical_args.syntax().text_range().start())?; let token_id = tmap_1.token_by_range(range)?; @@ -143,10 +143,7 @@ fn macro_def(db: &dyn AstDatabase, id: MacroDefId) -> Option match ast_id.to_node(db) { syntax::ast::Macro::MacroRules(macro_rules) => { let arg = macro_rules.token_tree()?; - let (tt, tmap) = mbe::ast_to_token_tree(&arg).or_else(|| { - log::warn!("fail on macro_rules to token tree: {:#?}", arg); - None - })?; + let (tt, tmap) = mbe::ast_to_token_tree(&arg); let rules = match MacroRules::parse(&tt) { Ok(it) => it, Err(err) => { @@ -159,10 +156,7 @@ fn macro_def(db: &dyn AstDatabase, id: MacroDefId) -> Option { let arg = macro_def.body()?; - let (tt, tmap) = mbe::ast_to_token_tree(&arg).or_else(|| { - log::warn!("fail on macro_def to token tree: {:#?}", arg); - None - })?; + let (tt, tmap) = mbe::ast_to_token_tree(&arg); let rules = match MacroDef::parse(&tt) { Ok(it) => it, Err(err) => { @@ -202,7 +196,7 @@ fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option { fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option> { let arg = db.macro_arg_text(id)?; - let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg))?; + let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg)); Some(Arc::new((tt, tmap))) } diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs index 9eedc8461..9705526fa 100644 --- a/crates/hir_expand/src/eager.rs +++ b/crates/hir_expand/src/eager.rs @@ -106,7 +106,7 @@ pub fn expand_eager_macro( mut diagnostic_sink: &mut dyn FnMut(mbe::ExpandError), ) -> Result { let parsed_args = diagnostic_sink.option_with( - || Some(mbe::ast_to_token_tree(¯o_call.value.token_tree()?)?.0), + || Some(mbe::ast_to_token_tree(¯o_call.value.token_tree()?).0), || err("malformed macro invocation"), )?; @@ -161,7 +161,7 @@ pub fn expand_eager_macro( } fn to_subtree(node: &SyntaxNode) -> Option { - let mut subtree = mbe::syntax_node_to_token_tree(node)?.0; + let mut subtree = mbe::syntax_node_to_token_tree(node).0; subtree.delimiter = None; Some(subtree) } -- cgit v1.2.3