@@ -429,6 +429,45 @@ impl Docs for EnumVariant {
429
429
}
430
430
}
431
431
432
+ /// The defs which have a body.
433
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
434
+ pub enum DefWithBody {
435
+ Function ( Function ) ,
436
+ Const ( Const ) ,
437
+ Static ( Static ) ,
438
+ }
439
+
440
+ impl_froms ! ( DefWithBody : Function , Const , Static ) ;
441
+
442
+ impl DefWithBody {
443
+ pub fn infer ( & self , db : & impl HirDatabase ) -> Arc < InferenceResult > {
444
+ db. infer ( * self )
445
+ }
446
+
447
+ pub fn body_source_map ( & self , db : & impl HirDatabase ) -> Arc < BodySourceMap > {
448
+ db. body_with_source_map ( * self ) . 1
449
+ }
450
+
451
+ pub fn body ( & self , db : & impl HirDatabase ) -> Arc < Body > {
452
+ db. body_hir ( * self )
453
+ }
454
+
455
+ /// Builds a resolver for code inside this item.
456
+ pub fn resolver ( & self , db : & impl HirDatabase ) -> Resolver {
457
+ match * self {
458
+ DefWithBody :: Const ( ref c) => c. resolver ( db) ,
459
+ DefWithBody :: Function ( ref f) => f. resolver ( db) ,
460
+ DefWithBody :: Static ( ref s) => s. resolver ( db) ,
461
+ }
462
+ }
463
+
464
+ pub fn scopes ( & self , db : & impl HirDatabase ) -> ScopesWithSourceMap {
465
+ let scopes = db. expr_scopes ( * self ) ;
466
+ let source_map = db. body_with_source_map ( * self ) . 1 ;
467
+ ScopesWithSourceMap { scopes, source_map }
468
+ }
469
+ }
470
+
432
471
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
433
472
pub struct Function {
434
473
pub ( crate ) id : FunctionId ,
@@ -479,20 +518,20 @@ impl Function {
479
518
}
480
519
481
520
pub fn body_source_map ( & self , db : & impl HirDatabase ) -> Arc < BodySourceMap > {
482
- db. body_with_source_map ( * self ) . 1
521
+ db. body_with_source_map ( ( * self ) . into ( ) ) . 1
483
522
}
484
523
485
524
pub fn body ( & self , db : & impl HirDatabase ) -> Arc < Body > {
486
- db. body_hir ( * self )
525
+ db. body_hir ( ( * self ) . into ( ) )
487
526
}
488
527
489
528
pub fn ty ( & self , db : & impl HirDatabase ) -> Ty {
490
529
db. type_for_def ( ( * self ) . into ( ) , Namespace :: Values )
491
530
}
492
531
493
532
pub fn scopes ( & self , db : & impl HirDatabase ) -> ScopesWithSourceMap {
494
- let scopes = db. expr_scopes ( * self ) ;
495
- let source_map = db. body_with_source_map ( * self ) . 1 ;
533
+ let scopes = db. expr_scopes ( ( * self ) . into ( ) ) ;
534
+ let source_map = db. body_with_source_map ( ( * self ) . into ( ) ) . 1 ;
496
535
ScopesWithSourceMap { scopes, source_map }
497
536
}
498
537
@@ -501,7 +540,7 @@ impl Function {
501
540
}
502
541
503
542
pub fn infer ( & self , db : & impl HirDatabase ) -> Arc < InferenceResult > {
504
- db. infer ( * self )
543
+ db. infer ( ( * self ) . into ( ) )
505
544
}
506
545
507
546
pub fn generic_params ( & self , db : & impl DefDatabase ) -> Arc < GenericParams > {
@@ -557,6 +596,14 @@ impl Const {
557
596
db. const_signature ( * self )
558
597
}
559
598
599
+ pub fn infer ( & self , db : & impl HirDatabase ) -> Arc < InferenceResult > {
600
+ db. infer ( ( * self ) . into ( ) )
601
+ }
602
+
603
+ pub fn body_source_map ( & self , db : & impl HirDatabase ) -> Arc < BodySourceMap > {
604
+ db. body_with_source_map ( ( * self ) . into ( ) ) . 1
605
+ }
606
+
560
607
/// The containing impl block, if this is a method.
561
608
pub fn impl_block ( & self , db : & impl DefDatabase ) -> Option < ImplBlock > {
562
609
let module_impls = db. impls_in_module ( self . module ( db) ) ;
@@ -621,6 +668,14 @@ impl Static {
621
668
// take the outer scope...
622
669
self . module ( db) . resolver ( db)
623
670
}
671
+
672
+ pub fn infer ( & self , db : & impl HirDatabase ) -> Arc < InferenceResult > {
673
+ db. infer ( ( * self ) . into ( ) )
674
+ }
675
+
676
+ pub fn body_source_map ( & self , db : & impl HirDatabase ) -> Arc < BodySourceMap > {
677
+ db. body_with_source_map ( ( * self ) . into ( ) ) . 1
678
+ }
624
679
}
625
680
626
681
impl Docs for Static {
0 commit comments