diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_expand/src/builtin_derive.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/macros.rs | 11 |
2 files changed, 26 insertions, 11 deletions
diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs index cc8c45347..3bd3f7041 100644 --- a/crates/ra_hir_expand/src/builtin_derive.rs +++ b/crates/ra_hir_expand/src/builtin_derive.rs | |||
@@ -160,11 +160,17 @@ fn find_builtin_crate(db: &dyn AstDatabase, id: LazyMacroId) -> tt::TokenTree { | |||
160 | let m: MacroCallId = id.into(); | 160 | let m: MacroCallId = id.into(); |
161 | let file_id = m.as_file().original_file(db); | 161 | let file_id = m.as_file().original_file(db); |
162 | let cg = db.crate_graph(); | 162 | let cg = db.crate_graph(); |
163 | let crates = db.relevant_crates(file_id); | 163 | let krates = db.relevant_crates(file_id); |
164 | let mut crate_names = | 164 | let krate = match krates.get(0) { |
165 | crates.iter().filter_map(|krate| cg[*krate].display_name.clone()).map(|it| it.to_string()); | 165 | Some(krate) => krate, |
166 | None => { | ||
167 | let tt = quote! { core }; | ||
168 | return tt.token_trees[0].clone(); | ||
169 | } | ||
170 | }; | ||
166 | 171 | ||
167 | let tt = if crate_names.any(|name| name == "std" || name == "core") { | 172 | // Check whether it has any deps, if not, it should be core: |
173 | let tt = if cg[*krate].dependencies.is_empty() { | ||
168 | quote! { crate } | 174 | quote! { crate } |
169 | } else { | 175 | } else { |
170 | quote! { core } | 176 | quote! { core } |
@@ -263,8 +269,18 @@ mod tests { | |||
263 | 269 | ||
264 | fn expand_builtin_derive(s: &str, name: Name) -> String { | 270 | fn expand_builtin_derive(s: &str, name: Name) -> String { |
265 | let def = find_builtin_derive(&name).unwrap(); | 271 | let def = find_builtin_derive(&name).unwrap(); |
272 | let fixture = format!( | ||
273 | r#"//- /main.rs crate:main deps:core | ||
274 | <|> | ||
275 | {} | ||
276 | //- /lib.rs crate:core | ||
277 | // empty | ||
278 | "#, | ||
279 | s | ||
280 | ); | ||
266 | 281 | ||
267 | let (db, file_id) = TestDB::with_single_file(&s); | 282 | let (db, file_pos) = TestDB::with_position(&fixture); |
283 | let file_id = file_pos.file_id; | ||
268 | let parsed = db.parse(file_id); | 284 | let parsed = db.parse(file_id); |
269 | let items: Vec<_> = | 285 | let items: Vec<_> = |
270 | parsed.syntax_node().descendants().filter_map(ast::ModuleItem::cast).collect(); | 286 | parsed.syntax_node().descendants().filter_map(ast::ModuleItem::cast).collect(); |
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index ac5485bc9..5ddecbdc6 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs | |||
@@ -646,12 +646,6 @@ mod clone { | |||
646 | fn infer_derive_clone_in_core() { | 646 | fn infer_derive_clone_in_core() { |
647 | let (db, pos) = TestDB::with_position( | 647 | let (db, pos) = TestDB::with_position( |
648 | r#" | 648 | r#" |
649 | //- /main.rs crate:main deps:core | ||
650 | use core::S; | ||
651 | fn test() { | ||
652 | S.clone()<|>; | ||
653 | } | ||
654 | |||
655 | //- /lib.rs crate:core | 649 | //- /lib.rs crate:core |
656 | #[prelude_import] | 650 | #[prelude_import] |
657 | use clone::*; | 651 | use clone::*; |
@@ -663,6 +657,11 @@ mod clone { | |||
663 | #[derive(Clone)] | 657 | #[derive(Clone)] |
664 | pub struct S; | 658 | pub struct S; |
665 | 659 | ||
660 | //- /main.rs crate:main deps:core | ||
661 | use core::S; | ||
662 | fn test() { | ||
663 | S.clone()<|>; | ||
664 | } | ||
666 | "#, | 665 | "#, |
667 | ); | 666 | ); |
668 | assert_eq!("S", type_at_pos(&db, pos)); | 667 | assert_eq!("S", type_at_pos(&db, pos)); |