@@ -113,7 +113,9 @@ pub struct TyLoweringContext<'a> {
113113 pub db : & ' a dyn HirDatabase ,
114114 resolver : & ' a Resolver ,
115115 in_binders : DebruijnIndex ,
116- owner : TypeOwnerId ,
116+ // FIXME: Should not be an `Option` but `Resolver` currently does not return owners in all cases
117+ // where expected
118+ owner : Option < TypeOwnerId > ,
117119 /// Note: Conceptually, it's thinkable that we could be in a location where
118120 /// some type params should be represented as placeholders, and others
119121 /// should be converted to variables. I think in practice, this isn't
@@ -127,6 +129,14 @@ pub struct TyLoweringContext<'a> {
127129
128130impl < ' a > TyLoweringContext < ' a > {
129131 pub fn new ( db : & ' a dyn HirDatabase , resolver : & ' a Resolver , owner : TypeOwnerId ) -> Self {
132+ Self :: new_maybe_unowned ( db, resolver, Some ( owner) )
133+ }
134+
135+ pub fn new_maybe_unowned (
136+ db : & ' a dyn HirDatabase ,
137+ resolver : & ' a Resolver ,
138+ owner : Option < TypeOwnerId > ,
139+ ) -> Self {
130140 let impl_trait_mode = ImplTraitLoweringState :: Disallowed ;
131141 let type_param_mode = ParamLoweringMode :: Placeholder ;
132142 let in_binders = DebruijnIndex :: INNERMOST ;
@@ -213,10 +223,11 @@ impl<'a> TyLoweringContext<'a> {
213223 }
214224
215225 pub fn lower_const ( & self , const_ref : & ConstRef , const_type : Ty ) -> Const {
226+ let Some ( owner) = self . owner else { return unknown_const ( const_type) } ;
216227 const_or_path_to_chalk (
217228 self . db ,
218229 self . resolver ,
219- self . owner ,
230+ owner,
220231 const_type,
221232 const_ref,
222233 self . type_param_mode ,
@@ -1768,10 +1779,11 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
17681779 let resolver = t. resolver ( db. upcast ( ) ) ;
17691780 let ctx = TyLoweringContext :: new ( db, & resolver, t. into ( ) )
17701781 . with_type_param_mode ( ParamLoweringMode :: Variable ) ;
1771- if db. type_alias_data ( t) . is_extern {
1782+ let type_alias_data = db. type_alias_data ( t) ;
1783+ if type_alias_data. is_extern {
17721784 Binders :: empty ( Interner , TyKind :: Foreign ( crate :: to_foreign_def_id ( t) ) . intern ( Interner ) )
17731785 } else {
1774- let type_ref = & db . type_alias_data ( t ) . type_ref ;
1786+ let type_ref = & type_alias_data. type_ref ;
17751787 let inner = ctx. lower_ty ( type_ref. as_deref ( ) . unwrap_or ( & TypeRef :: Error ) ) ;
17761788 make_binders ( db, & generics, inner)
17771789 }
@@ -2042,7 +2054,7 @@ pub(crate) fn const_or_path_to_chalk(
20422054 . intern_in_type_const ( InTypeConstLoc {
20432055 id : it,
20442056 owner,
2045- thing : Box :: new ( InTypeConstIdMetadata ( expected_ty. clone ( ) ) ) ,
2057+ expected_ty : Box :: new ( InTypeConstIdMetadata ( expected_ty. clone ( ) ) ) ,
20462058 } )
20472059 . into ( ) ;
20482060 intern_const_scalar (
0 commit comments