@@ -102,15 +102,8 @@ pub enum TypeNs {
102
102
BuiltinType ( BuiltinType ) ,
103
103
TraitId ( TraitId ) ,
104
104
TraitAliasId ( TraitAliasId ) ,
105
- // Module belong to type ns, but the resolver is used when all module paths
106
- // are fully resolved.
107
- // ModuleId(ModuleId)
108
- }
109
105
110
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
111
- pub enum ModuleOrTypeNs {
112
- ModuleNs ( ModuleId ) ,
113
- TypeNs ( TypeNs ) ,
106
+ ModuleId ( ModuleId ) ,
114
107
}
115
108
116
109
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
@@ -173,7 +166,7 @@ impl Resolver {
173
166
& self ,
174
167
db : & dyn DefDatabase ,
175
168
path : & Path ,
176
- ) -> Option < ( ModuleOrTypeNs , Option < usize > , Option < ImportOrExternCrate > ) > {
169
+ ) -> Option < ( TypeNs , Option < usize > , Option < ImportOrExternCrate > ) > {
177
170
self . resolve_path_in_type_ns_with_prefix_info ( db, path) . map (
178
171
|( resolution, remaining_segments, import, _) | ( resolution, remaining_segments, import) ,
179
172
)
@@ -183,12 +176,8 @@ impl Resolver {
183
176
& self ,
184
177
db : & dyn DefDatabase ,
185
178
path : & Path ,
186
- ) -> Option < (
187
- ModuleOrTypeNs ,
188
- Option < usize > ,
189
- Option < ImportOrExternCrate > ,
190
- ResolvePathResultPrefixInfo ,
191
- ) > {
179
+ ) -> Option < ( TypeNs , Option < usize > , Option < ImportOrExternCrate > , ResolvePathResultPrefixInfo ) >
180
+ {
192
181
let path = match path {
193
182
Path :: BarePath ( mod_path) => mod_path,
194
183
Path :: Normal ( it) => & it. mod_path ,
@@ -205,7 +194,7 @@ impl Resolver {
205
194
| LangItemTarget :: Static ( _) => return None ,
206
195
} ;
207
196
return Some ( (
208
- ModuleOrTypeNs :: TypeNs ( type_ns) ,
197
+ type_ns,
209
198
seg. as_ref ( ) . map ( |_| 1 ) ,
210
199
None ,
211
200
ResolvePathResultPrefixInfo :: default ( ) ,
@@ -215,7 +204,7 @@ impl Resolver {
215
204
let first_name = path. segments ( ) . first ( ) ?;
216
205
let skip_to_mod = path. kind != PathKind :: Plain ;
217
206
if skip_to_mod {
218
- return self . module_scope . resolve_path_in_module_or_type_ns ( db, path) ;
207
+ return self . module_scope . resolve_path_in_type_ns ( db, path) ;
219
208
}
220
209
221
210
let remaining_idx = || {
@@ -228,7 +217,7 @@ impl Resolver {
228
217
Scope :: GenericParams { params, def } => {
229
218
if let Some ( id) = params. find_type_by_name ( first_name, * def) {
230
219
return Some ( (
231
- ModuleOrTypeNs :: TypeNs ( TypeNs :: GenericParam ( id) ) ,
220
+ TypeNs :: GenericParam ( id) ,
232
221
remaining_idx ( ) ,
233
222
None ,
234
223
ResolvePathResultPrefixInfo :: default ( ) ,
@@ -238,7 +227,7 @@ impl Resolver {
238
227
& Scope :: ImplDefScope ( impl_) => {
239
228
if * first_name == sym:: Self_ . clone ( ) {
240
229
return Some ( (
241
- ModuleOrTypeNs :: TypeNs ( TypeNs :: SelfType ( impl_) ) ,
230
+ TypeNs :: SelfType ( impl_) ,
242
231
remaining_idx ( ) ,
243
232
None ,
244
233
ResolvePathResultPrefixInfo :: default ( ) ,
@@ -248,24 +237,23 @@ impl Resolver {
248
237
& Scope :: AdtScope ( adt) => {
249
238
if * first_name == sym:: Self_ . clone ( ) {
250
239
return Some ( (
251
- ModuleOrTypeNs :: TypeNs ( TypeNs :: AdtSelfType ( adt) ) ,
240
+ TypeNs :: AdtSelfType ( adt) ,
252
241
remaining_idx ( ) ,
253
242
None ,
254
243
ResolvePathResultPrefixInfo :: default ( ) ,
255
244
) ) ;
256
245
}
257
246
}
258
247
Scope :: BlockScope ( m) => {
259
- if let Some ( res) = m. resolve_path_in_module_or_type_ns ( db, path) {
248
+ if let Some ( res) = m. resolve_path_in_type_ns ( db, path) {
260
249
let res = match res. 0 {
261
- ModuleOrTypeNs :: TypeNs ( _) => res,
262
- ModuleOrTypeNs :: ModuleNs ( _) => {
250
+ TypeNs :: ModuleId ( _) => {
263
251
if let Some ( ModuleDefId :: BuiltinType ( builtin) ) = BUILTIN_SCOPE
264
252
. get ( first_name)
265
253
. and_then ( |builtin| builtin. take_types ( ) )
266
254
{
267
255
(
268
- ModuleOrTypeNs :: TypeNs ( TypeNs :: BuiltinType ( builtin) ) ,
256
+ TypeNs :: BuiltinType ( builtin) ,
269
257
remaining_idx ( ) ,
270
258
None ,
271
259
ResolvePathResultPrefixInfo :: default ( ) ,
@@ -274,25 +262,26 @@ impl Resolver {
274
262
res
275
263
}
276
264
}
265
+ _ => res,
277
266
} ;
278
267
return Some ( res) ;
279
268
}
280
269
}
281
270
}
282
271
}
283
- self . module_scope . resolve_path_in_module_or_type_ns ( db, path)
272
+ self . module_scope . resolve_path_in_type_ns ( db, path)
284
273
}
285
274
286
275
pub fn resolve_path_in_type_ns_fully (
287
276
& self ,
288
277
db : & dyn DefDatabase ,
289
278
path : & Path ,
290
279
) -> Option < TypeNs > {
291
- if let ( ModuleOrTypeNs :: TypeNs ( res) , None , _) = self . resolve_path_in_type_ns ( db, path) ? {
292
- Some ( res)
293
- } else {
294
- None
280
+ let ( res, unresolved, _) = self . resolve_path_in_type_ns ( db, path) ?;
281
+ if unresolved. is_some ( ) {
282
+ return None ;
295
283
}
284
+ Some ( res)
296
285
}
297
286
298
287
pub fn resolve_visibility (
@@ -1182,24 +1171,20 @@ impl ModuleItemMap {
1182
1171
}
1183
1172
}
1184
1173
1185
- fn resolve_path_in_module_or_type_ns (
1174
+ fn resolve_path_in_type_ns (
1186
1175
& self ,
1187
1176
db : & dyn DefDatabase ,
1188
1177
path : & ModPath ,
1189
- ) -> Option < (
1190
- ModuleOrTypeNs ,
1191
- Option < usize > ,
1192
- Option < ImportOrExternCrate > ,
1193
- ResolvePathResultPrefixInfo ,
1194
- ) > {
1178
+ ) -> Option < ( TypeNs , Option < usize > , Option < ImportOrExternCrate > , ResolvePathResultPrefixInfo ) >
1179
+ {
1195
1180
let ( module_def, idx, prefix_info) = self . def_map . resolve_path_locally (
1196
1181
& self . local_def_map ,
1197
1182
db,
1198
1183
self . module_id ,
1199
1184
path,
1200
1185
BuiltinShadowMode :: Other ,
1201
1186
) ;
1202
- let ( res, import) = to_module_or_type_ns ( module_def) ?;
1187
+ let ( res, import) = to_type_ns ( module_def) ?;
1203
1188
Some ( ( res, idx, import, prefix_info) )
1204
1189
}
1205
1190
}
@@ -1224,19 +1209,19 @@ fn to_value_ns(per_ns: PerNs) -> Option<(ValueNs, Option<ImportOrGlob>)> {
1224
1209
Some ( ( res, import) )
1225
1210
}
1226
1211
1227
- fn to_module_or_type_ns ( per_ns : PerNs ) -> Option < ( ModuleOrTypeNs , Option < ImportOrExternCrate > ) > {
1212
+ fn to_type_ns ( per_ns : PerNs ) -> Option < ( TypeNs , Option < ImportOrExternCrate > ) > {
1228
1213
let def = per_ns. take_types_full ( ) ?;
1229
1214
let res = match def. def {
1230
- ModuleDefId :: AdtId ( it) => ModuleOrTypeNs :: TypeNs ( TypeNs :: AdtId ( it) ) ,
1231
- ModuleDefId :: EnumVariantId ( it) => ModuleOrTypeNs :: TypeNs ( TypeNs :: EnumVariantId ( it) ) ,
1215
+ ModuleDefId :: AdtId ( it) => TypeNs :: AdtId ( it) ,
1216
+ ModuleDefId :: EnumVariantId ( it) => TypeNs :: EnumVariantId ( it) ,
1232
1217
1233
- ModuleDefId :: TypeAliasId ( it) => ModuleOrTypeNs :: TypeNs ( TypeNs :: TypeAliasId ( it) ) ,
1234
- ModuleDefId :: BuiltinType ( it) => ModuleOrTypeNs :: TypeNs ( TypeNs :: BuiltinType ( it) ) ,
1218
+ ModuleDefId :: TypeAliasId ( it) => TypeNs :: TypeAliasId ( it) ,
1219
+ ModuleDefId :: BuiltinType ( it) => TypeNs :: BuiltinType ( it) ,
1235
1220
1236
- ModuleDefId :: TraitId ( it) => ModuleOrTypeNs :: TypeNs ( TypeNs :: TraitId ( it) ) ,
1237
- ModuleDefId :: TraitAliasId ( it) => ModuleOrTypeNs :: TypeNs ( TypeNs :: TraitAliasId ( it) ) ,
1221
+ ModuleDefId :: TraitId ( it) => TypeNs :: TraitId ( it) ,
1222
+ ModuleDefId :: TraitAliasId ( it) => TypeNs :: TraitAliasId ( it) ,
1238
1223
1239
- ModuleDefId :: ModuleId ( it) => ModuleOrTypeNs :: ModuleNs ( it) ,
1224
+ ModuleDefId :: ModuleId ( it) => TypeNs :: ModuleId ( it) ,
1240
1225
1241
1226
ModuleDefId :: FunctionId ( _)
1242
1227
| ModuleDefId :: ConstId ( _)
0 commit comments