@@ -169,33 +169,26 @@ impl Resolver {
169169 self . resolve_module_path ( db, path, BuiltinShadowMode :: Module )
170170 }
171171
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 > ) > {
178177 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) ,
182179 )
183180 }
184181
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+ ) > {
199192 let path = match path {
200193 Path :: BarePath ( mod_path) => mod_path,
201194 Path :: Normal ( it) => & it. mod_path ,
@@ -209,30 +202,29 @@ impl Resolver {
209202 LangItemTarget :: Trait ( it) => TypeNs :: TraitId ( it) ,
210203 LangItemTarget :: Function ( _)
211204 | LangItemTarget :: ImplDef ( _)
212- | LangItemTarget :: Static ( _) => return Box :: new ( iter :: empty ( ) ) ,
205+ | LangItemTarget :: Static ( _) => return None ,
213206 } ;
214- return Box :: new ( iter :: once ( (
207+ return Some ( (
215208 ModuleOrTypeNs :: TypeNs ( type_ns) ,
216209 seg. as_ref ( ) . map ( |_| 1 ) ,
217210 None ,
218211 ResolvePathResultPrefixInfo :: default ( ) ,
219- ) ) ) ;
212+ ) ) ;
220213 }
221214 } ;
222- let Some ( first_name) = path. segments ( ) . first ( ) else { return Box :: new ( iter :: empty ( ) ) } ;
215+ let first_name = path. segments ( ) . first ( ) ? ;
223216 let skip_to_mod = path. kind != PathKind :: Plain ;
224217 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) ;
226219 }
227220
228221 let remaining_idx = || {
229222 if path. segments ( ) . len ( ) == 1 { None } else { Some ( 1 ) }
230223 } ;
231224
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 ,
236228 Scope :: GenericParams { params, def } => {
237229 if let Some ( id) = params. find_type_by_name ( first_name, * def) {
238230 return Some ( (
@@ -242,7 +234,6 @@ impl Resolver {
242234 ResolvePathResultPrefixInfo :: default ( ) ,
243235 ) ) ;
244236 }
245- None
246237 }
247238 & Scope :: ImplDefScope ( impl_) => {
248239 if * first_name == sym:: Self_ . clone ( ) {
@@ -253,7 +244,6 @@ impl Resolver {
253244 ResolvePathResultPrefixInfo :: default ( ) ,
254245 ) ) ;
255246 }
256- None
257247 }
258248 & Scope :: AdtScope ( adt) => {
259249 if * first_name == sym:: Self_ . clone ( ) {
@@ -264,36 +254,45 @@ impl Resolver {
264254 ResolvePathResultPrefixInfo :: default ( ) ,
265255 ) ) ;
266256 }
267- None
268257 }
269258 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+ } ;
271278 return Some ( res) ;
272279 }
273- None
274280 }
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)
279284 }
280285
281286 pub fn resolve_path_in_type_ns_fully (
282287 & self ,
283288 db : & dyn DefDatabase ,
284289 path : & Path ,
285290 ) -> 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
295295 }
296- Some ( res)
297296 }
298297
299298 pub fn resolve_visibility (
@@ -1183,7 +1182,7 @@ impl ModuleItemMap {
11831182 }
11841183 }
11851184
1186- fn resolve_path_in_type_ns (
1185+ fn resolve_path_in_module_or_type_ns (
11871186 & self ,
11881187 db : & dyn DefDatabase ,
11891188 path : & ModPath ,
0 commit comments