aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r--crates/ra_hir_def/src/lib.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index a3d617e1f..24f9eb9e0 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -47,8 +47,8 @@ mod marks;
47use std::hash::Hash; 47use std::hash::Hash;
48 48
49use hir_expand::{ 49use hir_expand::{
50 ast_id_map::FileAstId, db::AstDatabase, eager::expand_eager_macro, hygiene::Hygiene, AstId, 50 ast_id_map::FileAstId, eager::expand_eager_macro, hygiene::Hygiene, AstId, HirFileId, InFile,
51 HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, 51 MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
52}; 52};
53use ra_arena::{impl_arena_id, RawId}; 53use ra_arena::{impl_arena_id, RawId};
54use ra_db::{impl_intern_key, salsa, CrateId}; 54use ra_db::{impl_intern_key, salsa, CrateId};
@@ -87,14 +87,14 @@ macro_rules! impl_intern {
87 87
88 impl Intern for $loc { 88 impl Intern for $loc {
89 type ID = $id; 89 type ID = $id;
90 fn intern(self, db: &impl db::DefDatabase) -> $id { 90 fn intern(self, db: &dyn db::DefDatabase) -> $id {
91 db.$intern(self) 91 db.$intern(self)
92 } 92 }
93 } 93 }
94 94
95 impl Lookup for $id { 95 impl Lookup for $id {
96 type Data = $loc; 96 type Data = $loc;
97 fn lookup(&self, db: &impl db::DefDatabase) -> $loc { 97 fn lookup(&self, db: &dyn db::DefDatabase) -> $loc {
98 db.$lookup(*self) 98 db.$lookup(*self)
99 } 99 }
100 } 100 }
@@ -339,20 +339,20 @@ impl_froms!(VariantId: EnumVariantId, StructId, UnionId);
339 339
340trait Intern { 340trait Intern {
341 type ID; 341 type ID;
342 fn intern(self, db: &impl db::DefDatabase) -> Self::ID; 342 fn intern(self, db: &dyn db::DefDatabase) -> Self::ID;
343} 343}
344 344
345pub trait Lookup { 345pub trait Lookup {
346 type Data; 346 type Data;
347 fn lookup(&self, db: &impl db::DefDatabase) -> Self::Data; 347 fn lookup(&self, db: &dyn db::DefDatabase) -> Self::Data;
348} 348}
349 349
350pub trait HasModule { 350pub trait HasModule {
351 fn module(&self, db: &impl db::DefDatabase) -> ModuleId; 351 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId;
352} 352}
353 353
354impl HasModule for ContainerId { 354impl HasModule for ContainerId {
355 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 355 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
356 match *self { 356 match *self {
357 ContainerId::ModuleId(it) => it, 357 ContainerId::ModuleId(it) => it,
358 ContainerId::DefWithBodyId(it) => it.module(db), 358 ContainerId::DefWithBodyId(it) => it.module(db),
@@ -361,7 +361,7 @@ impl HasModule for ContainerId {
361} 361}
362 362
363impl HasModule for AssocContainerId { 363impl HasModule for AssocContainerId {
364 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 364 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
365 match *self { 365 match *self {
366 AssocContainerId::ContainerId(it) => it.module(db), 366 AssocContainerId::ContainerId(it) => it.module(db),
367 AssocContainerId::ImplId(it) => it.lookup(db).container.module(db), 367 AssocContainerId::ImplId(it) => it.lookup(db).container.module(db),
@@ -371,13 +371,13 @@ impl HasModule for AssocContainerId {
371} 371}
372 372
373impl<N: AstNode> HasModule for AssocItemLoc<N> { 373impl<N: AstNode> HasModule for AssocItemLoc<N> {
374 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 374 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
375 self.container.module(db) 375 self.container.module(db)
376 } 376 }
377} 377}
378 378
379impl HasModule for AdtId { 379impl HasModule for AdtId {
380 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 380 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
381 match self { 381 match self {
382 AdtId::StructId(it) => it.lookup(db).container, 382 AdtId::StructId(it) => it.lookup(db).container,
383 AdtId::UnionId(it) => it.lookup(db).container, 383 AdtId::UnionId(it) => it.lookup(db).container,
@@ -388,7 +388,7 @@ impl HasModule for AdtId {
388} 388}
389 389
390impl HasModule for DefWithBodyId { 390impl HasModule for DefWithBodyId {
391 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 391 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
392 match self { 392 match self {
393 DefWithBodyId::FunctionId(it) => it.lookup(db).module(db), 393 DefWithBodyId::FunctionId(it) => it.lookup(db).module(db),
394 DefWithBodyId::StaticId(it) => it.lookup(db).module(db), 394 DefWithBodyId::StaticId(it) => it.lookup(db).module(db),
@@ -398,7 +398,7 @@ impl HasModule for DefWithBodyId {
398} 398}
399 399
400impl HasModule for GenericDefId { 400impl HasModule for GenericDefId {
401 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 401 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
402 match self { 402 match self {
403 GenericDefId::FunctionId(it) => it.lookup(db).module(db), 403 GenericDefId::FunctionId(it) => it.lookup(db).module(db),
404 GenericDefId::AdtId(it) => it.module(db), 404 GenericDefId::AdtId(it) => it.module(db),
@@ -412,7 +412,7 @@ impl HasModule for GenericDefId {
412} 412}
413 413
414impl HasModule for StaticLoc { 414impl HasModule for StaticLoc {
415 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 415 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
416 self.container.module(db) 416 self.container.module(db)
417 } 417 }
418} 418}
@@ -421,7 +421,7 @@ impl HasModule for StaticLoc {
421pub trait AsMacroCall { 421pub trait AsMacroCall {
422 fn as_call_id( 422 fn as_call_id(
423 &self, 423 &self,
424 db: &(impl db::DefDatabase + AstDatabase), 424 db: &dyn db::DefDatabase,
425 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 425 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
426 ) -> Option<MacroCallId>; 426 ) -> Option<MacroCallId>;
427} 427}
@@ -429,11 +429,11 @@ pub trait AsMacroCall {
429impl AsMacroCall for InFile<&ast::MacroCall> { 429impl AsMacroCall for InFile<&ast::MacroCall> {
430 fn as_call_id( 430 fn as_call_id(
431 &self, 431 &self,
432 db: &(impl db::DefDatabase + AstDatabase), 432 db: &dyn db::DefDatabase,
433 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 433 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
434 ) -> Option<MacroCallId> { 434 ) -> Option<MacroCallId> {
435 let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(self.value)); 435 let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(self.value));
436 let h = Hygiene::new(db, self.file_id); 436 let h = Hygiene::new(db.upcast(), self.file_id);
437 let path = path::ModPath::from_src(self.value.path()?, &h)?; 437 let path = path::ModPath::from_src(self.value.path()?, &h)?;
438 438
439 AstIdWithPath::new(ast_id.file_id, ast_id.value, path).as_call_id(db, resolver) 439 AstIdWithPath::new(ast_id.file_id, ast_id.value, path).as_call_id(db, resolver)
@@ -456,23 +456,23 @@ impl<T: ast::AstNode> AstIdWithPath<T> {
456impl AsMacroCall for AstIdWithPath<ast::MacroCall> { 456impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
457 fn as_call_id( 457 fn as_call_id(
458 &self, 458 &self,
459 db: &impl AstDatabase, 459 db: &dyn db::DefDatabase,
460 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 460 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
461 ) -> Option<MacroCallId> { 461 ) -> Option<MacroCallId> {
462 let def: MacroDefId = resolver(self.path.clone())?; 462 let def: MacroDefId = resolver(self.path.clone())?;
463 463
464 if let MacroDefKind::BuiltInEager(_) = def.kind { 464 if let MacroDefKind::BuiltInEager(_) = def.kind {
465 let macro_call = InFile::new(self.ast_id.file_id, self.ast_id.to_node(db)); 465 let macro_call = InFile::new(self.ast_id.file_id, self.ast_id.to_node(db.upcast()));
466 let hygiene = Hygiene::new(db, self.ast_id.file_id); 466 let hygiene = Hygiene::new(db.upcast(), self.ast_id.file_id);
467 467
468 Some( 468 Some(
469 expand_eager_macro(db, macro_call, def, &|path: ast::Path| { 469 expand_eager_macro(db.upcast(), macro_call, def, &|path: ast::Path| {
470 resolver(path::ModPath::from_src(path, &hygiene)?) 470 resolver(path::ModPath::from_src(path, &hygiene)?)
471 })? 471 })?
472 .into(), 472 .into(),
473 ) 473 )
474 } else { 474 } else {
475 Some(def.as_lazy_macro(db, MacroCallKind::FnLike(self.ast_id)).into()) 475 Some(def.as_lazy_macro(db.upcast(), MacroCallKind::FnLike(self.ast_id)).into())
476 } 476 }
477 } 477 }
478} 478}
@@ -480,10 +480,10 @@ impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
480impl AsMacroCall for AstIdWithPath<ast::ModuleItem> { 480impl AsMacroCall for AstIdWithPath<ast::ModuleItem> {
481 fn as_call_id( 481 fn as_call_id(
482 &self, 482 &self,
483 db: &impl AstDatabase, 483 db: &dyn db::DefDatabase,
484 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 484 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
485 ) -> Option<MacroCallId> { 485 ) -> Option<MacroCallId> {
486 let def = resolver(self.path.clone())?; 486 let def = resolver(self.path.clone())?;
487 Some(def.as_lazy_macro(db, MacroCallKind::Attr(self.ast_id)).into()) 487 Some(def.as_lazy_macro(db.upcast(), MacroCallKind::Attr(self.ast_id)).into())
488 } 488 }
489} 489}