misc improvements
- avoid needless pass by value in
`DeclarativeMacroExpander::expand{,_unhygienic}`, thus avoiding the
need to clone
diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs
index 69bacad..92be93a 100644
--- a/crates/hir-expand/src/db.rs
+++ b/crates/hir-expand/src/db.rs
@@ -275,7 +275,7 @@
}
MacroDefKind::Declarative(it, _) => db
.decl_macro_expander(loc.krate, it)
- .expand_unhygienic(db, tt, loc.kind.call_style(), span),
+ .expand_unhygienic(db, &tt, loc.kind.call_style(), span),
MacroDefKind::BuiltIn(_, it) => {
it.expand(db, actual_macro_call, &tt, span).map_err(Into::into)
}
@@ -547,9 +547,9 @@
let arg = macro_arg;
let res = match loc.def.kind {
- MacroDefKind::Declarative(id, _) => db
- .decl_macro_expander(loc.def.krate, id)
- .expand(db, arg.clone(), macro_call_id, span),
+ MacroDefKind::Declarative(id, _) => {
+ db.decl_macro_expander(loc.def.krate, id).expand(db, arg, macro_call_id, span)
+ }
MacroDefKind::BuiltIn(_, it) => {
it.expand(db, macro_call_id, arg, span).map_err(Into::into).zip_val(None)
}
@@ -589,7 +589,7 @@
}
MacroDefKind::ProcMacro(_, _, _) => unreachable!(),
};
- (ExpandResult { value: res.value, err: res.err }, span)
+ (res, span)
}
};
diff --git a/crates/hir-expand/src/declarative.rs b/crates/hir-expand/src/declarative.rs
index 99db0db..e6374b6 100644
--- a/crates/hir-expand/src/declarative.rs
+++ b/crates/hir-expand/src/declarative.rs
@@ -32,7 +32,7 @@
pub fn expand(
&self,
db: &dyn ExpandDatabase,
- tt: tt::TopSubtree,
+ tt: &tt::TopSubtree,
call_id: MacroCallId,
span: Span,
) -> ExpandResult<(tt::TopSubtree, Option<u32>)> {
@@ -46,7 +46,7 @@
.mac
.expand(
db,
- &tt,
+ tt,
|s| {
s.ctx =
apply_mark(db, s.ctx, call_id.into(), self.transparency, self.edition)
@@ -61,7 +61,7 @@
pub fn expand_unhygienic(
&self,
db: &dyn ExpandDatabase,
- tt: tt::TopSubtree,
+ tt: &tt::TopSubtree,
call_style: MacroCallStyle,
call_site: Span,
) -> ExpandResult<tt::TopSubtree> {
@@ -72,7 +72,7 @@
),
None => self
.mac
- .expand(db, &tt, |_| (), call_style, call_site)
+ .expand(db, tt, |_| (), call_style, call_site)
.map(TupleExt::head)
.map_err(Into::into),
}
diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs
index fd90bc4..96c95ec 100644
--- a/crates/load-cargo/src/lib.rs
+++ b/crates/load-cargo/src/lib.rs
@@ -171,7 +171,7 @@
.map(|(crate_id, path)| {
(
crate_id,
- path.map_or_else(Err, |(_, path)| {
+ path.and_then(|(_, path)| {
proc_macro_server.as_ref().map_err(Clone::clone).and_then(
|proc_macro_server| load_proc_macro(proc_macro_server, &path, &[]),
)