|
3 | 3 | //! generic parameters. See also the `Generics` type and the `generics_of` query
|
4 | 4 | //! in rustc.
|
5 | 5 |
|
6 |
| -use base_db::FileId; |
7 | 6 | use either::Either;
|
8 | 7 | use hir_expand::{
|
9 | 8 | name::{AsName, Name},
|
10 |
| - ExpandResult, HirFileId, InFile, |
| 9 | + ExpandResult, |
11 | 10 | };
|
12 | 11 | use intern::Interned;
|
13 |
| -use la_arena::{Arena, ArenaMap, Idx}; |
| 12 | +use la_arena::{Arena, Idx}; |
14 | 13 | use once_cell::unsync::Lazy;
|
15 | 14 | use stdx::impl_from;
|
16 | 15 | use syntax::ast::{self, HasGenericParams, HasName, HasTypeBounds};
|
17 | 16 | use triomphe::Arc;
|
18 | 17 |
|
19 | 18 | use crate::{
|
20 |
| - child_by_source::ChildBySource, |
21 | 19 | db::DefDatabase,
|
22 |
| - dyn_map::{keys, DynMap}, |
23 | 20 | expander::Expander,
|
24 | 21 | item_tree::ItemTree,
|
25 | 22 | lower::LowerCtx,
|
26 | 23 | nameres::{DefMap, MacroSubNs},
|
27 |
| - src::{HasChildSource, HasSource}, |
28 | 24 | type_ref::{ConstRef, LifetimeRef, TypeBound, TypeRef},
|
29 |
| - AdtId, ConstParamId, GenericDefId, HasModule, LifetimeParamId, LocalLifetimeParamId, |
30 |
| - LocalTypeOrConstParamId, Lookup, TypeOrConstParamId, TypeParamId, |
| 25 | + AdtId, ConstParamId, GenericDefId, HasModule, LocalTypeOrConstParamId, Lookup, |
| 26 | + TypeOrConstParamId, TypeParamId, |
31 | 27 | };
|
32 | 28 |
|
33 | 29 | /// Data about a generic type parameter (to a function, struct, impl, ...).
|
@@ -507,130 +503,3 @@ impl GenericParams {
|
507 | 503 | })
|
508 | 504 | }
|
509 | 505 | }
|
510 |
| - |
511 |
| -fn file_id_and_params_of( |
512 |
| - db: &dyn DefDatabase, |
513 |
| - def: GenericDefId, |
514 |
| -) -> (HirFileId, Option<ast::GenericParamList>) { |
515 |
| - match def { |
516 |
| - GenericDefId::FunctionId(it) => file_id_and_params_of_item_loc(db, it), |
517 |
| - GenericDefId::TypeAliasId(it) => file_id_and_params_of_item_loc(db, it), |
518 |
| - GenericDefId::ConstId(_) => (FileId::BOGUS.into(), None), |
519 |
| - GenericDefId::AdtId(AdtId::StructId(it)) => file_id_and_params_of_item_loc(db, it), |
520 |
| - GenericDefId::AdtId(AdtId::UnionId(it)) => file_id_and_params_of_item_loc(db, it), |
521 |
| - GenericDefId::AdtId(AdtId::EnumId(it)) => file_id_and_params_of_item_loc(db, it), |
522 |
| - GenericDefId::TraitId(it) => file_id_and_params_of_item_loc(db, it), |
523 |
| - GenericDefId::TraitAliasId(it) => file_id_and_params_of_item_loc(db, it), |
524 |
| - GenericDefId::ImplId(it) => file_id_and_params_of_item_loc(db, it), |
525 |
| - // We won't be using this ID anyway |
526 |
| - GenericDefId::EnumVariantId(_) => (FileId::BOGUS.into(), None), |
527 |
| - } |
528 |
| -} |
529 |
| - |
530 |
| -fn file_id_and_params_of_item_loc<Loc>( |
531 |
| - db: &dyn DefDatabase, |
532 |
| - def: impl for<'db> Lookup<Database<'db> = dyn DefDatabase + 'db, Data = Loc>, |
533 |
| -) -> (HirFileId, Option<ast::GenericParamList>) |
534 |
| -where |
535 |
| - Loc: HasSource, |
536 |
| - Loc::Value: HasGenericParams, |
537 |
| -{ |
538 |
| - let src = def.lookup(db).source(db); |
539 |
| - (src.file_id, src.value.generic_param_list()) |
540 |
| -} |
541 |
| - |
542 |
| -impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId { |
543 |
| - type Value = Either<ast::TypeOrConstParam, ast::TraitOrAlias>; |
544 |
| - fn child_source( |
545 |
| - &self, |
546 |
| - db: &dyn DefDatabase, |
547 |
| - ) -> InFile<ArenaMap<LocalTypeOrConstParamId, Self::Value>> { |
548 |
| - let generic_params = db.generic_params(*self); |
549 |
| - let mut idx_iter = generic_params.type_or_consts.iter().map(|(idx, _)| idx); |
550 |
| - |
551 |
| - let (file_id, generic_params_list) = file_id_and_params_of(db, *self); |
552 |
| - |
553 |
| - let mut params = ArenaMap::default(); |
554 |
| - |
555 |
| - // For traits and trait aliases the first type index is `Self`, we need to add it before |
556 |
| - // the other params. |
557 |
| - match *self { |
558 |
| - GenericDefId::TraitId(id) => { |
559 |
| - let trait_ref = id.lookup(db).source(db).value; |
560 |
| - let idx = idx_iter.next().unwrap(); |
561 |
| - params.insert(idx, Either::Right(ast::TraitOrAlias::Trait(trait_ref))); |
562 |
| - } |
563 |
| - GenericDefId::TraitAliasId(id) => { |
564 |
| - let alias = id.lookup(db).source(db).value; |
565 |
| - let idx = idx_iter.next().unwrap(); |
566 |
| - params.insert(idx, Either::Right(ast::TraitOrAlias::TraitAlias(alias))); |
567 |
| - } |
568 |
| - _ => {} |
569 |
| - } |
570 |
| - |
571 |
| - if let Some(generic_params_list) = generic_params_list { |
572 |
| - for (idx, ast_param) in idx_iter.zip(generic_params_list.type_or_const_params()) { |
573 |
| - params.insert(idx, Either::Left(ast_param)); |
574 |
| - } |
575 |
| - } |
576 |
| - |
577 |
| - InFile::new(file_id, params) |
578 |
| - } |
579 |
| -} |
580 |
| - |
581 |
| -impl HasChildSource<LocalLifetimeParamId> for GenericDefId { |
582 |
| - type Value = ast::LifetimeParam; |
583 |
| - fn child_source( |
584 |
| - &self, |
585 |
| - db: &dyn DefDatabase, |
586 |
| - ) -> InFile<ArenaMap<LocalLifetimeParamId, Self::Value>> { |
587 |
| - let generic_params = db.generic_params(*self); |
588 |
| - let idx_iter = generic_params.lifetimes.iter().map(|(idx, _)| idx); |
589 |
| - |
590 |
| - let (file_id, generic_params_list) = file_id_and_params_of(db, *self); |
591 |
| - |
592 |
| - let mut params = ArenaMap::default(); |
593 |
| - |
594 |
| - if let Some(generic_params_list) = generic_params_list { |
595 |
| - for (idx, ast_param) in idx_iter.zip(generic_params_list.lifetime_params()) { |
596 |
| - params.insert(idx, ast_param); |
597 |
| - } |
598 |
| - } |
599 |
| - |
600 |
| - InFile::new(file_id, params) |
601 |
| - } |
602 |
| -} |
603 |
| - |
604 |
| -impl ChildBySource for GenericDefId { |
605 |
| - fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) { |
606 |
| - let (gfile_id, generic_params_list) = file_id_and_params_of(db, *self); |
607 |
| - if gfile_id != file_id { |
608 |
| - return; |
609 |
| - } |
610 |
| - |
611 |
| - let generic_params = db.generic_params(*self); |
612 |
| - let mut toc_idx_iter = generic_params.type_or_consts.iter().map(|(idx, _)| idx); |
613 |
| - let lts_idx_iter = generic_params.lifetimes.iter().map(|(idx, _)| idx); |
614 |
| - |
615 |
| - // For traits the first type index is `Self`, skip it. |
616 |
| - if let GenericDefId::TraitId(_) = *self { |
617 |
| - toc_idx_iter.next().unwrap(); // advance_by(1); |
618 |
| - } |
619 |
| - |
620 |
| - if let Some(generic_params_list) = generic_params_list { |
621 |
| - for (local_id, ast_param) in |
622 |
| - toc_idx_iter.zip(generic_params_list.type_or_const_params()) |
623 |
| - { |
624 |
| - let id = TypeOrConstParamId { parent: *self, local_id }; |
625 |
| - match ast_param { |
626 |
| - ast::TypeOrConstParam::Type(a) => res[keys::TYPE_PARAM].insert(a, id), |
627 |
| - ast::TypeOrConstParam::Const(a) => res[keys::CONST_PARAM].insert(a, id), |
628 |
| - } |
629 |
| - } |
630 |
| - for (local_id, ast_param) in lts_idx_iter.zip(generic_params_list.lifetime_params()) { |
631 |
| - let id = LifetimeParamId { parent: *self, local_id }; |
632 |
| - res[keys::LIFETIME_PARAM].insert(ast_param, id); |
633 |
| - } |
634 |
| - } |
635 |
| - } |
636 |
| -} |
0 commit comments