diff options
Diffstat (limited to 'crates/ra_hir_expand/src/builtin_derive.rs')
-rw-r--r-- | crates/ra_hir_expand/src/builtin_derive.rs | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs index 967d1f3a1..26b667b55 100644 --- a/crates/ra_hir_expand/src/builtin_derive.rs +++ b/crates/ra_hir_expand/src/builtin_derive.rs | |||
@@ -8,8 +8,7 @@ use ra_syntax::{ | |||
8 | match_ast, | 8 | match_ast, |
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::db::AstDatabase; | 11 | use crate::{db::AstDatabase, name, quote, LazyMacroId, MacroDefId, MacroDefKind}; |
12 | use crate::{guess_crate, name, quote, LazyMacroId, MacroCallId, MacroDefId, MacroDefKind}; | ||
13 | 12 | ||
14 | macro_rules! register_builtin { | 13 | macro_rules! register_builtin { |
15 | ( $($trait:ident => $expand:ident),* ) => { | 14 | ( $($trait:ident => $expand:ident),* ) => { |
@@ -156,17 +155,8 @@ fn expand_simple_derive( | |||
156 | fn find_builtin_crate(db: &dyn AstDatabase, id: LazyMacroId) -> tt::TokenTree { | 155 | fn find_builtin_crate(db: &dyn AstDatabase, id: LazyMacroId) -> tt::TokenTree { |
157 | // FIXME: make hygiene works for builtin derive macro | 156 | // FIXME: make hygiene works for builtin derive macro |
158 | // such that $crate can be used here. | 157 | // such that $crate can be used here. |
159 | |||
160 | let m: MacroCallId = id.into(); | ||
161 | let file_id = m.as_file().original_file(db); | ||
162 | let cg = db.crate_graph(); | 158 | let cg = db.crate_graph(); |
163 | let krate = match guess_crate(db, file_id) { | 159 | let krate = db.lookup_intern_macro(id).krate; |
164 | Some(krate) => krate, | ||
165 | None => { | ||
166 | let tt = quote! { core }; | ||
167 | return tt.token_trees[0].clone(); | ||
168 | } | ||
169 | }; | ||
170 | 160 | ||
171 | // XXX | 161 | // XXX |
172 | // All crates except core itself should have a dependency on core, | 162 | // All crates except core itself should have a dependency on core, |
@@ -263,10 +253,12 @@ fn partial_ord_expand( | |||
263 | 253 | ||
264 | #[cfg(test)] | 254 | #[cfg(test)] |
265 | mod tests { | 255 | mod tests { |
266 | use super::*; | ||
267 | use crate::{test_db::TestDB, AstId, MacroCallId, MacroCallKind, MacroCallLoc}; | ||
268 | use name::{known, Name}; | 256 | use name::{known, Name}; |
269 | use ra_db::{fixture::WithFixture, SourceDatabase}; | 257 | use ra_db::{fixture::WithFixture, CrateId, SourceDatabase}; |
258 | |||
259 | use crate::{test_db::TestDB, AstId, MacroCallId, MacroCallKind, MacroCallLoc}; | ||
260 | |||
261 | use super::*; | ||
270 | 262 | ||
271 | fn expand_builtin_derive(s: &str, name: Name) -> String { | 263 | fn expand_builtin_derive(s: &str, name: Name) -> String { |
272 | let def = find_builtin_derive(&name).unwrap(); | 264 | let def = find_builtin_derive(&name).unwrap(); |
@@ -290,7 +282,11 @@ mod tests { | |||
290 | 282 | ||
291 | let attr_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0])); | 283 | let attr_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0])); |
292 | 284 | ||
293 | let loc = MacroCallLoc { def, kind: MacroCallKind::Attr(attr_id, name.to_string()) }; | 285 | let loc = MacroCallLoc { |
286 | def, | ||
287 | krate: CrateId(0), | ||
288 | kind: MacroCallKind::Attr(attr_id, name.to_string()), | ||
289 | }; | ||
294 | 290 | ||
295 | let id: MacroCallId = db.intern_macro(loc).into(); | 291 | let id: MacroCallId = db.intern_macro(loc).into(); |
296 | let parsed = db.parse_or_expand(id.as_file()).unwrap(); | 292 | let parsed = db.parse_or_expand(id.as_file()).unwrap(); |