ast_id_map::FileAstId,
eager::{expand_eager_macro, ErrorEmitted, ErrorSink},
hygiene::Hygiene,
- AstId, ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
- UnresolvedMacro,
+ AstId, ExpandError, ExpandTo, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId,
+ MacroDefKind, UnresolvedMacro,
};
use item_tree::ExternBlock;
use la_arena::Idx;
db: &dyn db::DefDatabase,
krate: CrateId,
resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
- error_sink: &mut dyn FnMut(mbe::ExpandError),
+ error_sink: &mut dyn FnMut(ExpandError),
) -> Result<Result<MacroCallId, ErrorEmitted>, UnresolvedMacro>;
}
db: &dyn db::DefDatabase,
krate: CrateId,
resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
- mut error_sink: &mut dyn FnMut(mbe::ExpandError),
+ mut error_sink: &mut dyn FnMut(ExpandError),
) -> Result<Result<MacroCallId, ErrorEmitted>, UnresolvedMacro> {
let expands_to = hir_expand::ExpandTo::from_call_site(self.value);
let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(self.value));
self.value.path().and_then(|path| path::ModPath::from_src(db.upcast(), path, &h));
let path = match error_sink
- .option(path, || mbe::ExpandError::Other("malformed macro invocation".into()))
+ .option(path, || ExpandError::Other("malformed macro invocation".into()))
{
Ok(path) => path,
Err(error) => {
};
macro_call_as_call_id(
+ db,
&AstIdWithPath::new(ast_id.file_id, ast_id.value, path),
expands_to,
- db,
krate,
resolver,
error_sink,
}
fn macro_call_as_call_id(
+ db: &dyn db::DefDatabase,
call: &AstIdWithPath<ast::MacroCall>,
expand_to: ExpandTo,
- db: &dyn db::DefDatabase,
krate: CrateId,
resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
- error_sink: &mut dyn FnMut(mbe::ExpandError),
+ error_sink: &mut dyn FnMut(ExpandError),
) -> Result<Result<MacroCallId, ErrorEmitted>, UnresolvedMacro> {
let def: MacroDefId =
resolver(call.path.clone()).ok_or_else(|| UnresolvedMacro { path: call.path.clone() })?;
}
fn derive_macro_as_call_id(
+ db: &dyn db::DefDatabase,
item_attr: &AstIdWithPath<ast::Adt>,
derive_attr: AttrId,
- db: &dyn db::DefDatabase,
+ derive_pos: u32,
krate: CrateId,
resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
) -> Result<MacroCallId, UnresolvedMacro> {
let def: MacroDefId = resolver(item_attr.path.clone())
.ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?;
- let last_segment = item_attr
- .path
- .segments()
- .last()
- .ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?;
let res = def.as_lazy_macro(
db.upcast(),
krate,
MacroCallKind::Derive {
ast_id: item_attr.ast_id,
- derive_name: last_segment.to_string().into_boxed_str(),
+ derive_index: derive_pos,
derive_attr_index: derive_attr.ast_index,
},
);
}
fn attr_macro_as_call_id(
+ db: &dyn db::DefDatabase,
item_attr: &AstIdWithPath<ast::Item>,
macro_attr: &Attr,
- db: &dyn db::DefDatabase,
krate: CrateId,
def: MacroDefId,
+ is_derive: bool,
) -> MacroCallId {
- let attr_path = &item_attr.path;
- let last_segment = attr_path.segments().last().expect("empty attribute path");
let mut arg = match macro_attr.input.as_deref() {
Some(attr::AttrInput::TokenTree(tt, map)) => (tt.clone(), map.clone()),
_ => Default::default(),
krate,
MacroCallKind::Attr {
ast_id: item_attr.ast_id,
- attr_name: last_segment.to_string().into_boxed_str(),
attr_args: Arc::new(arg),
invoc_attr_index: macro_attr.id.ast_index,
+ is_derive,
},
);
res