@@ -169,33 +169,26 @@ impl Resolver {
169
169
self . resolve_module_path ( db, path, BuiltinShadowMode :: Module )
170
170
}
171
171
172
- pub fn resolve_path_in_type_ns < ' a > (
173
- & ' a self ,
174
- db : & ' a dyn DefDatabase ,
175
- path : & ' a Path ,
176
- ) -> impl Iterator < Item = ( ModuleOrTypeNs , Option < usize > , Option < ImportOrExternCrate > ) > + ' a
177
- {
172
+ pub fn resolve_path_in_type_ns (
173
+ & self ,
174
+ db : & dyn DefDatabase ,
175
+ path : & Path ,
176
+ ) -> Option < ( ModuleOrTypeNs , Option < usize > , Option < ImportOrExternCrate > ) > {
178
177
self . resolve_path_in_type_ns_with_prefix_info ( db, path) . map (
179
- move |( resolution, remaining_segments, import, _) | {
180
- ( resolution, remaining_segments, import)
181
- } ,
178
+ |( resolution, remaining_segments, import, _) | ( resolution, remaining_segments, import) ,
182
179
)
183
180
}
184
181
185
- pub fn resolve_path_in_type_ns_with_prefix_info < ' a > (
186
- & ' a self ,
187
- db : & ' a dyn DefDatabase ,
188
- path : & ' a Path ,
189
- ) -> Box <
190
- dyn Iterator <
191
- Item = (
192
- ModuleOrTypeNs ,
193
- Option < usize > ,
194
- Option < ImportOrExternCrate > ,
195
- ResolvePathResultPrefixInfo ,
196
- ) ,
197
- > + ' a ,
198
- > {
182
+ pub fn resolve_path_in_type_ns_with_prefix_info (
183
+ & self ,
184
+ db : & dyn DefDatabase ,
185
+ path : & Path ,
186
+ ) -> Option < (
187
+ ModuleOrTypeNs ,
188
+ Option < usize > ,
189
+ Option < ImportOrExternCrate > ,
190
+ ResolvePathResultPrefixInfo ,
191
+ ) > {
199
192
let path = match path {
200
193
Path :: BarePath ( mod_path) => mod_path,
201
194
Path :: Normal ( it) => & it. mod_path ,
@@ -209,30 +202,29 @@ impl Resolver {
209
202
LangItemTarget :: Trait ( it) => TypeNs :: TraitId ( it) ,
210
203
LangItemTarget :: Function ( _)
211
204
| LangItemTarget :: ImplDef ( _)
212
- | LangItemTarget :: Static ( _) => return Box :: new ( iter :: empty ( ) ) ,
205
+ | LangItemTarget :: Static ( _) => return None ,
213
206
} ;
214
- return Box :: new ( iter :: once ( (
207
+ return Some ( (
215
208
ModuleOrTypeNs :: TypeNs ( type_ns) ,
216
209
seg. as_ref ( ) . map ( |_| 1 ) ,
217
210
None ,
218
211
ResolvePathResultPrefixInfo :: default ( ) ,
219
- ) ) ) ;
212
+ ) ) ;
220
213
}
221
214
} ;
222
- let Some ( first_name) = path. segments ( ) . first ( ) else { return Box :: new ( iter :: empty ( ) ) } ;
215
+ let first_name = path. segments ( ) . first ( ) ? ;
223
216
let skip_to_mod = path. kind != PathKind :: Plain ;
224
217
if skip_to_mod {
225
- return Box :: new ( self . module_scope . resolve_path_in_type_ns ( db, path) . into_iter ( ) ) ;
218
+ return self . module_scope . resolve_path_in_module_or_type_ns ( db, path) ;
226
219
}
227
220
228
221
let remaining_idx = || {
229
222
if path. segments ( ) . len ( ) == 1 { None } else { Some ( 1 ) }
230
223
} ;
231
224
232
- let ns = self
233
- . scopes ( )
234
- . filter_map ( move |scope| match scope {
235
- Scope :: ExprScope ( _) | Scope :: MacroDefScope ( _) => None ,
225
+ for scope in self . scopes ( ) {
226
+ match scope {
227
+ Scope :: ExprScope ( _) | Scope :: MacroDefScope ( _) => continue ,
236
228
Scope :: GenericParams { params, def } => {
237
229
if let Some ( id) = params. find_type_by_name ( first_name, * def) {
238
230
return Some ( (
@@ -242,7 +234,6 @@ impl Resolver {
242
234
ResolvePathResultPrefixInfo :: default ( ) ,
243
235
) ) ;
244
236
}
245
- None
246
237
}
247
238
& Scope :: ImplDefScope ( impl_) => {
248
239
if * first_name == sym:: Self_ . clone ( ) {
@@ -253,7 +244,6 @@ impl Resolver {
253
244
ResolvePathResultPrefixInfo :: default ( ) ,
254
245
) ) ;
255
246
}
256
- None
257
247
}
258
248
& Scope :: AdtScope ( adt) => {
259
249
if * first_name == sym:: Self_ . clone ( ) {
@@ -264,36 +254,45 @@ impl Resolver {
264
254
ResolvePathResultPrefixInfo :: default ( ) ,
265
255
) ) ;
266
256
}
267
- None
268
257
}
269
258
Scope :: BlockScope ( m) => {
270
- if let Some ( res) = m. resolve_path_in_type_ns ( db, path) {
259
+ if let Some ( res) = m. resolve_path_in_module_or_type_ns ( db, path) {
260
+ let res = match res. 0 {
261
+ ModuleOrTypeNs :: TypeNs ( _) => res,
262
+ ModuleOrTypeNs :: ModuleNs ( _) => {
263
+ if let Some ( ModuleDefId :: BuiltinType ( builtin) ) = BUILTIN_SCOPE
264
+ . get ( first_name)
265
+ . and_then ( |builtin| builtin. take_types ( ) )
266
+ {
267
+ (
268
+ ModuleOrTypeNs :: TypeNs ( TypeNs :: BuiltinType ( builtin) ) ,
269
+ remaining_idx ( ) ,
270
+ None ,
271
+ ResolvePathResultPrefixInfo :: default ( ) ,
272
+ )
273
+ } else {
274
+ res
275
+ }
276
+ }
277
+ } ;
271
278
return Some ( res) ;
272
279
}
273
- None
274
280
}
275
- } )
276
- . chain ( self . module_scope . resolve_path_in_type_ns ( db, path) ) ;
277
-
278
- Box :: new ( ns)
281
+ }
282
+ }
283
+ self . module_scope . resolve_path_in_module_or_type_ns ( db, path)
279
284
}
280
285
281
286
pub fn resolve_path_in_type_ns_fully (
282
287
& self ,
283
288
db : & dyn DefDatabase ,
284
289
path : & Path ,
285
290
) -> Option < TypeNs > {
286
- let ( res, unresolved) = self
287
- . resolve_path_in_type_ns ( db, path)
288
- . filter_map ( |( res, unresolved, _) | match res {
289
- ModuleOrTypeNs :: TypeNs ( it) => Some ( ( it, unresolved) ) ,
290
- ModuleOrTypeNs :: ModuleNs ( _) => None ,
291
- } )
292
- . next ( ) ?;
293
- if unresolved. is_some ( ) {
294
- return None ;
291
+ if let ( ModuleOrTypeNs :: TypeNs ( res) , None , _) = self . resolve_path_in_type_ns ( db, path) ? {
292
+ Some ( res)
293
+ } else {
294
+ None
295
295
}
296
- Some ( res)
297
296
}
298
297
299
298
pub fn resolve_visibility (
@@ -1183,7 +1182,7 @@ impl ModuleItemMap {
1183
1182
}
1184
1183
}
1185
1184
1186
- fn resolve_path_in_type_ns (
1185
+ fn resolve_path_in_module_or_type_ns (
1187
1186
& self ,
1188
1187
db : & dyn DefDatabase ,
1189
1188
path : & ModPath ,
0 commit comments