Add more information on macro rules fail to parse

This commit is contained in:
Edwin Cheng 2019-04-24 03:00:59 +08:00
parent e4e2338f97
commit dfab545d5d

View File

@ -128,8 +128,14 @@ fn from(macro_call_id: MacroCallId) -> HirFileId {
pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
let macro_call = id.0.to_node(db);
let arg = macro_call.token_tree()?;
let (tt, _) = mbe::ast_to_token_tree(arg)?;
let rules = MacroRules::parse(&tt).ok()?;
let (tt, _) = mbe::ast_to_token_tree(arg).or_else(|| {
log::warn!("fail on macro_def to token tree: {:#?}", arg);
None
})?;
let rules = MacroRules::parse(&tt).ok().or_else(|| {
log::warn!("fail on macro_def parse: {:#?}", tt);
None
})?;
Some(Arc::new(rules))
}