@@ -113,7 +113,9 @@ pub struct TyLoweringContext<'a> {
113
113
pub db : & ' a dyn HirDatabase ,
114
114
resolver : & ' a Resolver ,
115
115
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 > ,
117
119
/// Note: Conceptually, it's thinkable that we could be in a location where
118
120
/// some type params should be represented as placeholders, and others
119
121
/// should be converted to variables. I think in practice, this isn't
@@ -127,6 +129,14 @@ pub struct TyLoweringContext<'a> {
127
129
128
130
impl < ' a > TyLoweringContext < ' a > {
129
131
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 {
130
140
let impl_trait_mode = ImplTraitLoweringState :: Disallowed ;
131
141
let type_param_mode = ParamLoweringMode :: Placeholder ;
132
142
let in_binders = DebruijnIndex :: INNERMOST ;
@@ -213,10 +223,11 @@ impl<'a> TyLoweringContext<'a> {
213
223
}
214
224
215
225
pub fn lower_const ( & self , const_ref : & ConstRef , const_type : Ty ) -> Const {
226
+ let Some ( owner) = self . owner else { return unknown_const ( const_type) } ;
216
227
const_or_path_to_chalk (
217
228
self . db ,
218
229
self . resolver ,
219
- self . owner ,
230
+ owner,
220
231
const_type,
221
232
const_ref,
222
233
self . type_param_mode ,
@@ -1768,10 +1779,11 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
1768
1779
let resolver = t. resolver ( db. upcast ( ) ) ;
1769
1780
let ctx = TyLoweringContext :: new ( db, & resolver, t. into ( ) )
1770
1781
. 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 {
1772
1784
Binders :: empty ( Interner , TyKind :: Foreign ( crate :: to_foreign_def_id ( t) ) . intern ( Interner ) )
1773
1785
} else {
1774
- let type_ref = & db . type_alias_data ( t ) . type_ref ;
1786
+ let type_ref = & type_alias_data. type_ref ;
1775
1787
let inner = ctx. lower_ty ( type_ref. as_deref ( ) . unwrap_or ( & TypeRef :: Error ) ) ;
1776
1788
make_binders ( db, & generics, inner)
1777
1789
}
@@ -2042,7 +2054,7 @@ pub(crate) fn const_or_path_to_chalk(
2042
2054
. intern_in_type_const ( InTypeConstLoc {
2043
2055
id : it,
2044
2056
owner,
2045
- thing : Box :: new ( InTypeConstIdMetadata ( expected_ty. clone ( ) ) ) ,
2057
+ expected_ty : Box :: new ( InTypeConstIdMetadata ( expected_ty. clone ( ) ) ) ,
2046
2058
} )
2047
2059
. into ( ) ;
2048
2060
intern_const_scalar (
0 commit comments