aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_expand/src')
-rw-r--r--crates/hir_expand/src/db.rs4
-rw-r--r--crates/hir_expand/src/eager.rs2
-rw-r--r--crates/hir_expand/src/hygiene.rs2
-rw-r--r--crates/hir_expand/src/lib.rs2
-rw-r--r--crates/hir_expand/src/name.rs10
-rw-r--r--crates/hir_expand/src/proc_macro.rs39
6 files changed, 35 insertions, 24 deletions
diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs
index 710694a34..b591130ca 100644
--- a/crates/hir_expand/src/db.rs
+++ b/crates/hir_expand/src/db.rs
@@ -143,7 +143,7 @@ pub(crate) fn macro_def(
143 Some(Arc::new((TokenExpander::BuiltinDerive(expander), mbe::TokenMap::default()))) 143 Some(Arc::new((TokenExpander::BuiltinDerive(expander), mbe::TokenMap::default())))
144 } 144 }
145 MacroDefKind::BuiltInEager(_) => None, 145 MacroDefKind::BuiltInEager(_) => None,
146 MacroDefKind::CustomDerive(expander) => { 146 MacroDefKind::ProcMacro(expander) => {
147 Some(Arc::new((TokenExpander::ProcMacro(expander), mbe::TokenMap::default()))) 147 Some(Arc::new((TokenExpander::ProcMacro(expander), mbe::TokenMap::default())))
148 } 148 }
149 } 149 }
@@ -249,7 +249,7 @@ pub(crate) fn expand_proc_macro(
249 }; 249 };
250 250
251 let expander = match loc.def.kind { 251 let expander = match loc.def.kind {
252 MacroDefKind::CustomDerive(expander) => expander, 252 MacroDefKind::ProcMacro(expander) => expander,
253 _ => unreachable!(), 253 _ => unreachable!(),
254 }; 254 };
255 255
diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs
index 10c45646f..2f37d7189 100644
--- a/crates/hir_expand/src/eager.rs
+++ b/crates/hir_expand/src/eager.rs
@@ -129,7 +129,7 @@ fn eager_macro_recur(
129 MacroDefKind::Declarative 129 MacroDefKind::Declarative
130 | MacroDefKind::BuiltIn(_) 130 | MacroDefKind::BuiltIn(_)
131 | MacroDefKind::BuiltInDerive(_) 131 | MacroDefKind::BuiltInDerive(_)
132 | MacroDefKind::CustomDerive(_) => { 132 | MacroDefKind::ProcMacro(_) => {
133 let expanded = lazy_expand(db, &def, curr.with_value(child.clone()), krate)?; 133 let expanded = lazy_expand(db, &def, curr.with_value(child.clone()), krate)?;
134 // replace macro inside 134 // replace macro inside
135 eager_macro_recur(db, expanded, krate, macro_resolver)? 135 eager_macro_recur(db, expanded, krate, macro_resolver)?
diff --git a/crates/hir_expand/src/hygiene.rs b/crates/hir_expand/src/hygiene.rs
index 845e9cbc1..d383b968d 100644
--- a/crates/hir_expand/src/hygiene.rs
+++ b/crates/hir_expand/src/hygiene.rs
@@ -33,7 +33,7 @@ impl Hygiene {
33 MacroDefKind::BuiltIn(_) => (None, false), 33 MacroDefKind::BuiltIn(_) => (None, false),
34 MacroDefKind::BuiltInDerive(_) => (None, false), 34 MacroDefKind::BuiltInDerive(_) => (None, false),
35 MacroDefKind::BuiltInEager(_) => (None, false), 35 MacroDefKind::BuiltInEager(_) => (None, false),
36 MacroDefKind::CustomDerive(_) => (None, false), 36 MacroDefKind::ProcMacro(_) => (None, false),
37 } 37 }
38 } 38 }
39 MacroCallId::EagerMacro(_id) => (None, false), 39 MacroCallId::EagerMacro(_id) => (None, false),
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 2be15e841..17f1178ed 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -246,7 +246,7 @@ pub enum MacroDefKind {
246 // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander 246 // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander
247 BuiltInDerive(BuiltinDeriveExpander), 247 BuiltInDerive(BuiltinDeriveExpander),
248 BuiltInEager(EagerExpander), 248 BuiltInEager(EagerExpander),
249 CustomDerive(ProcMacroExpander), 249 ProcMacro(ProcMacroExpander),
250} 250}
251 251
252#[derive(Debug, Clone, PartialEq, Eq, Hash)] 252#[derive(Debug, Clone, PartialEq, Eq, Hash)]
diff --git a/crates/hir_expand/src/name.rs b/crates/hir_expand/src/name.rs
index 49841c7a1..a5750d829 100644
--- a/crates/hir_expand/src/name.rs
+++ b/crates/hir_expand/src/name.rs
@@ -43,8 +43,8 @@ impl Name {
43 } 43 }
44 44
45 /// Shortcut to create inline plain text name 45 /// Shortcut to create inline plain text name
46 const fn new_inline_ascii(text: &[u8]) -> Name { 46 const fn new_inline(text: &str) -> Name {
47 Name::new_text(SmolStr::new_inline_from_ascii(text.len(), text)) 47 Name::new_text(SmolStr::new_inline(text))
48 } 48 }
49 49
50 /// Resolve a name from the text of token. 50 /// Resolve a name from the text of token.
@@ -127,7 +127,7 @@ pub mod known {
127 $( 127 $(
128 #[allow(bad_style)] 128 #[allow(bad_style)]
129 pub const $ident: super::Name = 129 pub const $ident: super::Name =
130 super::Name::new_inline_ascii(stringify!($ident).as_bytes()); 130 super::Name::new_inline(stringify!($ident));
131 )* 131 )*
132 }; 132 };
133 } 133 }
@@ -210,8 +210,8 @@ pub mod known {
210 ); 210 );
211 211
212 // self/Self cannot be used as an identifier 212 // self/Self cannot be used as an identifier
213 pub const SELF_PARAM: super::Name = super::Name::new_inline_ascii(b"self"); 213 pub const SELF_PARAM: super::Name = super::Name::new_inline("self");
214 pub const SELF_TYPE: super::Name = super::Name::new_inline_ascii(b"Self"); 214 pub const SELF_TYPE: super::Name = super::Name::new_inline("Self");
215 215
216 #[macro_export] 216 #[macro_export]
217 macro_rules! name { 217 macro_rules! name {
diff --git a/crates/hir_expand/src/proc_macro.rs b/crates/hir_expand/src/proc_macro.rs
index 80255ea32..7505cb061 100644
--- a/crates/hir_expand/src/proc_macro.rs
+++ b/crates/hir_expand/src/proc_macro.rs
@@ -7,7 +7,7 @@ use tt::buffer::{Cursor, TokenBuffer};
7#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] 7#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
8pub struct ProcMacroExpander { 8pub struct ProcMacroExpander {
9 krate: CrateId, 9 krate: CrateId,
10 proc_macro_id: ProcMacroId, 10 proc_macro_id: Option<ProcMacroId>,
11} 11}
12 12
13macro_rules! err { 13macro_rules! err {
@@ -20,8 +20,14 @@ macro_rules! err {
20} 20}
21 21
22impl ProcMacroExpander { 22impl ProcMacroExpander {
23 pub fn new(krate: CrateId, proc_macro_id: ProcMacroId) -> ProcMacroExpander { 23 pub fn new(krate: CrateId, proc_macro_id: ProcMacroId) -> Self {
24 ProcMacroExpander { krate, proc_macro_id } 24 Self { krate, proc_macro_id: Some(proc_macro_id) }
25 }
26
27 pub fn dummy(krate: CrateId) -> Self {
28 // FIXME: Should store the name for better errors
29 // FIXME: I think this is the second layer of "dummy" expansion, we should reduce that
30 Self { krate, proc_macro_id: None }
25 } 31 }
26 32
27 pub fn expand( 33 pub fn expand(
@@ -30,17 +36,22 @@ impl ProcMacroExpander {
30 _id: LazyMacroId, 36 _id: LazyMacroId,
31 tt: &tt::Subtree, 37 tt: &tt::Subtree,
32 ) -> Result<tt::Subtree, mbe::ExpandError> { 38 ) -> Result<tt::Subtree, mbe::ExpandError> {
33 let krate_graph = db.crate_graph(); 39 match self.proc_macro_id {
34 let proc_macro = krate_graph[self.krate] 40 Some(id) => {
35 .proc_macro 41 let krate_graph = db.crate_graph();
36 .get(self.proc_macro_id.0 as usize) 42 let proc_macro = krate_graph[self.krate]
37 .clone() 43 .proc_macro
38 .ok_or_else(|| err!("No derive macro found."))?; 44 .get(id.0 as usize)
39 45 .clone()
40 let tt = remove_derive_attrs(tt) 46 .ok_or_else(|| err!("No derive macro found."))?;
41 .ok_or_else(|| err!("Fail to remove derive for custom derive"))?; 47
42 48 let tt = remove_derive_attrs(tt)
43 proc_macro.expander.expand(&tt, None).map_err(mbe::ExpandError::from) 49 .ok_or_else(|| err!("Fail to remove derive for custom derive"))?;
50
51 proc_macro.expander.expand(&tt, None).map_err(mbe::ExpandError::from)
52 }
53 None => Err(err!("Unresolved proc macro")),
54 }
44 } 55 }
45} 56}
46 57