@@ -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
@@ -6177,9 +6202,15 @@ impl HasContainer for TraitAlias {
6177
6202
}
6178
6203
}
6179
6204
6205
+ impl HasContainer for ExternBlock {
6206
+ fn container ( & self , db : & dyn HirDatabase ) -> ItemContainer {
6207
+ ItemContainer :: Module ( Module { id : self . id . lookup ( db. upcast ( ) ) . container } )
6208
+ }
6209
+ }
6210
+
6180
6211
fn container_id_to_hir ( c : ItemContainerId ) -> ItemContainer {
6181
6212
match c {
6182
- ItemContainerId :: ExternBlockId ( _id ) => ItemContainer :: ExternBlock ( ) ,
6213
+ ItemContainerId :: ExternBlockId ( id ) => ItemContainer :: ExternBlock ( ExternBlock { id } ) ,
6183
6214
ItemContainerId :: ModuleId ( id) => ItemContainer :: Module ( Module { id } ) ,
6184
6215
ItemContainerId :: ImplId ( id) => ItemContainer :: Impl ( Impl { id } ) ,
6185
6216
ItemContainerId :: TraitId ( id) => ItemContainer :: Trait ( Trait { id } ) ,
@@ -6191,7 +6222,7 @@ pub enum ItemContainer {
6191
6222
Trait ( Trait ) ,
6192
6223
Impl ( Impl ) ,
6193
6224
Module ( Module ) ,
6194
- ExternBlock ( ) ,
6225
+ ExternBlock ( ExternBlock ) ,
6195
6226
Crate ( CrateId ) ,
6196
6227
}
6197
6228
0 commit comments