diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-25 12:25:46 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-25 12:25:46 +0000 |
commit | 8d667bb32ed8460988bf9fe3515a6f8318adb8b0 (patch) | |
tree | 5d41d254dc94ff7d8d20063a08df2b9b133d34d9 /crates/ra_hir_expand/src/builtin_derive.rs | |
parent | e2dd17f75b1bb5e1185acff66211e74430177592 (diff) | |
parent | 2adc9a8d5f8f7686a125a478330c67a2d46fba98 (diff) |
Merge #3692
3692: Introduce `MacroDefKind::CustomDerive` r=matklad a=edwin0cheng
This PR introduce a new `MacroDefKind` `CustomDerive`. And use a new `ProcMacroExpander` for its expanding. And the expander is a dummy for now.
Related: #3654
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir_expand/src/builtin_derive.rs')
-rw-r--r-- | crates/ra_hir_expand/src/builtin_derive.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs index a5b50a832..79aea5806 100644 --- a/crates/ra_hir_expand/src/builtin_derive.rs +++ b/crates/ra_hir_expand/src/builtin_derive.rs | |||
@@ -229,9 +229,12 @@ fn partial_ord_expand( | |||
229 | mod tests { | 229 | mod tests { |
230 | use super::*; | 230 | use super::*; |
231 | use crate::{test_db::TestDB, AstId, MacroCallId, MacroCallKind, MacroCallLoc}; | 231 | use crate::{test_db::TestDB, AstId, MacroCallId, MacroCallKind, MacroCallLoc}; |
232 | use name::{known, Name}; | ||
232 | use ra_db::{fixture::WithFixture, SourceDatabase}; | 233 | use ra_db::{fixture::WithFixture, SourceDatabase}; |
233 | 234 | ||
234 | fn expand_builtin_derive(s: &str, expander: BuiltinDeriveExpander) -> String { | 235 | fn expand_builtin_derive(s: &str, name: Name) -> String { |
236 | let def = find_builtin_derive(&name).unwrap(); | ||
237 | |||
235 | let (db, file_id) = TestDB::with_single_file(&s); | 238 | let (db, file_id) = TestDB::with_single_file(&s); |
236 | let parsed = db.parse(file_id); | 239 | let parsed = db.parse(file_id); |
237 | let items: Vec<_> = | 240 | let items: Vec<_> = |
@@ -239,14 +242,9 @@ mod tests { | |||
239 | 242 | ||
240 | let ast_id_map = db.ast_id_map(file_id.into()); | 243 | let ast_id_map = db.ast_id_map(file_id.into()); |
241 | 244 | ||
242 | // the first one should be a macro_rules | 245 | let attr_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0])); |
243 | let def = | ||
244 | MacroDefId { krate: None, ast_id: None, kind: MacroDefKind::BuiltInDerive(expander) }; | ||
245 | 246 | ||
246 | let loc = MacroCallLoc { | 247 | let loc = MacroCallLoc { def, kind: MacroCallKind::Attr(attr_id, name.to_string()) }; |
247 | def, | ||
248 | kind: MacroCallKind::Attr(AstId::new(file_id.into(), ast_id_map.ast_id(&items[0]))), | ||
249 | }; | ||
250 | 248 | ||
251 | let id: MacroCallId = db.intern_macro(loc).into(); | 249 | let id: MacroCallId = db.intern_macro(loc).into(); |
252 | let parsed = db.parse_or_expand(id.as_file()).unwrap(); | 250 | let parsed = db.parse_or_expand(id.as_file()).unwrap(); |
@@ -263,7 +261,7 @@ mod tests { | |||
263 | #[derive(Copy)] | 261 | #[derive(Copy)] |
264 | struct Foo; | 262 | struct Foo; |
265 | "#, | 263 | "#, |
266 | BuiltinDeriveExpander::Copy, | 264 | known::Copy, |
267 | ); | 265 | ); |
268 | 266 | ||
269 | assert_eq!(expanded, "impl< >std::marker::CopyforFoo< >{}"); | 267 | assert_eq!(expanded, "impl< >std::marker::CopyforFoo< >{}"); |
@@ -276,7 +274,7 @@ mod tests { | |||
276 | #[derive(Copy)] | 274 | #[derive(Copy)] |
277 | struct Foo<A, B>; | 275 | struct Foo<A, B>; |
278 | "#, | 276 | "#, |
279 | BuiltinDeriveExpander::Copy, | 277 | known::Copy, |
280 | ); | 278 | ); |
281 | 279 | ||
282 | assert_eq!( | 280 | assert_eq!( |
@@ -292,7 +290,7 @@ mod tests { | |||
292 | #[derive(Copy)] | 290 | #[derive(Copy)] |
293 | struct Foo<A, B, 'a, 'b>; | 291 | struct Foo<A, B, 'a, 'b>; |
294 | "#, | 292 | "#, |
295 | BuiltinDeriveExpander::Copy, | 293 | known::Copy, |
296 | ); | 294 | ); |
297 | 295 | ||
298 | // We currently just ignore lifetimes | 296 | // We currently just ignore lifetimes |
@@ -310,7 +308,7 @@ mod tests { | |||
310 | #[derive(Clone)] | 308 | #[derive(Clone)] |
311 | struct Foo<A, B>; | 309 | struct Foo<A, B>; |
312 | "#, | 310 | "#, |
313 | BuiltinDeriveExpander::Clone, | 311 | known::Clone, |
314 | ); | 312 | ); |
315 | 313 | ||
316 | assert_eq!( | 314 | assert_eq!( |