mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Make ast_to_token_tree
infallible
It could never return `None`, so reflect that in the return type
This commit is contained in:
parent
bcf600fc88
commit
3abcdc03ba
11 changed files with 32 additions and 41 deletions
|
@ -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({
|
||||
|
|
|
@ -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<Arc<(TokenExpander,
|
|||
MacroDefKind::Declarative(ast_id) => 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<Arc<(TokenExpander,
|
|||
}
|
||||
syntax::ast::Macro::MacroDef(macro_def) => {
|
||||
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<GreenNode> {
|
|||
|
||||
fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
|
||||
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)))
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ pub fn expand_eager_macro(
|
|||
mut diagnostic_sink: &mut dyn FnMut(mbe::ExpandError),
|
||||
) -> Result<EagerMacroId, ErrorEmitted> {
|
||||
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<tt::Subtree> {
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue