aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src/builtin_derive.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_expand/src/builtin_derive.rs')
-rw-r--r--crates/ra_hir_expand/src/builtin_derive.rs22
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..7f753bbca 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(
229mod tests { 229mod 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::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 name::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 name::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 name::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 name::known::Clone,
314 ); 312 );
315 313
316 assert_eq!( 314 assert_eq!(