@@ -55,8 +55,8 @@ use hir_def::{
55
55
resolver:: { HasResolver , Resolver } ,
56
56
type_ref:: TypesSourceMap ,
57
57
AdtId , AssocItemId , AssocItemLoc , AttrDefId , CallableDefId , ConstId , ConstParamId ,
58
- CrateRootModuleId , DefWithBodyId , EnumId , EnumVariantId , ExternCrateId , FunctionId ,
59
- GenericDefId , GenericParamId , HasModule , ImplId , InTypeConstId , ItemContainerId ,
58
+ CrateRootModuleId , DefWithBodyId , EnumId , EnumVariantId , ExternBlockId , ExternCrateId ,
59
+ FunctionId , GenericDefId , GenericParamId , HasModule , ImplId , InTypeConstId , ItemContainerId ,
60
60
LifetimeParamId , LocalFieldId , Lookup , MacroExpander , MacroId , ModuleId , StaticId , StructId ,
61
61
SyntheticSyntax , TraitAliasId , TupleId , TypeAliasId , TypeOrConstParamId , TypeParamId , UnionId ,
62
62
} ;
@@ -2327,6 +2327,13 @@ impl Function {
2327
2327
db. function_data ( self . id ) . is_async ( )
2328
2328
}
2329
2329
2330
+ pub fn extern_block ( self , db : & dyn HirDatabase ) -> Option < ExternBlock > {
2331
+ match self . id . lookup ( db. upcast ( ) ) . container {
2332
+ ItemContainerId :: ExternBlockId ( id) => Some ( ExternBlock { id } ) ,
2333
+ _ => None ,
2334
+ }
2335
+ }
2336
+
2330
2337
pub fn returns_impl_future ( self , db : & dyn HirDatabase ) -> bool {
2331
2338
if self . is_async ( db) {
2332
2339
return true ;
@@ -2761,6 +2768,13 @@ impl Static {
2761
2768
Type :: from_value_def ( db, self . id )
2762
2769
}
2763
2770
2771
+ pub fn extern_block ( self , db : & dyn HirDatabase ) -> Option < ExternBlock > {
2772
+ match self . id . lookup ( db. upcast ( ) ) . container {
2773
+ ItemContainerId :: ExternBlockId ( id) => Some ( ExternBlock { id } ) ,
2774
+ _ => None ,
2775
+ }
2776
+ }
2777
+
2764
2778
/// Evaluate the static initializer.
2765
2779
pub fn eval ( self , db : & dyn HirDatabase ) -> Result < EvaluatedConst , ConstEvalError > {
2766
2780
db. const_eval ( self . id . into ( ) , Substitution :: empty ( Interner ) , None )
@@ -2928,6 +2942,17 @@ impl HasVisibility for TypeAlias {
2928
2942
}
2929
2943
}
2930
2944
2945
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
2946
+ pub struct ExternBlock {
2947
+ pub ( crate ) id : ExternBlockId ,
2948
+ }
2949
+
2950
+ impl ExternBlock {
2951
+ pub fn module ( self , db : & dyn HirDatabase ) -> Module {
2952
+ Module { id : self . id . module ( db. upcast ( ) ) }
2953
+ }
2954
+ }
2955
+
2931
2956
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
2932
2957
pub struct StaticLifetime ;
2933
2958
@@ -6180,9 +6205,15 @@ impl HasContainer for TraitAlias {
6180
6205
}
6181
6206
}
6182
6207
6208
+ impl HasContainer for ExternBlock {
6209
+ fn container ( & self , db : & dyn HirDatabase ) -> ItemContainer {
6210
+ ItemContainer :: Module ( Module { id : self . id . lookup ( db. upcast ( ) ) . container } )
6211
+ }
6212
+ }
6213
+
6183
6214
fn container_id_to_hir ( c : ItemContainerId ) -> ItemContainer {
6184
6215
match c {
6185
- ItemContainerId :: ExternBlockId ( _id ) => ItemContainer :: ExternBlock ( ) ,
6216
+ ItemContainerId :: ExternBlockId ( id ) => ItemContainer :: ExternBlock ( ExternBlock { id } ) ,
6186
6217
ItemContainerId :: ModuleId ( id) => ItemContainer :: Module ( Module { id } ) ,
6187
6218
ItemContainerId :: ImplId ( id) => ItemContainer :: Impl ( Impl { id } ) ,
6188
6219
ItemContainerId :: TraitId ( id) => ItemContainer :: Trait ( Trait { id } ) ,
@@ -6194,7 +6225,7 @@ pub enum ItemContainer {
6194
6225
Trait ( Trait ) ,
6195
6226
Impl ( Impl ) ,
6196
6227
Module ( Module ) ,
6197
- ExternBlock ( ) ,
6228
+ ExternBlock ( ExternBlock ) ,
6198
6229
Crate ( CrateId ) ,
6199
6230
}
6200
6231
0 commit comments