@@ -436,73 +436,40 @@ impl Docs for EnumVariant {
436
436
/// The defs which have a body.
437
437
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
438
438
pub enum DefWithBody {
439
- Func ( Function ) ,
439
+ Function ( Function ) ,
440
440
Const ( Const ) ,
441
441
Static ( Static ) ,
442
442
}
443
443
444
- impl DefWithBody {
445
- pub fn get_funct ( & self ) -> & Function {
446
- match * self {
447
- DefWithBody :: Func ( ref f) => f,
448
- _ => unreachable ! ( )
449
- }
450
- }
451
-
452
- pub fn const_source ( & self , db : & impl DefDatabase ) -> ( HirFileId , TreeArc < ast:: ConstDef > ) {
453
- match * self {
454
- DefWithBody :: Const ( ref c) => c. source ( db) ,
455
- _ => unreachable ! ( )
456
- }
457
- }
458
-
459
- pub fn func_source ( & self , db : & impl DefDatabase ) -> ( HirFileId , TreeArc < ast:: FnDef > ) {
460
- match * self {
461
- DefWithBody :: Func ( ref f) => f. source ( db) ,
462
- _ => unreachable ! ( )
463
- }
464
- }
465
-
466
- pub fn static_source ( & self , db : & impl DefDatabase ) -> ( HirFileId , TreeArc < ast:: StaticDef > ) {
467
- match * self {
468
- DefWithBody :: Static ( ref s) => s. source ( db) ,
469
- _ => unreachable ! ( )
470
- }
471
- }
444
+ impl_froms ! ( DefWithBody : Function , Const , Static ) ;
472
445
446
+ impl DefWithBody {
473
447
pub fn infer ( & self , db : & impl HirDatabase ) -> Arc < InferenceResult > {
474
448
db. infer ( * self )
475
449
}
476
450
451
+ pub fn body_source_map ( & self , db : & impl HirDatabase ) -> Arc < BodySourceMap > {
452
+ db. body_with_source_map ( * self ) . 1
453
+ }
454
+
477
455
pub fn body ( & self , db : & impl HirDatabase ) -> Arc < Body > {
478
456
db. body_hir ( * self )
479
457
}
480
-
458
+
481
459
/// Builds a resolver for code inside this item.
482
460
pub fn resolver ( & self , db : & impl HirDatabase ) -> Resolver {
483
- // // take the outer scope...
484
- // let r = self
485
- // .impl_block(db)
486
- // .map(|ib| ib.resolver(db))
487
- // .unwrap_or_else(|| self.module(db).resolver(db));
488
- // // ...and add generic params, if present
489
- // let p = self.generic_params(db);
490
- // let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
491
- // r
492
- unimplemented ! ( )
493
- }
494
-
495
- pub fn signature ( & self , db : & impl HirDatabase ) -> Arc < FnSignature > {
496
- // db.fn_signature(*self)
497
- unimplemented ! ( )
461
+ match * self {
462
+ DefWithBody :: Const ( ref c) => c. resolver ( db) ,
463
+ DefWithBody :: Function ( ref f) => f. resolver ( db) ,
464
+ DefWithBody :: Static ( ref s) => s. resolver ( db) ,
465
+ }
498
466
}
499
467
500
468
pub fn scopes ( & self , db : & impl HirDatabase ) -> ScopesWithSourceMap {
501
469
let scopes = db. expr_scopes ( * self ) ;
502
470
let source_map = db. body_with_source_map ( * self ) . 1 ;
503
471
ScopesWithSourceMap { scopes, source_map }
504
472
}
505
-
506
473
}
507
474
508
475
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
@@ -555,20 +522,20 @@ impl Function {
555
522
}
556
523
557
524
pub fn body_source_map ( & self , db : & impl HirDatabase ) -> Arc < BodySourceMap > {
558
- db. body_with_source_map ( DefWithBody :: Func ( * self ) ) . 1
525
+ db. body_with_source_map ( ( * self ) . into ( ) ) . 1
559
526
}
560
527
561
528
pub fn body ( & self , db : & impl HirDatabase ) -> Arc < Body > {
562
- db. body_hir ( DefWithBody :: Func ( * self ) )
529
+ db. body_hir ( ( * self ) . into ( ) )
563
530
}
564
531
565
532
pub fn ty ( & self , db : & impl HirDatabase ) -> Ty {
566
533
db. type_for_def ( ( * self ) . into ( ) , Namespace :: Values )
567
534
}
568
535
569
536
pub fn scopes ( & self , db : & impl HirDatabase ) -> ScopesWithSourceMap {
570
- let scopes = db. expr_scopes ( DefWithBody :: Func ( * self ) ) ;
571
- let source_map = db. body_with_source_map ( DefWithBody :: Func ( * self ) ) . 1 ;
537
+ let scopes = db. expr_scopes ( ( * self ) . into ( ) ) ;
538
+ let source_map = db. body_with_source_map ( ( * self ) . into ( ) ) . 1 ;
572
539
ScopesWithSourceMap { scopes, source_map }
573
540
}
574
541
@@ -577,7 +544,7 @@ impl Function {
577
544
}
578
545
579
546
pub fn infer ( & self , db : & impl HirDatabase ) -> Arc < InferenceResult > {
580
- db. infer ( DefWithBody :: Func ( * self ) )
547
+ db. infer ( ( * self ) . into ( ) )
581
548
}
582
549
583
550
pub fn generic_params ( & self , db : & impl DefDatabase ) -> Arc < GenericParams > {
@@ -633,6 +600,14 @@ impl Const {
633
600
db. const_signature ( * self )
634
601
}
635
602
603
+ pub fn infer ( & self , db : & impl HirDatabase ) -> Arc < InferenceResult > {
604
+ db. infer ( ( * self ) . into ( ) )
605
+ }
606
+
607
+ pub fn body_source_map ( & self , db : & impl HirDatabase ) -> Arc < BodySourceMap > {
608
+ db. body_with_source_map ( ( * self ) . into ( ) ) . 1
609
+ }
610
+
636
611
/// The containing impl block, if this is a method.
637
612
pub fn impl_block ( & self , db : & impl DefDatabase ) -> Option < ImplBlock > {
638
613
let module_impls = db. impls_in_module ( self . module ( db) ) ;
@@ -697,6 +672,14 @@ impl Static {
697
672
// take the outer scope...
698
673
self . module ( db) . resolver ( db)
699
674
}
675
+
676
+ pub fn infer ( & self , db : & impl HirDatabase ) -> Arc < InferenceResult > {
677
+ db. infer ( ( * self ) . into ( ) )
678
+ }
679
+
680
+ pub fn body_source_map ( & self , db : & impl HirDatabase ) -> Arc < BodySourceMap > {
681
+ db. body_with_source_map ( ( * self ) . into ( ) ) . 1
682
+ }
700
683
}
701
684
702
685
impl Docs for Static {
@@ -788,4 +771,4 @@ impl Docs for TypeAlias {
788
771
fn docs ( & self , db : & impl HirDatabase ) -> Option < Documentation > {
789
772
docs_from_ast ( & * self . source ( db) . 1 )
790
773
}
791
- }
774
+ }
0 commit comments