mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-25 21:37:39 +00:00
Repalce Span with SyntaxContextId in MacroCallLoc
This commit is contained in:
parent
08327e0e5d
commit
b59c8c76db
19 changed files with 190 additions and 165 deletions
|
|
@ -715,7 +715,7 @@ impl<'a> AssocItemCollector<'a> {
|
|||
}
|
||||
AssocItem::MacroCall(call) => {
|
||||
let file_id = self.expander.current_file_id();
|
||||
let MacroCall { ast_id, expand_to, call_site, ref path } = item_tree[call];
|
||||
let MacroCall { ast_id, expand_to, ctxt, ref path } = item_tree[call];
|
||||
let module = self.expander.module.local_id;
|
||||
|
||||
let resolver = |path| {
|
||||
|
|
@ -734,7 +734,7 @@ impl<'a> AssocItemCollector<'a> {
|
|||
match macro_call_as_call_id(
|
||||
self.db.upcast(),
|
||||
&AstIdWithPath::new(file_id, ast_id, Clone::clone(path)),
|
||||
call_site,
|
||||
ctxt,
|
||||
expand_to,
|
||||
self.expander.module.krate(),
|
||||
resolver,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ use intern::Interned;
|
|||
use la_arena::{Arena, Idx, IdxRange, RawIdx};
|
||||
use rustc_hash::FxHashMap;
|
||||
use smallvec::SmallVec;
|
||||
use span::{AstIdNode, FileAstId, Span};
|
||||
use span::{AstIdNode, FileAstId, SyntaxContextId};
|
||||
use stdx::never;
|
||||
use syntax::{ast, match_ast, SyntaxKind};
|
||||
use triomphe::Arc;
|
||||
|
|
@ -790,7 +790,7 @@ pub struct MacroCall {
|
|||
pub path: Interned<ModPath>,
|
||||
pub ast_id: FileAstId<ast::MacroCall>,
|
||||
pub expand_to: ExpandTo,
|
||||
pub call_site: Span,
|
||||
pub ctxt: SyntaxContextId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
|
|
|
|||
|
|
@ -567,7 +567,7 @@ impl<'a> Ctx<'a> {
|
|||
})?);
|
||||
let ast_id = self.source_ast_id_map.ast_id(m);
|
||||
let expand_to = hir_expand::ExpandTo::from_call_site(m);
|
||||
let res = MacroCall { path, ast_id, expand_to, call_site: span_map.span_for_range(range) };
|
||||
let res = MacroCall { path, ast_id, expand_to, ctxt: span_map.span_for_range(range).ctx };
|
||||
Some(id(self.data().macro_calls.alloc(res)))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -487,12 +487,12 @@ impl Printer<'_> {
|
|||
}
|
||||
}
|
||||
ModItem::MacroCall(it) => {
|
||||
let MacroCall { path, ast_id, expand_to, call_site } = &self.tree[it];
|
||||
let MacroCall { path, ast_id, expand_to, ctxt } = &self.tree[it];
|
||||
let _ = writeln!(
|
||||
self,
|
||||
"// AstId: {:?}, Span: {}, ExpandTo: {:?}",
|
||||
"// AstId: {:?}, SyntaxContext: {}, ExpandTo: {:?}",
|
||||
ast_id.erase().into_raw(),
|
||||
call_site,
|
||||
ctxt,
|
||||
expand_to
|
||||
);
|
||||
wln!(self, "{}!(...);", path.display(self.db.upcast()));
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@ m!();
|
|||
// AstId: 2
|
||||
pub macro m2 { ... }
|
||||
|
||||
// AstId: 3, Span: 0:3@0..1#0, ExpandTo: Items
|
||||
// AstId: 3, SyntaxContext: 0, ExpandTo: Items
|
||||
m!(...);
|
||||
"#]],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ use hir_expand::{
|
|||
use item_tree::ExternBlock;
|
||||
use la_arena::Idx;
|
||||
use nameres::DefMap;
|
||||
use span::{AstIdNode, FileAstId, FileId, Span};
|
||||
use span::{AstIdNode, FileAstId, FileId, SyntaxContextId};
|
||||
use stdx::impl_from;
|
||||
use syntax::{ast, AstNode};
|
||||
|
||||
|
|
@ -1357,7 +1357,7 @@ impl AsMacroCall for InFile<&ast::MacroCall> {
|
|||
macro_call_as_call_id_with_eager(
|
||||
db,
|
||||
&AstIdWithPath::new(ast_id.file_id, ast_id.value, path),
|
||||
call_site,
|
||||
call_site.ctx,
|
||||
expands_to,
|
||||
krate,
|
||||
resolver,
|
||||
|
|
@ -1382,7 +1382,7 @@ impl<T: AstIdNode> AstIdWithPath<T> {
|
|||
fn macro_call_as_call_id(
|
||||
db: &dyn ExpandDatabase,
|
||||
call: &AstIdWithPath<ast::MacroCall>,
|
||||
call_site: Span,
|
||||
call_site: SyntaxContextId,
|
||||
expand_to: ExpandTo,
|
||||
krate: CrateId,
|
||||
resolver: impl Fn(path::ModPath) -> Option<MacroDefId> + Copy,
|
||||
|
|
@ -1394,7 +1394,7 @@ fn macro_call_as_call_id(
|
|||
fn macro_call_as_call_id_with_eager(
|
||||
db: &dyn ExpandDatabase,
|
||||
call: &AstIdWithPath<ast::MacroCall>,
|
||||
call_site: Span,
|
||||
call_site: SyntaxContextId,
|
||||
expand_to: ExpandTo,
|
||||
krate: CrateId,
|
||||
resolver: impl FnOnce(path::ModPath) -> Option<MacroDefId>,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ m!(&k");
|
|||
"#,
|
||||
expect![[r#"
|
||||
macro_rules! m { ($i:literal) => {}; }
|
||||
/* error: mismatched delimiters */"#]],
|
||||
/* error: expected literal */"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ macro_rules! m1 { ($x:ident) => { ($x } }
|
|||
macro_rules! m2 { ($x:ident) => {} }
|
||||
|
||||
/* error: macro definition has parse errors */
|
||||
/* error: mismatched delimiters */
|
||||
/* error: expected ident */
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use hir_expand::{
|
|||
attrs::{Attr, AttrId, AttrInput},
|
||||
MacroCallId, MacroCallKind, MacroDefId,
|
||||
};
|
||||
use span::Span;
|
||||
use span::SyntaxContextId;
|
||||
use syntax::{ast, SmolStr};
|
||||
use triomphe::Arc;
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ pub(super) fn attr_macro_as_call_id(
|
|||
let arg = match macro_attr.input.as_deref() {
|
||||
Some(AttrInput::TokenTree(tt)) => {
|
||||
let mut tt = tt.as_ref().clone();
|
||||
tt.delimiter = tt::Delimiter::invisible_spanned(macro_attr.span);
|
||||
tt.delimiter.kind = tt::DelimiterKind::Invisible;
|
||||
Some(tt)
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ pub(super) fn attr_macro_as_call_id(
|
|||
attr_args: arg.map(Arc::new),
|
||||
invoc_attr_index: macro_attr.id,
|
||||
},
|
||||
macro_attr.span,
|
||||
macro_attr.ctxt,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ pub(super) fn derive_macro_as_call_id(
|
|||
item_attr: &AstIdWithPath<ast::Adt>,
|
||||
derive_attr_index: AttrId,
|
||||
derive_pos: u32,
|
||||
call_site: Span,
|
||||
call_site: SyntaxContextId,
|
||||
krate: CrateId,
|
||||
resolver: impl Fn(path::ModPath) -> Option<(MacroId, MacroDefId)>,
|
||||
) -> Result<(MacroId, MacroDefId, MacroCallId), UnresolvedMacro> {
|
||||
|
|
|
|||
|
|
@ -230,13 +230,13 @@ enum MacroDirectiveKind {
|
|||
FnLike {
|
||||
ast_id: AstIdWithPath<ast::MacroCall>,
|
||||
expand_to: ExpandTo,
|
||||
call_site: Span,
|
||||
ctxt: SyntaxContextId,
|
||||
},
|
||||
Derive {
|
||||
ast_id: AstIdWithPath<ast::Adt>,
|
||||
derive_attr: AttrId,
|
||||
derive_pos: usize,
|
||||
call_site: Span,
|
||||
ctxt: SyntaxContextId,
|
||||
},
|
||||
Attr {
|
||||
ast_id: AstIdWithPath<ast::Item>,
|
||||
|
|
@ -1126,7 +1126,7 @@ impl DefCollector<'_> {
|
|||
let resolver_def_id = |path| resolver(path).map(|(_, it)| it);
|
||||
|
||||
match &directive.kind {
|
||||
MacroDirectiveKind::FnLike { ast_id, expand_to, call_site } => {
|
||||
MacroDirectiveKind::FnLike { ast_id, expand_to, ctxt: call_site } => {
|
||||
let call_id = macro_call_as_call_id(
|
||||
self.db.upcast(),
|
||||
ast_id,
|
||||
|
|
@ -1146,7 +1146,7 @@ impl DefCollector<'_> {
|
|||
return Resolved::Yes;
|
||||
}
|
||||
}
|
||||
MacroDirectiveKind::Derive { ast_id, derive_attr, derive_pos, call_site } => {
|
||||
MacroDirectiveKind::Derive { ast_id, derive_attr, derive_pos, ctxt: call_site } => {
|
||||
let id = derive_macro_as_call_id(
|
||||
self.db,
|
||||
ast_id,
|
||||
|
|
@ -1266,7 +1266,7 @@ impl DefCollector<'_> {
|
|||
ast_id,
|
||||
derive_attr: attr.id,
|
||||
derive_pos: idx,
|
||||
call_site,
|
||||
ctxt: call_site.ctx,
|
||||
},
|
||||
container: directive.container,
|
||||
});
|
||||
|
|
@ -1428,7 +1428,7 @@ impl DefCollector<'_> {
|
|||
|
||||
for directive in &self.unresolved_macros {
|
||||
match &directive.kind {
|
||||
MacroDirectiveKind::FnLike { ast_id, expand_to, call_site } => {
|
||||
MacroDirectiveKind::FnLike { ast_id, expand_to, ctxt: call_site } => {
|
||||
// FIXME: we shouldn't need to re-resolve the macro here just to get the unresolved error!
|
||||
let macro_call_as_call_id = macro_call_as_call_id(
|
||||
self.db.upcast(),
|
||||
|
|
@ -1460,7 +1460,7 @@ impl DefCollector<'_> {
|
|||
));
|
||||
}
|
||||
}
|
||||
MacroDirectiveKind::Derive { ast_id, derive_attr, derive_pos, call_site: _ } => {
|
||||
MacroDirectiveKind::Derive { ast_id, derive_attr, derive_pos, ctxt: _ } => {
|
||||
self.def_map.diagnostics.push(DefDiagnostic::unresolved_macro_call(
|
||||
directive.module_id,
|
||||
MacroCallKind::Derive {
|
||||
|
|
@ -2289,7 +2289,7 @@ impl ModCollector<'_, '_> {
|
|||
|
||||
fn collect_macro_call(
|
||||
&mut self,
|
||||
&MacroCall { ref path, ast_id, expand_to, call_site }: &MacroCall,
|
||||
&MacroCall { ref path, ast_id, expand_to, ctxt }: &MacroCall,
|
||||
container: ItemContainerId,
|
||||
) {
|
||||
let ast_id = AstIdWithPath::new(self.file_id(), ast_id, ModPath::clone(path));
|
||||
|
|
@ -2303,7 +2303,7 @@ impl ModCollector<'_, '_> {
|
|||
if let Ok(res) = macro_call_as_call_id_with_eager(
|
||||
db.upcast(),
|
||||
&ast_id,
|
||||
call_site,
|
||||
ctxt,
|
||||
expand_to,
|
||||
self.def_collector.def_map.krate,
|
||||
|path| {
|
||||
|
|
@ -2361,7 +2361,7 @@ impl ModCollector<'_, '_> {
|
|||
self.def_collector.unresolved_macros.push(MacroDirective {
|
||||
module_id: self.module_id,
|
||||
depth: self.macro_depth + 1,
|
||||
kind: MacroDirectiveKind::FnLike { ast_id, expand_to, call_site },
|
||||
kind: MacroDirectiveKind::FnLike { ast_id, expand_to, ctxt },
|
||||
container,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue