]> git.lizzy.rs Git - rust.git/blob - crates/hir/src/source_analyzer.rs
internal: remove dead code
[rust.git] / crates / hir / src / source_analyzer.rs
1 //! Lookup hir elements using positions in the source code. This is a lossy
2 //! transformation: in general, a single source might correspond to several
3 //! modules, functions, etc, due to macros, cfgs and `#[path=]` attributes on
4 //! modules.
5 //!
6 //! So, this modules should not be used during hir construction, it exists
7 //! purely for "IDE needs".
8 use std::{iter::once, sync::Arc};
9
10 use hir_def::{
11     body::{
12         self,
13         scope::{ExprScopes, ScopeId},
14         Body, BodySourceMap,
15     },
16     expr::{ExprId, Pat, PatId},
17     path::{ModPath, Path, PathKind},
18     resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs},
19     AsMacroCall, DefWithBodyId, FieldId, FunctionId, LocalFieldId, VariantId,
20 };
21 use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile};
22 use hir_ty::{
23     diagnostics::{record_literal_missing_fields, record_pattern_missing_fields},
24     InferenceResult, Interner, Substitution, TyExt, TyLoweringContext,
25 };
26 use syntax::{
27     ast::{self, AstNode},
28     SyntaxNode, TextRange, TextSize,
29 };
30
31 use crate::{
32     db::HirDatabase, semantics::PathResolution, Adt, BuiltinType, Const, Field, Function, Local,
33     MacroDef, ModuleDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, Variant,
34 };
35 use base_db::CrateId;
36
37 /// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
38 /// original source files. It should not be used inside the HIR itself.
39 #[derive(Debug)]
40 pub(crate) struct SourceAnalyzer {
41     pub(crate) file_id: HirFileId,
42     pub(crate) resolver: Resolver,
43     body: Option<Arc<Body>>,
44     body_source_map: Option<Arc<BodySourceMap>>,
45     infer: Option<Arc<InferenceResult>>,
46 }
47
48 impl SourceAnalyzer {
49     pub(crate) fn new_for_body(
50         db: &dyn HirDatabase,
51         def: DefWithBodyId,
52         node: InFile<&SyntaxNode>,
53         offset: Option<TextSize>,
54     ) -> SourceAnalyzer {
55         let (body, source_map) = db.body_with_source_map(def);
56         let scopes = db.expr_scopes(def);
57         let scope = match offset {
58             None => scope_for(&scopes, &source_map, node),
59             Some(offset) => scope_for_offset(db, &scopes, &source_map, node.with_value(offset)),
60         };
61         let resolver = resolver_for_scope(db.upcast(), def, scope);
62         SourceAnalyzer {
63             resolver,
64             body: Some(body),
65             body_source_map: Some(source_map),
66             infer: Some(db.infer(def)),
67             file_id: node.file_id,
68         }
69     }
70
71     pub(crate) fn new_for_resolver(
72         resolver: Resolver,
73         node: InFile<&SyntaxNode>,
74     ) -> SourceAnalyzer {
75         SourceAnalyzer {
76             resolver,
77             body: None,
78             body_source_map: None,
79             infer: None,
80             file_id: node.file_id,
81         }
82     }
83
84     fn expr_id(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option<ExprId> {
85         let src = match expr {
86             ast::Expr::MacroCall(call) => {
87                 self.expand_expr(db, InFile::new(self.file_id, call.clone()))?
88             }
89             _ => InFile::new(self.file_id, expr.clone()),
90         };
91         let sm = self.body_source_map.as_ref()?;
92         sm.node_expr(src.as_ref())
93     }
94
95     fn pat_id(&self, pat: &ast::Pat) -> Option<PatId> {
96         // FIXME: macros, see `expr_id`
97         let src = InFile { file_id: self.file_id, value: pat };
98         self.body_source_map.as_ref()?.node_pat(src)
99     }
100
101     fn expand_expr(
102         &self,
103         db: &dyn HirDatabase,
104         expr: InFile<ast::MacroCall>,
105     ) -> Option<InFile<ast::Expr>> {
106         let macro_file = self.body_source_map.as_ref()?.node_macro_file(expr.as_ref())?;
107         let expanded = db.parse_or_expand(macro_file)?;
108
109         let res = match ast::MacroCall::cast(expanded.clone()) {
110             Some(call) => self.expand_expr(db, InFile::new(macro_file, call))?,
111             _ => InFile::new(macro_file, ast::Expr::cast(expanded)?),
112         };
113         Some(res)
114     }
115
116     pub(crate) fn type_of_expr(
117         &self,
118         db: &dyn HirDatabase,
119         expr: &ast::Expr,
120     ) -> Option<(Type, Option<Type>)> {
121         let expr_id = self.expr_id(db, expr)?;
122         let infer = self.infer.as_ref()?;
123         let coerced = infer
124             .expr_adjustments
125             .get(&expr_id)
126             .and_then(|adjusts| adjusts.last().map(|adjust| adjust.target.clone()));
127         let ty = infer[expr_id].clone();
128         let mk_ty = |ty| Type::new_with_resolver(db, &self.resolver, ty);
129         mk_ty(ty).zip(Some(coerced.and_then(mk_ty)))
130     }
131
132     pub(crate) fn type_of_pat(
133         &self,
134         db: &dyn HirDatabase,
135         pat: &ast::Pat,
136     ) -> Option<(Type, Option<Type>)> {
137         let pat_id = self.pat_id(pat)?;
138         let infer = self.infer.as_ref()?;
139         let coerced = infer
140             .pat_adjustments
141             .get(&pat_id)
142             .and_then(|adjusts| adjusts.last().map(|adjust| adjust.target.clone()));
143         let ty = infer[pat_id].clone();
144         let mk_ty = |ty| Type::new_with_resolver(db, &self.resolver, ty);
145         mk_ty(ty).zip(Some(coerced.and_then(mk_ty)))
146     }
147
148     pub(crate) fn type_of_self(
149         &self,
150         db: &dyn HirDatabase,
151         param: &ast::SelfParam,
152     ) -> Option<Type> {
153         let src = InFile { file_id: self.file_id, value: param };
154         let pat_id = self.body_source_map.as_ref()?.node_self_param(src)?;
155         let ty = self.infer.as_ref()?[pat_id].clone();
156         Type::new_with_resolver(db, &self.resolver, ty)
157     }
158
159     pub(crate) fn resolve_method_call(
160         &self,
161         db: &dyn HirDatabase,
162         call: &ast::MethodCallExpr,
163     ) -> Option<(FunctionId, Substitution)> {
164         let expr_id = self.expr_id(db, &call.clone().into())?;
165         self.infer.as_ref()?.method_resolution(expr_id)
166     }
167
168     pub(crate) fn resolve_field(
169         &self,
170         db: &dyn HirDatabase,
171         field: &ast::FieldExpr,
172     ) -> Option<Field> {
173         let expr_id = self.expr_id(db, &field.clone().into())?;
174         self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into())
175     }
176
177     pub(crate) fn resolve_record_field(
178         &self,
179         db: &dyn HirDatabase,
180         field: &ast::RecordExprField,
181     ) -> Option<(Field, Option<Local>, Type)> {
182         let record_expr = ast::RecordExpr::cast(field.syntax().parent().and_then(|p| p.parent())?)?;
183         let expr = ast::Expr::from(record_expr);
184         let expr_id = self.body_source_map.as_ref()?.node_expr(InFile::new(self.file_id, &expr))?;
185
186         let local_name = field.field_name()?.as_name();
187         let local = if field.name_ref().is_some() {
188             None
189         } else {
190             let path = ModPath::from_segments(PathKind::Plain, once(local_name.clone()));
191             match self.resolver.resolve_path_in_value_ns_fully(db.upcast(), &path) {
192                 Some(ValueNs::LocalBinding(pat_id)) => {
193                     Some(Local { pat_id, parent: self.resolver.body_owner()? })
194                 }
195                 _ => None,
196             }
197         };
198         let (_, subst) = self.infer.as_ref()?.type_of_expr.get(expr_id)?.as_adt()?;
199         let variant = self.infer.as_ref()?.variant_resolution_for_expr(expr_id)?;
200         let variant_data = variant.variant_data(db.upcast());
201         let field = FieldId { parent: variant, local_id: variant_data.field(&local_name)? };
202         let field_ty =
203             db.field_types(variant).get(field.local_id)?.clone().substitute(&Interner, subst);
204         Some((field.into(), local, Type::new_with_resolver(db, &self.resolver, field_ty)?))
205     }
206
207     pub(crate) fn resolve_record_pat_field(
208         &self,
209         db: &dyn HirDatabase,
210         field: &ast::RecordPatField,
211     ) -> Option<Field> {
212         let field_name = field.field_name()?.as_name();
213         let record_pat = ast::RecordPat::cast(field.syntax().parent().and_then(|p| p.parent())?)?;
214         let pat_id = self.pat_id(&record_pat.into())?;
215         let variant = self.infer.as_ref()?.variant_resolution_for_pat(pat_id)?;
216         let variant_data = variant.variant_data(db.upcast());
217         let field = FieldId { parent: variant, local_id: variant_data.field(&field_name)? };
218         Some(field.into())
219     }
220
221     pub(crate) fn resolve_macro_call(
222         &self,
223         db: &dyn HirDatabase,
224         macro_call: InFile<&ast::MacroCall>,
225     ) -> Option<MacroDef> {
226         let ctx = body::LowerCtx::new(db.upcast(), macro_call.file_id);
227         let path = macro_call.value.path().and_then(|ast| Path::from_src(ast, &ctx))?;
228         self.resolver.resolve_path_as_macro(db.upcast(), path.mod_path()).map(|it| it.into())
229     }
230
231     pub(crate) fn resolve_bind_pat_to_const(
232         &self,
233         db: &dyn HirDatabase,
234         pat: &ast::IdentPat,
235     ) -> Option<ModuleDef> {
236         let pat_id = self.pat_id(&pat.clone().into())?;
237         let body = self.body.as_ref()?;
238         let path = match &body[pat_id] {
239             Pat::Path(path) => path,
240             _ => return None,
241         };
242         let res = resolve_hir_path(db, &self.resolver, path)?;
243         match res {
244             PathResolution::Def(def) => Some(def),
245             _ => None,
246         }
247     }
248
249     pub(crate) fn resolve_path(
250         &self,
251         db: &dyn HirDatabase,
252         path: &ast::Path,
253     ) -> Option<PathResolution> {
254         let parent = || path.syntax().parent();
255         let mut prefer_value_ns = false;
256         if let Some(path_expr) = parent().and_then(ast::PathExpr::cast) {
257             let expr_id = self.expr_id(db, &path_expr.into())?;
258             let infer = self.infer.as_ref()?;
259             if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) {
260                 return Some(PathResolution::AssocItem(assoc.into()));
261             }
262             if let Some(VariantId::EnumVariantId(variant)) =
263                 infer.variant_resolution_for_expr(expr_id)
264             {
265                 return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
266             }
267             prefer_value_ns = true;
268         }
269
270         if let Some(path_pat) = parent().and_then(ast::PathPat::cast) {
271             let pat_id = self.pat_id(&path_pat.into())?;
272             if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
273                 return Some(PathResolution::AssocItem(assoc.into()));
274             }
275             if let Some(VariantId::EnumVariantId(variant)) =
276                 self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
277             {
278                 return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
279             }
280         }
281
282         if let Some(rec_lit) = parent().and_then(ast::RecordExpr::cast) {
283             let expr_id = self.expr_id(db, &rec_lit.into())?;
284             if let Some(VariantId::EnumVariantId(variant)) =
285                 self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
286             {
287                 return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
288             }
289         }
290
291         if let Some(pat) = parent()
292             .and_then(ast::RecordPat::cast)
293             .map(ast::Pat::from)
294             .or_else(|| parent().and_then(ast::TupleStructPat::cast).map(ast::Pat::from))
295         {
296             let pat_id = self.pat_id(&pat)?;
297             if let Some(VariantId::EnumVariantId(variant)) =
298                 self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
299             {
300                 return Some(PathResolution::Def(ModuleDef::Variant(variant.into())));
301             }
302         }
303
304         // This must be a normal source file rather than macro file.
305         let hygiene = Hygiene::new(db.upcast(), self.file_id);
306         let ctx = body::LowerCtx::with_hygiene(db.upcast(), &hygiene);
307         let hir_path = Path::from_src(path.clone(), &ctx)?;
308
309         // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we are
310         // trying to resolve foo::bar.
311         if let Some(outer_path) = parent().and_then(ast::Path::cast) {
312             if let Some(qualifier) = outer_path.qualifier() {
313                 if path == &qualifier {
314                     return resolve_hir_path_qualifier(db, &self.resolver, &hir_path);
315                 }
316             }
317         }
318         // Case where path is a qualifier of a use tree, e.g. foo::bar::{Baz, Qux} where we are
319         // trying to resolve foo::bar.
320         if let Some(use_tree) = parent().and_then(ast::UseTree::cast) {
321             if let Some(qualifier) = use_tree.path() {
322                 if path == &qualifier && use_tree.coloncolon_token().is_some() {
323                     return resolve_hir_path_qualifier(db, &self.resolver, &hir_path);
324                 }
325             }
326         }
327
328         if parent().map_or(false, |it| ast::Visibility::can_cast(it.kind())) {
329             resolve_hir_path_qualifier(db, &self.resolver, &hir_path)
330         } else {
331             resolve_hir_path_(db, &self.resolver, &hir_path, prefer_value_ns)
332         }
333     }
334
335     pub(crate) fn record_literal_missing_fields(
336         &self,
337         db: &dyn HirDatabase,
338         literal: &ast::RecordExpr,
339     ) -> Option<Vec<(Field, Type)>> {
340         let krate = self.resolver.krate()?;
341         let body = self.body.as_ref()?;
342         let infer = self.infer.as_ref()?;
343
344         let expr_id = self.expr_id(db, &literal.clone().into())?;
345         let substs = infer.type_of_expr[expr_id].as_adt()?.1;
346
347         let (variant, missing_fields, _exhaustive) =
348             record_literal_missing_fields(db, infer, expr_id, &body[expr_id])?;
349         let res = self.missing_fields(db, krate, substs, variant, missing_fields);
350         Some(res)
351     }
352
353     pub(crate) fn record_pattern_missing_fields(
354         &self,
355         db: &dyn HirDatabase,
356         pattern: &ast::RecordPat,
357     ) -> Option<Vec<(Field, Type)>> {
358         let krate = self.resolver.krate()?;
359         let body = self.body.as_ref()?;
360         let infer = self.infer.as_ref()?;
361
362         let pat_id = self.pat_id(&pattern.clone().into())?;
363         let substs = infer.type_of_pat[pat_id].as_adt()?.1;
364
365         let (variant, missing_fields, _exhaustive) =
366             record_pattern_missing_fields(db, infer, pat_id, &body[pat_id])?;
367         let res = self.missing_fields(db, krate, substs, variant, missing_fields);
368         Some(res)
369     }
370
371     fn missing_fields(
372         &self,
373         db: &dyn HirDatabase,
374         krate: CrateId,
375         substs: &Substitution,
376         variant: VariantId,
377         missing_fields: Vec<LocalFieldId>,
378     ) -> Vec<(Field, Type)> {
379         let field_types = db.field_types(variant);
380
381         missing_fields
382             .into_iter()
383             .map(|local_id| {
384                 let field = FieldId { parent: variant, local_id };
385                 let ty = field_types[local_id].clone().substitute(&Interner, substs);
386                 (field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty))
387             })
388             .collect()
389     }
390
391     pub(crate) fn expand(
392         &self,
393         db: &dyn HirDatabase,
394         macro_call: InFile<&ast::MacroCall>,
395     ) -> Option<HirFileId> {
396         let krate = self.resolver.krate()?;
397         let macro_call_id = macro_call.as_call_id(db.upcast(), krate, |path| {
398             self.resolver.resolve_path_as_macro(db.upcast(), &path)
399         })?;
400         Some(macro_call_id.as_file()).filter(|it| it.expansion_level(db.upcast()) < 64)
401     }
402
403     pub(crate) fn resolve_variant(
404         &self,
405         db: &dyn HirDatabase,
406         record_lit: ast::RecordExpr,
407     ) -> Option<VariantId> {
408         let infer = self.infer.as_ref()?;
409         let expr_id = self.expr_id(db, &record_lit.into())?;
410         infer.variant_resolution_for_expr(expr_id)
411     }
412 }
413
414 fn scope_for(
415     scopes: &ExprScopes,
416     source_map: &BodySourceMap,
417     node: InFile<&SyntaxNode>,
418 ) -> Option<ScopeId> {
419     node.value
420         .ancestors()
421         .filter_map(ast::Expr::cast)
422         .filter_map(|it| source_map.node_expr(InFile::new(node.file_id, &it)))
423         .find_map(|it| scopes.scope_for(it))
424 }
425
426 fn scope_for_offset(
427     db: &dyn HirDatabase,
428     scopes: &ExprScopes,
429     source_map: &BodySourceMap,
430     offset: InFile<TextSize>,
431 ) -> Option<ScopeId> {
432     scopes
433         .scope_by_expr()
434         .iter()
435         .filter_map(|(id, scope)| {
436             let source = source_map.expr_syntax(*id).ok()?;
437             // FIXME: correctly handle macro expansion
438             if source.file_id != offset.file_id {
439                 return None;
440             }
441             let root = source.file_syntax(db.upcast());
442             let node = source.value.to_node(&root);
443             Some((node.syntax().text_range(), scope))
444         })
445         // find containing scope
446         .min_by_key(|(expr_range, _scope)| {
447             (
448                 !(expr_range.start() <= offset.value && offset.value <= expr_range.end()),
449                 expr_range.len(),
450             )
451         })
452         .map(|(expr_range, scope)| {
453             adjust(db, scopes, source_map, expr_range, offset).unwrap_or(*scope)
454         })
455 }
456
457 // XXX: during completion, cursor might be outside of any particular
458 // expression. Try to figure out the correct scope...
459 fn adjust(
460     db: &dyn HirDatabase,
461     scopes: &ExprScopes,
462     source_map: &BodySourceMap,
463     expr_range: TextRange,
464     offset: InFile<TextSize>,
465 ) -> Option<ScopeId> {
466     let child_scopes = scopes
467         .scope_by_expr()
468         .iter()
469         .filter_map(|(id, scope)| {
470             let source = source_map.expr_syntax(*id).ok()?;
471             // FIXME: correctly handle macro expansion
472             if source.file_id != offset.file_id {
473                 return None;
474             }
475             let root = source.file_syntax(db.upcast());
476             let node = source.value.to_node(&root);
477             Some((node.syntax().text_range(), scope))
478         })
479         .filter(|&(range, _)| {
480             range.start() <= offset.value && expr_range.contains_range(range) && range != expr_range
481         });
482
483     child_scopes
484         .max_by(|&(r1, _), &(r2, _)| {
485             if r1.contains_range(r2) {
486                 std::cmp::Ordering::Greater
487             } else if r2.contains_range(r1) {
488                 std::cmp::Ordering::Less
489             } else {
490                 r1.start().cmp(&r2.start())
491             }
492         })
493         .map(|(_ptr, scope)| *scope)
494 }
495
496 #[inline]
497 pub(crate) fn resolve_hir_path(
498     db: &dyn HirDatabase,
499     resolver: &Resolver,
500     path: &Path,
501 ) -> Option<PathResolution> {
502     resolve_hir_path_(db, resolver, path, false)
503 }
504
505 fn resolve_hir_path_(
506     db: &dyn HirDatabase,
507     resolver: &Resolver,
508     path: &Path,
509     prefer_value_ns: bool,
510 ) -> Option<PathResolution> {
511     let types = || {
512         let (ty, unresolved) = match path.type_anchor() {
513             Some(type_ref) => {
514                 let (_, res) = TyLoweringContext::new(db, resolver).lower_ty_ext(type_ref);
515                 res.map(|ty_ns| (ty_ns, path.segments().first()))
516             }
517             None => {
518                 let (ty, remaining) =
519                     resolver.resolve_path_in_type_ns(db.upcast(), path.mod_path())?;
520                 match remaining {
521                     Some(remaining) if remaining > 1 => None,
522                     _ => Some((ty, path.segments().get(1))),
523                 }
524             }
525         }?;
526         let res = match ty {
527             TypeNs::SelfType(it) => PathResolution::SelfType(it.into()),
528             TypeNs::GenericParam(id) => PathResolution::TypeParam(TypeParam { id }),
529             TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => {
530                 PathResolution::Def(Adt::from(it).into())
531             }
532             TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
533             TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
534             TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()),
535             TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
536         };
537         match unresolved {
538             Some(unresolved) => res
539                 .assoc_type_shorthand_candidates(db, |name, alias| {
540                     (name == unresolved.name).then(|| alias)
541                 })
542                 .map(TypeAlias::from)
543                 .map(Into::into)
544                 .map(PathResolution::Def),
545             None => Some(res),
546         }
547     };
548
549     let body_owner = resolver.body_owner();
550     let values = || {
551         resolver.resolve_path_in_value_ns_fully(db.upcast(), path.mod_path()).and_then(|val| {
552             let res = match val {
553                 ValueNs::LocalBinding(pat_id) => {
554                     let var = Local { parent: body_owner?, pat_id };
555                     PathResolution::Local(var)
556                 }
557                 ValueNs::FunctionId(it) => PathResolution::Def(Function::from(it).into()),
558                 ValueNs::ConstId(it) => PathResolution::Def(Const::from(it).into()),
559                 ValueNs::StaticId(it) => PathResolution::Def(Static::from(it).into()),
560                 ValueNs::StructId(it) => PathResolution::Def(Struct::from(it).into()),
561                 ValueNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
562                 ValueNs::ImplSelf(impl_id) => PathResolution::SelfType(impl_id.into()),
563                 ValueNs::GenericParam(it) => PathResolution::ConstParam(it.into()),
564             };
565             Some(res)
566         })
567     };
568
569     let items = || {
570         resolver
571             .resolve_module_path_in_items(db.upcast(), path.mod_path())
572             .take_types()
573             .map(|it| PathResolution::Def(it.into()))
574     };
575
576     let macros = || {
577         resolver
578             .resolve_path_as_macro(db.upcast(), path.mod_path())
579             .map(|def| PathResolution::Macro(def.into()))
580     };
581
582     if prefer_value_ns { values().or_else(types) } else { types().or_else(values) }
583         .or_else(items)
584         .or_else(macros)
585 }
586
587 /// Resolves a path where we know it is a qualifier of another path.
588 ///
589 /// For example, if we have:
590 /// ```
591 /// mod my {
592 ///     pub mod foo {
593 ///         struct Bar;
594 ///     }
595 ///
596 ///     pub fn foo() {}
597 /// }
598 /// ```
599 /// then we know that `foo` in `my::foo::Bar` refers to the module, not the function.
600 fn resolve_hir_path_qualifier(
601     db: &dyn HirDatabase,
602     resolver: &Resolver,
603     path: &Path,
604 ) -> Option<PathResolution> {
605     let items = resolver
606         .resolve_module_path_in_items(db.upcast(), path.mod_path())
607         .take_types()
608         .map(|it| PathResolution::Def(it.into()));
609
610     if items.is_some() {
611         return items;
612     }
613
614     resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty {
615         TypeNs::SelfType(it) => PathResolution::SelfType(it.into()),
616         TypeNs::GenericParam(id) => PathResolution::TypeParam(TypeParam { id }),
617         TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => PathResolution::Def(Adt::from(it).into()),
618         TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
619         TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
620         TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()),
621         TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
622     })
623 }