mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Push macro-parsing error calculation out of fundamental queries
This commit is contained in:
parent
067d9d995b
commit
56552f4839
15 changed files with 145 additions and 140 deletions
|
@ -229,7 +229,7 @@ pub struct TraitData {
|
|||
/// method calls to this trait's methods when the receiver is an array and the crate edition is
|
||||
/// 2015 or 2018.
|
||||
// box it as the vec is usually empty anyways
|
||||
pub attribute_calls: Option<Box<Vec<(AstId<ast::Item>, MacroCallId)>>>,
|
||||
pub macro_calls: Option<Box<Vec<(AstId<ast::Item>, MacroCallId)>>>,
|
||||
}
|
||||
|
||||
impl TraitData {
|
||||
|
@ -258,12 +258,12 @@ impl TraitData {
|
|||
let mut collector =
|
||||
AssocItemCollector::new(db, module_id, tree_id.file_id(), ItemContainerId::TraitId(tr));
|
||||
collector.collect(&item_tree, tree_id.tree_id(), &tr_def.items);
|
||||
let (items, attribute_calls, diagnostics) = collector.finish();
|
||||
let (items, macro_calls, diagnostics) = collector.finish();
|
||||
|
||||
(
|
||||
Arc::new(TraitData {
|
||||
name,
|
||||
attribute_calls,
|
||||
macro_calls,
|
||||
items,
|
||||
is_auto,
|
||||
is_unsafe,
|
||||
|
@ -298,7 +298,7 @@ impl TraitData {
|
|||
}
|
||||
|
||||
pub fn attribute_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
|
||||
self.attribute_calls.iter().flat_map(|it| it.iter()).copied()
|
||||
self.macro_calls.iter().flat_map(|it| it.iter()).copied()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -319,7 +319,7 @@ impl TraitAliasData {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct ImplData {
|
||||
pub target_trait: Option<Interned<TraitRef>>,
|
||||
pub self_ty: Interned<TypeRef>,
|
||||
|
@ -327,7 +327,7 @@ pub struct ImplData {
|
|||
pub is_negative: bool,
|
||||
pub is_unsafe: bool,
|
||||
// box it as the vec is usually empty anyways
|
||||
pub attribute_calls: Option<Box<Vec<(AstId<ast::Item>, MacroCallId)>>>,
|
||||
pub macro_calls: Option<Box<Vec<(AstId<ast::Item>, MacroCallId)>>>,
|
||||
}
|
||||
|
||||
impl ImplData {
|
||||
|
@ -354,7 +354,7 @@ impl ImplData {
|
|||
AssocItemCollector::new(db, module_id, tree_id.file_id(), ItemContainerId::ImplId(id));
|
||||
collector.collect(&item_tree, tree_id.tree_id(), &impl_def.items);
|
||||
|
||||
let (items, attribute_calls, diagnostics) = collector.finish();
|
||||
let (items, macro_calls, diagnostics) = collector.finish();
|
||||
let items = items.into_iter().map(|(_, item)| item).collect();
|
||||
|
||||
(
|
||||
|
@ -364,14 +364,14 @@ impl ImplData {
|
|||
items,
|
||||
is_negative,
|
||||
is_unsafe,
|
||||
attribute_calls,
|
||||
macro_calls,
|
||||
}),
|
||||
DefDiagnostics::new(diagnostics),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn attribute_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
|
||||
self.attribute_calls.iter().flat_map(|it| it.iter()).copied()
|
||||
self.macro_calls.iter().flat_map(|it| it.iter()).copied()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -573,7 +573,7 @@ struct AssocItemCollector<'a> {
|
|||
expander: Expander,
|
||||
|
||||
items: Vec<(Name, AssocItemId)>,
|
||||
attr_calls: Vec<(AstId<ast::Item>, MacroCallId)>,
|
||||
macro_calls: Vec<(AstId<ast::Item>, MacroCallId)>,
|
||||
}
|
||||
|
||||
impl<'a> AssocItemCollector<'a> {
|
||||
|
@ -590,7 +590,7 @@ impl<'a> AssocItemCollector<'a> {
|
|||
container,
|
||||
expander: Expander::new(db, file_id, module_id),
|
||||
items: Vec::new(),
|
||||
attr_calls: Vec::new(),
|
||||
macro_calls: Vec::new(),
|
||||
diagnostics: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
@ -604,7 +604,7 @@ impl<'a> AssocItemCollector<'a> {
|
|||
) {
|
||||
(
|
||||
self.items,
|
||||
if self.attr_calls.is_empty() { None } else { Some(Box::new(self.attr_calls)) },
|
||||
if self.macro_calls.is_empty() { None } else { Some(Box::new(self.macro_calls)) },
|
||||
self.diagnostics,
|
||||
)
|
||||
}
|
||||
|
@ -662,11 +662,11 @@ impl<'a> AssocItemCollector<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
self.attr_calls.push((ast_id, call_id));
|
||||
self.macro_calls.push((ast_id, call_id));
|
||||
|
||||
let res =
|
||||
self.expander.enter_expand_id::<ast::MacroItems>(self.db, call_id);
|
||||
self.collect_macro_items(res, &|| loc.kind.clone());
|
||||
self.collect_macro_items(res);
|
||||
continue 'items;
|
||||
}
|
||||
Ok(_) => (),
|
||||
|
@ -743,11 +743,8 @@ impl<'a> AssocItemCollector<'a> {
|
|||
Ok(Some(call_id)) => {
|
||||
let res =
|
||||
self.expander.enter_expand_id::<ast::MacroItems>(self.db, call_id);
|
||||
self.collect_macro_items(res, &|| hir_expand::MacroCallKind::FnLike {
|
||||
ast_id: InFile::new(file_id, ast_id),
|
||||
expand_to: hir_expand::ExpandTo::Items,
|
||||
eager: None,
|
||||
});
|
||||
self.macro_calls.push((InFile::new(file_id, ast_id.upcast()), call_id));
|
||||
self.collect_macro_items(res);
|
||||
}
|
||||
Ok(None) => (),
|
||||
Err(_) => {
|
||||
|
@ -766,39 +763,8 @@ impl<'a> AssocItemCollector<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn collect_macro_items(
|
||||
&mut self,
|
||||
ExpandResult { value, err }: ExpandResult<Option<(Mark, Parse<ast::MacroItems>)>>,
|
||||
error_call_kind: &dyn Fn() -> hir_expand::MacroCallKind,
|
||||
) {
|
||||
let Some((mark, parse)) = value else { return };
|
||||
|
||||
if let Some(err) = err {
|
||||
let diag = match err {
|
||||
// why is this reported here?
|
||||
hir_expand::ExpandError::UnresolvedProcMacro(krate) => {
|
||||
DefDiagnostic::unresolved_proc_macro(
|
||||
self.module_id.local_id,
|
||||
error_call_kind(),
|
||||
krate,
|
||||
)
|
||||
}
|
||||
_ => DefDiagnostic::macro_error(
|
||||
self.module_id.local_id,
|
||||
error_call_kind(),
|
||||
err.to_string(),
|
||||
),
|
||||
};
|
||||
self.diagnostics.push(diag);
|
||||
}
|
||||
let errors = parse.errors();
|
||||
if !errors.is_empty() {
|
||||
self.diagnostics.push(DefDiagnostic::macro_expansion_parse_error(
|
||||
self.module_id.local_id,
|
||||
error_call_kind(),
|
||||
errors.into_boxed_slice(),
|
||||
));
|
||||
}
|
||||
fn collect_macro_items(&mut self, res: ExpandResult<Option<(Mark, Parse<ast::MacroItems>)>>) {
|
||||
let Some((mark, _parse)) = res.value else { return };
|
||||
|
||||
let tree_id = item_tree::TreeId::new(self.expander.current_file_id(), None);
|
||||
let item_tree = tree_id.item_tree(self.db);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue