aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src/builtin_derive.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-11 11:08:24 +0100
committerAleksey Kladov <[email protected]>2020-06-11 11:13:14 +0100
commitfac7b0e252ab305f5c8d69b04c46c587ee021aa9 (patch)
treec8a90f4da1a3ab9f949466dd651d1983231674e8 /crates/ra_hir_expand/src/builtin_derive.rs
parentd8a5d39c2d05fb59b6c243935111714e18334599 (diff)
Don't guess macro expansion crate
Diffstat (limited to 'crates/ra_hir_expand/src/builtin_derive.rs')
-rw-r--r--crates/ra_hir_expand/src/builtin_derive.rs28
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
11use crate::db::AstDatabase; 11use crate::{db::AstDatabase, name, quote, LazyMacroId, MacroDefId, MacroDefKind};
12use crate::{guess_crate, name, quote, LazyMacroId, MacroCallId, MacroDefId, MacroDefKind};
13 12
14macro_rules! register_builtin { 13macro_rules! register_builtin {
15 ( $($trait:ident => $expand:ident),* ) => { 14 ( $($trait:ident => $expand:ident),* ) => {
@@ -156,17 +155,8 @@ fn expand_simple_derive(
156fn find_builtin_crate(db: &dyn AstDatabase, id: LazyMacroId) -> tt::TokenTree { 155fn 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)]
265mod tests { 255mod 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();