use profile::Count;
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
-use syntax::{ast, match_ast};
+use syntax::{ast, match_ast, SyntaxKind};
use test_utils::mark;
use crate::{
pub(crate) fn item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> {
let _p = profile::span("item_tree_query").detail(|| format!("{:?}", file_id));
let syntax = if let Some(node) = db.parse_or_expand(file_id) {
+ if node.kind() == SyntaxKind::ERROR {
+ // FIXME: not 100% sure why these crop up, but return an empty tree to avoid a panic
+ return Default::default();
+ }
node
} else {
return Default::default();
ctx.lower_module_items(&items)
},
ast::MacroStmts(stmts) => {
- ctx.lower_inner_items(stmts.syntax())
+ // The produced statements can include items, which should be added as top-level
+ // items.
+ ctx.lower_macro_stmts(stmts)
},
- // Macros can expand to expressions. We return an empty item tree in this case, but
- // still need to collect inner items.
ast::Expr(e) => {
+ // Macros can expand to expressions. We return an empty item tree in this case, but
+ // still need to collect inner items.
ctx.lower_inner_items(e.syntax())
},
_ => {
- panic!("cannot create item tree from {:?}", syntax);
+ panic!("cannot create item tree from {:?} {}", syntax, syntax);
},
}
};