mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 22:24:14 +00:00
Lower and handle trait aliases in HIR
This commit is contained in:
parent
e2ec3a6561
commit
29c957f973
47 changed files with 334 additions and 75 deletions
|
@ -300,6 +300,7 @@ impl AttrsWithOwner {
|
||||||
AdtId::UnionId(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
AdtId::UnionId(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
||||||
},
|
},
|
||||||
AttrDefId::TraitId(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
AttrDefId::TraitId(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
||||||
|
AttrDefId::TraitAliasId(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
||||||
AttrDefId::MacroId(it) => match it {
|
AttrDefId::MacroId(it) => match it {
|
||||||
MacroId::Macro2Id(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
MacroId::Macro2Id(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
||||||
MacroId::MacroRulesId(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
MacroId::MacroRulesId(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
||||||
|
@ -392,6 +393,7 @@ impl AttrsWithOwner {
|
||||||
AttrDefId::StaticId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
AttrDefId::StaticId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
||||||
AttrDefId::ConstId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
AttrDefId::ConstId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
||||||
AttrDefId::TraitId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
AttrDefId::TraitId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
||||||
|
AttrDefId::TraitAliasId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
||||||
AttrDefId::TypeAliasId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
AttrDefId::TypeAliasId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
||||||
AttrDefId::MacroId(id) => match id {
|
AttrDefId::MacroId(id) => match id {
|
||||||
MacroId::Macro2Id(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
MacroId::Macro2Id(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! When *constructing* `hir`, we start at some parent syntax node and recursively
|
//! When *constructing* `hir`, we start at some parent syntax node and recursively
|
||||||
//! lower the children.
|
//! lower the children.
|
||||||
//!
|
//!
|
||||||
//! This modules allows one to go in the opposite direction: start with a syntax
|
//! This module allows one to go in the opposite direction: start with a syntax
|
||||||
//! node for a *child*, and get its hir.
|
//! node for a *child*, and get its hir.
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
|
@ -145,6 +145,7 @@ impl ChildBySource for ItemScope {
|
||||||
ModuleDefId::StaticId(id) => insert!(map[keys::STATIC].insert(id)),
|
ModuleDefId::StaticId(id) => insert!(map[keys::STATIC].insert(id)),
|
||||||
ModuleDefId::TypeAliasId(id) => insert!(map[keys::TYPE_ALIAS].insert(id)),
|
ModuleDefId::TypeAliasId(id) => insert!(map[keys::TYPE_ALIAS].insert(id)),
|
||||||
ModuleDefId::TraitId(id) => insert!(map[keys::TRAIT].insert(id)),
|
ModuleDefId::TraitId(id) => insert!(map[keys::TRAIT].insert(id)),
|
||||||
|
ModuleDefId::TraitAliasId(id) => insert!(map[keys::TRAIT_ALIAS].insert(id)),
|
||||||
ModuleDefId::AdtId(adt) => match adt {
|
ModuleDefId::AdtId(adt) => match adt {
|
||||||
AdtId::StructId(id) => insert!(map[keys::STRUCT].insert(id)),
|
AdtId::StructId(id) => insert!(map[keys::STRUCT].insert(id)),
|
||||||
AdtId::UnionId(id) => insert!(map[keys::UNION].insert(id)),
|
AdtId::UnionId(id) => insert!(map[keys::UNION].insert(id)),
|
||||||
|
|
|
@ -22,7 +22,7 @@ use crate::{
|
||||||
visibility::RawVisibility,
|
visibility::RawVisibility,
|
||||||
AssocItemId, AstIdWithPath, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId,
|
AssocItemId, AstIdWithPath, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId,
|
||||||
Intern, ItemContainerId, ItemLoc, Lookup, Macro2Id, MacroRulesId, ModuleId, ProcMacroId,
|
Intern, ItemContainerId, ItemLoc, Lookup, Macro2Id, MacroRulesId, ModuleId, ProcMacroId,
|
||||||
StaticId, TraitId, TypeAliasId, TypeAliasLoc,
|
StaticId, TraitAliasId, TraitId, TypeAliasId, TypeAliasLoc,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -245,19 +245,11 @@ impl TraitData {
|
||||||
attrs.by_key("rustc_skip_array_during_method_dispatch").exists();
|
attrs.by_key("rustc_skip_array_during_method_dispatch").exists();
|
||||||
let rustc_has_incoherent_inherent_impls =
|
let rustc_has_incoherent_inherent_impls =
|
||||||
attrs.by_key("rustc_has_incoherent_inherent_impls").exists();
|
attrs.by_key("rustc_has_incoherent_inherent_impls").exists();
|
||||||
let (items, attribute_calls, diagnostics) = match &tr_def.items {
|
let mut collector =
|
||||||
Some(items) => {
|
AssocItemCollector::new(db, module_id, tree_id.file_id(), ItemContainerId::TraitId(tr));
|
||||||
let mut collector = AssocItemCollector::new(
|
collector.collect(&item_tree, tree_id.tree_id(), &tr_def.items);
|
||||||
db,
|
let (items, attribute_calls, diagnostics) = collector.finish();
|
||||||
module_id,
|
|
||||||
tree_id.file_id(),
|
|
||||||
ItemContainerId::TraitId(tr),
|
|
||||||
);
|
|
||||||
collector.collect(&item_tree, tree_id.tree_id(), items);
|
|
||||||
collector.finish()
|
|
||||||
}
|
|
||||||
None => Default::default(),
|
|
||||||
};
|
|
||||||
(
|
(
|
||||||
Arc::new(TraitData {
|
Arc::new(TraitData {
|
||||||
name,
|
name,
|
||||||
|
@ -299,6 +291,23 @@ impl TraitData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct TraitAliasData {
|
||||||
|
pub name: Name,
|
||||||
|
pub visibility: RawVisibility,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TraitAliasData {
|
||||||
|
pub(crate) fn trait_alias_query(db: &dyn DefDatabase, id: TraitAliasId) -> Arc<TraitAliasData> {
|
||||||
|
let loc = id.lookup(db);
|
||||||
|
let item_tree = loc.id.item_tree(db);
|
||||||
|
let alias = &item_tree[loc.id.value];
|
||||||
|
let visibility = item_tree[alias.visibility].clone();
|
||||||
|
|
||||||
|
Arc::new(TraitAliasData { name: alias.name.clone(), visibility })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ImplData {
|
pub struct ImplData {
|
||||||
pub target_trait: Option<Interned<TraitRef>>,
|
pub target_trait: Option<Interned<TraitRef>>,
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::{
|
||||||
body::{scope::ExprScopes, Body, BodySourceMap},
|
body::{scope::ExprScopes, Body, BodySourceMap},
|
||||||
data::{
|
data::{
|
||||||
ConstData, FunctionData, ImplData, Macro2Data, MacroRulesData, ProcMacroData, StaticData,
|
ConstData, FunctionData, ImplData, Macro2Data, MacroRulesData, ProcMacroData, StaticData,
|
||||||
TraitData, TypeAliasData,
|
TraitAliasData, TraitData, TypeAliasData,
|
||||||
},
|
},
|
||||||
generics::GenericParams,
|
generics::GenericParams,
|
||||||
import_map::ImportMap,
|
import_map::ImportMap,
|
||||||
|
@ -25,8 +25,8 @@ use crate::{
|
||||||
AttrDefId, BlockId, BlockLoc, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, ExternBlockId,
|
AttrDefId, BlockId, BlockLoc, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, ExternBlockId,
|
||||||
ExternBlockLoc, FunctionId, FunctionLoc, GenericDefId, ImplId, ImplLoc, LocalEnumVariantId,
|
ExternBlockLoc, FunctionId, FunctionLoc, GenericDefId, ImplId, ImplLoc, LocalEnumVariantId,
|
||||||
LocalFieldId, Macro2Id, Macro2Loc, MacroRulesId, MacroRulesLoc, ProcMacroId, ProcMacroLoc,
|
LocalFieldId, Macro2Id, Macro2Loc, MacroRulesId, MacroRulesLoc, ProcMacroId, ProcMacroLoc,
|
||||||
StaticId, StaticLoc, StructId, StructLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc,
|
StaticId, StaticLoc, StructId, StructLoc, TraitAliasId, TraitAliasLoc, TraitId, TraitLoc,
|
||||||
UnionId, UnionLoc, VariantId,
|
TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VariantId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[salsa::query_group(InternDatabaseStorage)]
|
#[salsa::query_group(InternDatabaseStorage)]
|
||||||
|
@ -46,6 +46,8 @@ pub trait InternDatabase: SourceDatabase {
|
||||||
#[salsa::interned]
|
#[salsa::interned]
|
||||||
fn intern_trait(&self, loc: TraitLoc) -> TraitId;
|
fn intern_trait(&self, loc: TraitLoc) -> TraitId;
|
||||||
#[salsa::interned]
|
#[salsa::interned]
|
||||||
|
fn intern_trait_alias(&self, loc: TraitAliasLoc) -> TraitAliasId;
|
||||||
|
#[salsa::interned]
|
||||||
fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId;
|
fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId;
|
||||||
#[salsa::interned]
|
#[salsa::interned]
|
||||||
fn intern_impl(&self, loc: ImplLoc) -> ImplId;
|
fn intern_impl(&self, loc: ImplLoc) -> ImplId;
|
||||||
|
@ -125,6 +127,9 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
|
||||||
#[salsa::invoke(TraitData::trait_data_with_diagnostics_query)]
|
#[salsa::invoke(TraitData::trait_data_with_diagnostics_query)]
|
||||||
fn trait_data_with_diagnostics(&self, tr: TraitId) -> (Arc<TraitData>, Arc<[DefDiagnostic]>);
|
fn trait_data_with_diagnostics(&self, tr: TraitId) -> (Arc<TraitData>, Arc<[DefDiagnostic]>);
|
||||||
|
|
||||||
|
#[salsa::invoke(TraitAliasData::trait_alias_query)]
|
||||||
|
fn trait_alias_data(&self, e: TraitAliasId) -> Arc<TraitAliasData>;
|
||||||
|
|
||||||
#[salsa::invoke(TypeAliasData::type_alias_data_query)]
|
#[salsa::invoke(TypeAliasData::type_alias_data_query)]
|
||||||
fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
|
fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,7 @@ impl GenericParams {
|
||||||
GenericDefId::AdtId(AdtId::EnumId(id)) => id_to_generics!(id),
|
GenericDefId::AdtId(AdtId::EnumId(id)) => id_to_generics!(id),
|
||||||
GenericDefId::AdtId(AdtId::UnionId(id)) => id_to_generics!(id),
|
GenericDefId::AdtId(AdtId::UnionId(id)) => id_to_generics!(id),
|
||||||
GenericDefId::TraitId(id) => id_to_generics!(id),
|
GenericDefId::TraitId(id) => id_to_generics!(id),
|
||||||
|
GenericDefId::TraitAliasId(id) => id_to_generics!(id),
|
||||||
GenericDefId::TypeAliasId(id) => id_to_generics!(id),
|
GenericDefId::TypeAliasId(id) => id_to_generics!(id),
|
||||||
GenericDefId::ImplId(id) => id_to_generics!(id),
|
GenericDefId::ImplId(id) => id_to_generics!(id),
|
||||||
GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => {
|
GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => {
|
||||||
|
@ -427,6 +428,10 @@ fn file_id_and_params_of(
|
||||||
let src = it.lookup(db).source(db);
|
let src = it.lookup(db).source(db);
|
||||||
(src.file_id, src.value.generic_param_list())
|
(src.file_id, src.value.generic_param_list())
|
||||||
}
|
}
|
||||||
|
GenericDefId::TraitAliasId(it) => {
|
||||||
|
let src = it.lookup(db).source(db);
|
||||||
|
(src.file_id, src.value.generic_param_list())
|
||||||
|
}
|
||||||
GenericDefId::TypeAliasId(it) => {
|
GenericDefId::TypeAliasId(it) => {
|
||||||
let src = it.lookup(db).source(db);
|
let src = it.lookup(db).source(db);
|
||||||
(src.file_id, src.value.generic_param_list())
|
(src.file_id, src.value.generic_param_list())
|
||||||
|
@ -441,7 +446,7 @@ fn file_id_and_params_of(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
|
impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
|
||||||
type Value = Either<ast::TypeOrConstParam, ast::Trait>;
|
type Value = Either<ast::TypeOrConstParam, ast::TraitOrAlias>;
|
||||||
fn child_source(
|
fn child_source(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
|
@ -453,11 +458,20 @@ impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
|
||||||
|
|
||||||
let mut params = ArenaMap::default();
|
let mut params = ArenaMap::default();
|
||||||
|
|
||||||
// For traits the first type index is `Self`, we need to add it before the other params.
|
// For traits and trait aliases the first type index is `Self`, we need to add it before
|
||||||
if let GenericDefId::TraitId(id) = *self {
|
// the other params.
|
||||||
let trait_ref = id.lookup(db).source(db).value;
|
match *self {
|
||||||
let idx = idx_iter.next().unwrap();
|
GenericDefId::TraitId(id) => {
|
||||||
params.insert(idx, Either::Right(trait_ref));
|
let trait_ref = id.lookup(db).source(db).value;
|
||||||
|
let idx = idx_iter.next().unwrap();
|
||||||
|
params.insert(idx, Either::Right(ast::TraitOrAlias::Trait(trait_ref)));
|
||||||
|
}
|
||||||
|
GenericDefId::TraitAliasId(id) => {
|
||||||
|
let alias = id.lookup(db).source(db).value;
|
||||||
|
let idx = idx_iter.next().unwrap();
|
||||||
|
params.insert(idx, Either::Right(ast::TraitOrAlias::TraitAlias(alias)));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(generic_params_list) = generic_params_list {
|
if let Some(generic_params_list) = generic_params_list {
|
||||||
|
|
|
@ -268,6 +268,7 @@ pub enum ImportKind {
|
||||||
Const,
|
Const,
|
||||||
Static,
|
Static,
|
||||||
Trait,
|
Trait,
|
||||||
|
TraitAlias,
|
||||||
TypeAlias,
|
TypeAlias,
|
||||||
BuiltinType,
|
BuiltinType,
|
||||||
AssociatedItem,
|
AssociatedItem,
|
||||||
|
@ -463,6 +464,7 @@ fn item_import_kind(item: ItemInNs) -> Option<ImportKind> {
|
||||||
ModuleDefId::ConstId(_) => ImportKind::Const,
|
ModuleDefId::ConstId(_) => ImportKind::Const,
|
||||||
ModuleDefId::StaticId(_) => ImportKind::Static,
|
ModuleDefId::StaticId(_) => ImportKind::Static,
|
||||||
ModuleDefId::TraitId(_) => ImportKind::Trait,
|
ModuleDefId::TraitId(_) => ImportKind::Trait,
|
||||||
|
ModuleDefId::TraitAliasId(_) => ImportKind::TraitAlias,
|
||||||
ModuleDefId::TypeAliasId(_) => ImportKind::TypeAlias,
|
ModuleDefId::TypeAliasId(_) => ImportKind::TypeAlias,
|
||||||
ModuleDefId::BuiltinType(_) => ImportKind::BuiltinType,
|
ModuleDefId::BuiltinType(_) => ImportKind::BuiltinType,
|
||||||
ModuleDefId::MacroId(_) => ImportKind::Macro,
|
ModuleDefId::MacroId(_) => ImportKind::Macro,
|
||||||
|
|
|
@ -431,6 +431,7 @@ impl PerNs {
|
||||||
ModuleDefId::EnumVariantId(_) => PerNs::both(def, def, v),
|
ModuleDefId::EnumVariantId(_) => PerNs::both(def, def, v),
|
||||||
ModuleDefId::ConstId(_) | ModuleDefId::StaticId(_) => PerNs::values(def, v),
|
ModuleDefId::ConstId(_) | ModuleDefId::StaticId(_) => PerNs::values(def, v),
|
||||||
ModuleDefId::TraitId(_) => PerNs::types(def, v),
|
ModuleDefId::TraitId(_) => PerNs::types(def, v),
|
||||||
|
ModuleDefId::TraitAliasId(_) => PerNs::types(def, v),
|
||||||
ModuleDefId::TypeAliasId(_) => PerNs::types(def, v),
|
ModuleDefId::TypeAliasId(_) => PerNs::types(def, v),
|
||||||
ModuleDefId::BuiltinType(_) => PerNs::types(def, v),
|
ModuleDefId::BuiltinType(_) => PerNs::types(def, v),
|
||||||
ModuleDefId::MacroId(mac) => PerNs::macros(mac, v),
|
ModuleDefId::MacroId(mac) => PerNs::macros(mac, v),
|
||||||
|
|
|
@ -204,6 +204,7 @@ impl ItemTree {
|
||||||
consts,
|
consts,
|
||||||
statics,
|
statics,
|
||||||
traits,
|
traits,
|
||||||
|
trait_aliases,
|
||||||
impls,
|
impls,
|
||||||
type_aliases,
|
type_aliases,
|
||||||
mods,
|
mods,
|
||||||
|
@ -226,6 +227,7 @@ impl ItemTree {
|
||||||
consts.shrink_to_fit();
|
consts.shrink_to_fit();
|
||||||
statics.shrink_to_fit();
|
statics.shrink_to_fit();
|
||||||
traits.shrink_to_fit();
|
traits.shrink_to_fit();
|
||||||
|
trait_aliases.shrink_to_fit();
|
||||||
impls.shrink_to_fit();
|
impls.shrink_to_fit();
|
||||||
type_aliases.shrink_to_fit();
|
type_aliases.shrink_to_fit();
|
||||||
mods.shrink_to_fit();
|
mods.shrink_to_fit();
|
||||||
|
@ -276,6 +278,7 @@ struct ItemTreeData {
|
||||||
consts: Arena<Const>,
|
consts: Arena<Const>,
|
||||||
statics: Arena<Static>,
|
statics: Arena<Static>,
|
||||||
traits: Arena<Trait>,
|
traits: Arena<Trait>,
|
||||||
|
trait_aliases: Arena<TraitAlias>,
|
||||||
impls: Arena<Impl>,
|
impls: Arena<Impl>,
|
||||||
type_aliases: Arena<TypeAlias>,
|
type_aliases: Arena<TypeAlias>,
|
||||||
mods: Arena<Mod>,
|
mods: Arena<Mod>,
|
||||||
|
@ -496,6 +499,7 @@ mod_items! {
|
||||||
Const in consts -> ast::Const,
|
Const in consts -> ast::Const,
|
||||||
Static in statics -> ast::Static,
|
Static in statics -> ast::Static,
|
||||||
Trait in traits -> ast::Trait,
|
Trait in traits -> ast::Trait,
|
||||||
|
TraitAlias in trait_aliases -> ast::TraitAlias,
|
||||||
Impl in impls -> ast::Impl,
|
Impl in impls -> ast::Impl,
|
||||||
TypeAlias in type_aliases -> ast::TypeAlias,
|
TypeAlias in type_aliases -> ast::TypeAlias,
|
||||||
Mod in mods -> ast::Module,
|
Mod in mods -> ast::Module,
|
||||||
|
@ -672,11 +676,18 @@ pub struct Trait {
|
||||||
pub generic_params: Interned<GenericParams>,
|
pub generic_params: Interned<GenericParams>,
|
||||||
pub is_auto: bool,
|
pub is_auto: bool,
|
||||||
pub is_unsafe: bool,
|
pub is_unsafe: bool,
|
||||||
/// This is [`None`] if this Trait is a trait alias.
|
pub items: Box<[AssocItem]>,
|
||||||
pub items: Option<Box<[AssocItem]>>,
|
|
||||||
pub ast_id: FileAstId<ast::Trait>,
|
pub ast_id: FileAstId<ast::Trait>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
|
pub struct TraitAlias {
|
||||||
|
pub name: Name,
|
||||||
|
pub visibility: RawVisibilityId,
|
||||||
|
pub generic_params: Interned<GenericParams>,
|
||||||
|
pub ast_id: FileAstId<ast::TraitAlias>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Impl {
|
pub struct Impl {
|
||||||
pub generic_params: Interned<GenericParams>,
|
pub generic_params: Interned<GenericParams>,
|
||||||
|
@ -872,6 +883,7 @@ impl ModItem {
|
||||||
| ModItem::Enum(_)
|
| ModItem::Enum(_)
|
||||||
| ModItem::Static(_)
|
| ModItem::Static(_)
|
||||||
| ModItem::Trait(_)
|
| ModItem::Trait(_)
|
||||||
|
| ModItem::TraitAlias(_)
|
||||||
| ModItem::Impl(_)
|
| ModItem::Impl(_)
|
||||||
| ModItem::Mod(_)
|
| ModItem::Mod(_)
|
||||||
| ModItem::MacroRules(_)
|
| ModItem::MacroRules(_)
|
||||||
|
@ -899,6 +911,7 @@ impl ModItem {
|
||||||
ModItem::Const(it) => tree[it.index].ast_id().upcast(),
|
ModItem::Const(it) => tree[it.index].ast_id().upcast(),
|
||||||
ModItem::Static(it) => tree[it.index].ast_id().upcast(),
|
ModItem::Static(it) => tree[it.index].ast_id().upcast(),
|
||||||
ModItem::Trait(it) => tree[it.index].ast_id().upcast(),
|
ModItem::Trait(it) => tree[it.index].ast_id().upcast(),
|
||||||
|
ModItem::TraitAlias(it) => tree[it.index].ast_id().upcast(),
|
||||||
ModItem::Impl(it) => tree[it.index].ast_id().upcast(),
|
ModItem::Impl(it) => tree[it.index].ast_id().upcast(),
|
||||||
ModItem::TypeAlias(it) => tree[it.index].ast_id().upcast(),
|
ModItem::TypeAlias(it) => tree[it.index].ast_id().upcast(),
|
||||||
ModItem::Mod(it) => tree[it.index].ast_id().upcast(),
|
ModItem::Mod(it) => tree[it.index].ast_id().upcast(),
|
||||||
|
|
|
@ -110,7 +110,7 @@ impl<'a> Ctx<'a> {
|
||||||
ast::Item::Const(ast) => self.lower_const(ast).into(),
|
ast::Item::Const(ast) => self.lower_const(ast).into(),
|
||||||
ast::Item::Module(ast) => self.lower_module(ast)?.into(),
|
ast::Item::Module(ast) => self.lower_module(ast)?.into(),
|
||||||
ast::Item::Trait(ast) => self.lower_trait(ast)?.into(),
|
ast::Item::Trait(ast) => self.lower_trait(ast)?.into(),
|
||||||
ast::Item::TraitAlias(_) => return None,
|
ast::Item::TraitAlias(ast) => self.lower_trait_alias(ast)?.into(),
|
||||||
ast::Item::Impl(ast) => self.lower_impl(ast)?.into(),
|
ast::Item::Impl(ast) => self.lower_impl(ast)?.into(),
|
||||||
ast::Item::Use(ast) => self.lower_use(ast)?.into(),
|
ast::Item::Use(ast) => self.lower_use(ast)?.into(),
|
||||||
ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast)?.into(),
|
ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast)?.into(),
|
||||||
|
@ -446,20 +446,39 @@ impl<'a> Ctx<'a> {
|
||||||
self.lower_generic_params(HasImplicitSelf::Yes(trait_def.type_bound_list()), trait_def);
|
self.lower_generic_params(HasImplicitSelf::Yes(trait_def.type_bound_list()), trait_def);
|
||||||
let is_auto = trait_def.auto_token().is_some();
|
let is_auto = trait_def.auto_token().is_some();
|
||||||
let is_unsafe = trait_def.unsafe_token().is_some();
|
let is_unsafe = trait_def.unsafe_token().is_some();
|
||||||
let items = trait_def.assoc_item_list().map(|list| {
|
|
||||||
list.assoc_items()
|
|
||||||
.filter_map(|item| {
|
|
||||||
let attrs = RawAttrs::new(self.db.upcast(), &item, self.hygiene());
|
|
||||||
self.lower_assoc_item(&item).map(|item| {
|
|
||||||
self.add_attrs(ModItem::from(item).into(), attrs);
|
|
||||||
item
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
});
|
|
||||||
let ast_id = self.source_ast_id_map.ast_id(trait_def);
|
let ast_id = self.source_ast_id_map.ast_id(trait_def);
|
||||||
let res = Trait { name, visibility, generic_params, is_auto, is_unsafe, items, ast_id };
|
|
||||||
Some(id(self.data().traits.alloc(res)))
|
let items = trait_def
|
||||||
|
.assoc_item_list()
|
||||||
|
.into_iter()
|
||||||
|
.flat_map(|list| list.assoc_items())
|
||||||
|
.filter_map(|item| {
|
||||||
|
let attrs = RawAttrs::new(self.db.upcast(), &item, self.hygiene());
|
||||||
|
self.lower_assoc_item(&item).map(|item| {
|
||||||
|
self.add_attrs(ModItem::from(item).into(), attrs);
|
||||||
|
item
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let def = Trait { name, visibility, generic_params, is_auto, is_unsafe, items, ast_id };
|
||||||
|
Some(id(self.data().traits.alloc(def)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lower_trait_alias(
|
||||||
|
&mut self,
|
||||||
|
trait_alias_def: &ast::TraitAlias,
|
||||||
|
) -> Option<FileItemTreeId<TraitAlias>> {
|
||||||
|
let name = trait_alias_def.name()?.as_name();
|
||||||
|
let visibility = self.lower_visibility(trait_alias_def);
|
||||||
|
let generic_params = self.lower_generic_params(
|
||||||
|
HasImplicitSelf::Yes(trait_alias_def.type_bound_list()),
|
||||||
|
trait_alias_def,
|
||||||
|
);
|
||||||
|
let ast_id = self.source_ast_id_map.ast_id(trait_alias_def);
|
||||||
|
|
||||||
|
let alias = TraitAlias { name, visibility, generic_params, ast_id };
|
||||||
|
Some(id(self.data().trait_aliases.alloc(alias)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option<FileItemTreeId<Impl>> {
|
fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option<FileItemTreeId<Impl>> {
|
||||||
|
|
|
@ -374,23 +374,24 @@ impl<'a> Printer<'a> {
|
||||||
}
|
}
|
||||||
w!(self, "trait {}", name);
|
w!(self, "trait {}", name);
|
||||||
self.print_generic_params(generic_params);
|
self.print_generic_params(generic_params);
|
||||||
match items {
|
self.print_where_clause_and_opening_brace(generic_params);
|
||||||
Some(items) => {
|
self.indented(|this| {
|
||||||
self.print_where_clause_and_opening_brace(generic_params);
|
for item in &**items {
|
||||||
self.indented(|this| {
|
this.print_mod_item((*item).into());
|
||||||
for item in &**items {
|
|
||||||
this.print_mod_item((*item).into());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
None => {
|
});
|
||||||
w!(self, " = ");
|
|
||||||
// FIXME: Print the aliased traits
|
|
||||||
self.print_where_clause_and_opening_brace(generic_params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wln!(self, "}}");
|
wln!(self, "}}");
|
||||||
}
|
}
|
||||||
|
ModItem::TraitAlias(it) => {
|
||||||
|
let TraitAlias { name, visibility, generic_params, ast_id: _ } = &self.tree[it];
|
||||||
|
self.print_visibility(*visibility);
|
||||||
|
w!(self, "trait {}", name);
|
||||||
|
self.print_generic_params(generic_params);
|
||||||
|
w!(self, " = ");
|
||||||
|
self.print_where_clause(generic_params);
|
||||||
|
w!(self, ";");
|
||||||
|
wln!(self);
|
||||||
|
}
|
||||||
ModItem::Impl(it) => {
|
ModItem::Impl(it) => {
|
||||||
let Impl { target_trait, self_ty, is_negative, items, generic_params, ast_id: _ } =
|
let Impl { target_trait, self_ty, is_negative, items, generic_params, ast_id: _ } =
|
||||||
&self.tree[it];
|
&self.tree[it];
|
||||||
|
|
|
@ -9,8 +9,8 @@ use syntax::{ast, AstNode, AstPtr};
|
||||||
use crate::{
|
use crate::{
|
||||||
dyn_map::{DynMap, Policy},
|
dyn_map::{DynMap, Policy},
|
||||||
ConstId, EnumId, EnumVariantId, FieldId, FunctionId, ImplId, LifetimeParamId, Macro2Id,
|
ConstId, EnumId, EnumVariantId, FieldId, FunctionId, ImplId, LifetimeParamId, Macro2Id,
|
||||||
MacroRulesId, ProcMacroId, StaticId, StructId, TraitId, TypeAliasId, TypeOrConstParamId,
|
MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId,
|
||||||
UnionId,
|
TypeOrConstParamId, UnionId,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Key<K, V> = crate::dyn_map::Key<K, V, AstPtrPolicy<K, V>>;
|
pub type Key<K, V> = crate::dyn_map::Key<K, V, AstPtrPolicy<K, V>>;
|
||||||
|
@ -21,6 +21,7 @@ pub const STATIC: Key<ast::Static, StaticId> = Key::new();
|
||||||
pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
|
pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
|
||||||
pub const IMPL: Key<ast::Impl, ImplId> = Key::new();
|
pub const IMPL: Key<ast::Impl, ImplId> = Key::new();
|
||||||
pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
|
pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
|
||||||
|
pub const TRAIT_ALIAS: Key<ast::TraitAlias, TraitAliasId> = Key::new();
|
||||||
pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
|
pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
|
||||||
pub const UNION: Key<ast::Union, UnionId> = Key::new();
|
pub const UNION: Key<ast::Union, UnionId> = Key::new();
|
||||||
pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
|
pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
|
||||||
|
|
|
@ -86,7 +86,7 @@ use crate::{
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
item_tree::{
|
item_tree::{
|
||||||
Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, MacroDef, MacroRules, ModItem,
|
Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, MacroDef, MacroRules, ModItem,
|
||||||
Static, Struct, Trait, TypeAlias, Union,
|
Static, Struct, Trait, TraitAlias, TypeAlias, Union,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -261,6 +261,11 @@ pub struct TraitId(salsa::InternId);
|
||||||
pub type TraitLoc = ItemLoc<Trait>;
|
pub type TraitLoc = ItemLoc<Trait>;
|
||||||
impl_intern!(TraitId, TraitLoc, intern_trait, lookup_intern_trait);
|
impl_intern!(TraitId, TraitLoc, intern_trait, lookup_intern_trait);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub struct TraitAliasId(salsa::InternId);
|
||||||
|
pub type TraitAliasLoc = ItemLoc<TraitAlias>;
|
||||||
|
impl_intern!(TraitAliasId, TraitAliasLoc, intern_trait_alias, lookup_intern_trait_alias);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct TypeAliasId(salsa::InternId);
|
pub struct TypeAliasId(salsa::InternId);
|
||||||
type TypeAliasLoc = AssocItemLoc<TypeAlias>;
|
type TypeAliasLoc = AssocItemLoc<TypeAlias>;
|
||||||
|
@ -453,6 +458,7 @@ pub enum ModuleDefId {
|
||||||
ConstId(ConstId),
|
ConstId(ConstId),
|
||||||
StaticId(StaticId),
|
StaticId(StaticId),
|
||||||
TraitId(TraitId),
|
TraitId(TraitId),
|
||||||
|
TraitAliasId(TraitAliasId),
|
||||||
TypeAliasId(TypeAliasId),
|
TypeAliasId(TypeAliasId),
|
||||||
BuiltinType(BuiltinType),
|
BuiltinType(BuiltinType),
|
||||||
MacroId(MacroId),
|
MacroId(MacroId),
|
||||||
|
@ -466,6 +472,7 @@ impl_from!(
|
||||||
ConstId,
|
ConstId,
|
||||||
StaticId,
|
StaticId,
|
||||||
TraitId,
|
TraitId,
|
||||||
|
TraitAliasId,
|
||||||
TypeAliasId,
|
TypeAliasId,
|
||||||
BuiltinType
|
BuiltinType
|
||||||
for ModuleDefId
|
for ModuleDefId
|
||||||
|
@ -516,6 +523,7 @@ pub enum GenericDefId {
|
||||||
FunctionId(FunctionId),
|
FunctionId(FunctionId),
|
||||||
AdtId(AdtId),
|
AdtId(AdtId),
|
||||||
TraitId(TraitId),
|
TraitId(TraitId),
|
||||||
|
TraitAliasId(TraitAliasId),
|
||||||
TypeAliasId(TypeAliasId),
|
TypeAliasId(TypeAliasId),
|
||||||
ImplId(ImplId),
|
ImplId(ImplId),
|
||||||
// enum variants cannot have generics themselves, but their parent enums
|
// enum variants cannot have generics themselves, but their parent enums
|
||||||
|
@ -528,6 +536,7 @@ impl_from!(
|
||||||
FunctionId,
|
FunctionId,
|
||||||
AdtId(StructId, EnumId, UnionId),
|
AdtId(StructId, EnumId, UnionId),
|
||||||
TraitId,
|
TraitId,
|
||||||
|
TraitAliasId,
|
||||||
TypeAliasId,
|
TypeAliasId,
|
||||||
ImplId,
|
ImplId,
|
||||||
EnumVariantId,
|
EnumVariantId,
|
||||||
|
@ -555,6 +564,7 @@ pub enum AttrDefId {
|
||||||
StaticId(StaticId),
|
StaticId(StaticId),
|
||||||
ConstId(ConstId),
|
ConstId(ConstId),
|
||||||
TraitId(TraitId),
|
TraitId(TraitId),
|
||||||
|
TraitAliasId(TraitAliasId),
|
||||||
TypeAliasId(TypeAliasId),
|
TypeAliasId(TypeAliasId),
|
||||||
MacroId(MacroId),
|
MacroId(MacroId),
|
||||||
ImplId(ImplId),
|
ImplId(ImplId),
|
||||||
|
@ -714,6 +724,7 @@ impl HasModule for GenericDefId {
|
||||||
GenericDefId::FunctionId(it) => it.lookup(db).module(db),
|
GenericDefId::FunctionId(it) => it.lookup(db).module(db),
|
||||||
GenericDefId::AdtId(it) => it.module(db),
|
GenericDefId::AdtId(it) => it.module(db),
|
||||||
GenericDefId::TraitId(it) => it.lookup(db).container,
|
GenericDefId::TraitId(it) => it.lookup(db).container,
|
||||||
|
GenericDefId::TraitAliasId(it) => it.lookup(db).container,
|
||||||
GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
|
GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
|
||||||
GenericDefId::ImplId(it) => it.lookup(db).container,
|
GenericDefId::ImplId(it) => it.lookup(db).container,
|
||||||
GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container,
|
GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container,
|
||||||
|
@ -747,6 +758,7 @@ impl ModuleDefId {
|
||||||
ModuleDefId::ConstId(id) => id.lookup(db).container.module(db),
|
ModuleDefId::ConstId(id) => id.lookup(db).container.module(db),
|
||||||
ModuleDefId::StaticId(id) => id.lookup(db).module(db),
|
ModuleDefId::StaticId(id) => id.lookup(db).module(db),
|
||||||
ModuleDefId::TraitId(id) => id.lookup(db).container,
|
ModuleDefId::TraitId(id) => id.lookup(db).container,
|
||||||
|
ModuleDefId::TraitAliasId(id) => id.lookup(db).container,
|
||||||
ModuleDefId::TypeAliasId(id) => id.lookup(db).module(db),
|
ModuleDefId::TypeAliasId(id) => id.lookup(db).module(db),
|
||||||
ModuleDefId::MacroId(id) => id.module(db),
|
ModuleDefId::MacroId(id) => id.module(db),
|
||||||
ModuleDefId::BuiltinType(_) => return None,
|
ModuleDefId::BuiltinType(_) => return None,
|
||||||
|
@ -765,6 +777,7 @@ impl AttrDefId {
|
||||||
AttrDefId::StaticId(it) => it.lookup(db).module(db).krate,
|
AttrDefId::StaticId(it) => it.lookup(db).module(db).krate,
|
||||||
AttrDefId::ConstId(it) => it.lookup(db).module(db).krate,
|
AttrDefId::ConstId(it) => it.lookup(db).module(db).krate,
|
||||||
AttrDefId::TraitId(it) => it.lookup(db).container.krate,
|
AttrDefId::TraitId(it) => it.lookup(db).container.krate,
|
||||||
|
AttrDefId::TraitAliasId(it) => it.lookup(db).container.krate,
|
||||||
AttrDefId::TypeAliasId(it) => it.lookup(db).module(db).krate,
|
AttrDefId::TypeAliasId(it) => it.lookup(db).module(db).krate,
|
||||||
AttrDefId::ImplId(it) => it.lookup(db).container.krate,
|
AttrDefId::ImplId(it) => it.lookup(db).container.krate,
|
||||||
AttrDefId::ExternBlockId(it) => it.lookup(db).container.krate,
|
AttrDefId::ExternBlockId(it) => it.lookup(db).container.krate,
|
||||||
|
|
|
@ -51,7 +51,8 @@ use crate::{
|
||||||
AdtId, AstId, AstIdWithPath, ConstLoc, EnumLoc, EnumVariantId, ExternBlockLoc, FunctionId,
|
AdtId, AstId, AstIdWithPath, ConstLoc, EnumLoc, EnumVariantId, ExternBlockLoc, FunctionId,
|
||||||
FunctionLoc, ImplLoc, Intern, ItemContainerId, LocalModuleId, Macro2Id, Macro2Loc,
|
FunctionLoc, ImplLoc, Intern, ItemContainerId, LocalModuleId, Macro2Id, Macro2Loc,
|
||||||
MacroExpander, MacroId, MacroRulesId, MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId,
|
MacroExpander, MacroId, MacroRulesId, MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId,
|
||||||
ProcMacroLoc, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro,
|
ProcMacroLoc, StaticLoc, StructLoc, TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc,
|
||||||
|
UnresolvedMacro,
|
||||||
};
|
};
|
||||||
|
|
||||||
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
|
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
|
||||||
|
@ -1709,6 +1710,20 @@ impl ModCollector<'_, '_> {
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
ModItem::TraitAlias(id) => {
|
||||||
|
let it = &self.item_tree[id];
|
||||||
|
|
||||||
|
let vis = resolve_vis(def_map, &self.item_tree[it.visibility]);
|
||||||
|
update_def(
|
||||||
|
self.def_collector,
|
||||||
|
TraitAliasLoc { container: module, id: ItemTreeId::new(self.tree_id, id) }
|
||||||
|
.intern(db)
|
||||||
|
.into(),
|
||||||
|
&it.name,
|
||||||
|
vis,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
ModItem::TypeAlias(id) => {
|
ModItem::TypeAlias(id) => {
|
||||||
let it = &self.item_tree[id];
|
let it = &self.item_tree[id];
|
||||||
|
|
||||||
|
|
|
@ -223,6 +223,7 @@ pub type Ty = ();
|
||||||
ModuleDefId::ConstId(it) => drop(db.const_data(it)),
|
ModuleDefId::ConstId(it) => drop(db.const_data(it)),
|
||||||
ModuleDefId::StaticId(it) => drop(db.static_data(it)),
|
ModuleDefId::StaticId(it) => drop(db.static_data(it)),
|
||||||
ModuleDefId::TraitId(it) => drop(db.trait_data(it)),
|
ModuleDefId::TraitId(it) => drop(db.trait_data(it)),
|
||||||
|
ModuleDefId::TraitAliasId(it) => drop(db.trait_alias_data(it)),
|
||||||
ModuleDefId::TypeAliasId(it) => drop(db.type_alias_data(it)),
|
ModuleDefId::TypeAliasId(it) => drop(db.type_alias_data(it)),
|
||||||
ModuleDefId::EnumVariantId(_)
|
ModuleDefId::EnumVariantId(_)
|
||||||
| ModuleDefId::ModuleId(_)
|
| ModuleDefId::ModuleId(_)
|
||||||
|
|
|
@ -22,7 +22,8 @@ use crate::{
|
||||||
AdtId, AssocItemId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId,
|
AdtId, AssocItemId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId,
|
||||||
FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
|
FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
|
||||||
LocalModuleId, Lookup, Macro2Id, MacroId, MacroRulesId, ModuleDefId, ModuleId, ProcMacroId,
|
LocalModuleId, Lookup, Macro2Id, MacroId, MacroRulesId, ModuleDefId, ModuleId, ProcMacroId,
|
||||||
StaticId, StructId, TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId, VariantId,
|
StaticId, StructId, TraitAliasId, TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId,
|
||||||
|
VariantId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -74,6 +75,7 @@ pub enum TypeNs {
|
||||||
TypeAliasId(TypeAliasId),
|
TypeAliasId(TypeAliasId),
|
||||||
BuiltinType(BuiltinType),
|
BuiltinType(BuiltinType),
|
||||||
TraitId(TraitId),
|
TraitId(TraitId),
|
||||||
|
TraitAliasId(TraitAliasId),
|
||||||
// Module belong to type ns, but the resolver is used when all module paths
|
// Module belong to type ns, but the resolver is used when all module paths
|
||||||
// are fully resolved.
|
// are fully resolved.
|
||||||
// ModuleId(ModuleId)
|
// ModuleId(ModuleId)
|
||||||
|
@ -402,6 +404,8 @@ impl Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn traits_in_scope(&self, db: &dyn DefDatabase) -> FxHashSet<TraitId> {
|
pub fn traits_in_scope(&self, db: &dyn DefDatabase) -> FxHashSet<TraitId> {
|
||||||
|
// FIXME(trait_alias): Trait alias brings aliased traits in scope! Note that supertraits of
|
||||||
|
// aliased traits are NOT brought in scope (unless also aliased).
|
||||||
let mut traits = FxHashSet::default();
|
let mut traits = FxHashSet::default();
|
||||||
|
|
||||||
for scope in self.scopes() {
|
for scope in self.scopes() {
|
||||||
|
@ -650,6 +654,7 @@ impl ModuleItemMap {
|
||||||
let ty = match module_def.take_types()? {
|
let ty = match module_def.take_types()? {
|
||||||
ModuleDefId::AdtId(it) => TypeNs::AdtId(it),
|
ModuleDefId::AdtId(it) => TypeNs::AdtId(it),
|
||||||
ModuleDefId::TraitId(it) => TypeNs::TraitId(it),
|
ModuleDefId::TraitId(it) => TypeNs::TraitId(it),
|
||||||
|
ModuleDefId::TraitAliasId(it) => TypeNs::TraitAliasId(it),
|
||||||
ModuleDefId::TypeAliasId(it) => TypeNs::TypeAliasId(it),
|
ModuleDefId::TypeAliasId(it) => TypeNs::TypeAliasId(it),
|
||||||
ModuleDefId::BuiltinType(it) => TypeNs::BuiltinType(it),
|
ModuleDefId::BuiltinType(it) => TypeNs::BuiltinType(it),
|
||||||
|
|
||||||
|
@ -687,6 +692,7 @@ fn to_value_ns(per_ns: PerNs) -> Option<ValueNs> {
|
||||||
|
|
||||||
ModuleDefId::AdtId(AdtId::EnumId(_) | AdtId::UnionId(_))
|
ModuleDefId::AdtId(AdtId::EnumId(_) | AdtId::UnionId(_))
|
||||||
| ModuleDefId::TraitId(_)
|
| ModuleDefId::TraitId(_)
|
||||||
|
| ModuleDefId::TraitAliasId(_)
|
||||||
| ModuleDefId::TypeAliasId(_)
|
| ModuleDefId::TypeAliasId(_)
|
||||||
| ModuleDefId::BuiltinType(_)
|
| ModuleDefId::BuiltinType(_)
|
||||||
| ModuleDefId::MacroId(_)
|
| ModuleDefId::MacroId(_)
|
||||||
|
@ -704,6 +710,7 @@ fn to_type_ns(per_ns: PerNs) -> Option<TypeNs> {
|
||||||
ModuleDefId::BuiltinType(it) => TypeNs::BuiltinType(it),
|
ModuleDefId::BuiltinType(it) => TypeNs::BuiltinType(it),
|
||||||
|
|
||||||
ModuleDefId::TraitId(it) => TypeNs::TraitId(it),
|
ModuleDefId::TraitId(it) => TypeNs::TraitId(it),
|
||||||
|
ModuleDefId::TraitAliasId(it) => TypeNs::TraitAliasId(it),
|
||||||
|
|
||||||
ModuleDefId::FunctionId(_)
|
ModuleDefId::FunctionId(_)
|
||||||
| ModuleDefId::ConstId(_)
|
| ModuleDefId::ConstId(_)
|
||||||
|
@ -788,6 +795,12 @@ impl HasResolver for TraitId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasResolver for TraitAliasId {
|
||||||
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
||||||
|
self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Into<AdtId> + Copy> HasResolver for T {
|
impl<T: Into<AdtId> + Copy> HasResolver for T {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
||||||
let def = self.into();
|
let def = self.into();
|
||||||
|
@ -867,6 +880,7 @@ impl HasResolver for GenericDefId {
|
||||||
GenericDefId::FunctionId(inner) => inner.resolver(db),
|
GenericDefId::FunctionId(inner) => inner.resolver(db),
|
||||||
GenericDefId::AdtId(adt) => adt.resolver(db),
|
GenericDefId::AdtId(adt) => adt.resolver(db),
|
||||||
GenericDefId::TraitId(inner) => inner.resolver(db),
|
GenericDefId::TraitId(inner) => inner.resolver(db),
|
||||||
|
GenericDefId::TraitAliasId(inner) => inner.resolver(db),
|
||||||
GenericDefId::TypeAliasId(inner) => inner.resolver(db),
|
GenericDefId::TypeAliasId(inner) => inner.resolver(db),
|
||||||
GenericDefId::ImplId(inner) => inner.resolver(db),
|
GenericDefId::ImplId(inner) => inner.resolver(db),
|
||||||
GenericDefId::EnumVariantId(inner) => inner.parent.resolver(db),
|
GenericDefId::EnumVariantId(inner) => inner.parent.resolver(db),
|
||||||
|
|
|
@ -178,6 +178,7 @@ impl<'a> DeclValidator<'a> {
|
||||||
AttrDefId::StaticId(sid) => Some(sid.lookup(self.db.upcast()).container.into()),
|
AttrDefId::StaticId(sid) => Some(sid.lookup(self.db.upcast()).container.into()),
|
||||||
AttrDefId::ConstId(cid) => Some(cid.lookup(self.db.upcast()).container.into()),
|
AttrDefId::ConstId(cid) => Some(cid.lookup(self.db.upcast()).container.into()),
|
||||||
AttrDefId::TraitId(tid) => Some(tid.lookup(self.db.upcast()).container.into()),
|
AttrDefId::TraitId(tid) => Some(tid.lookup(self.db.upcast()).container.into()),
|
||||||
|
AttrDefId::TraitAliasId(taid) => Some(taid.lookup(self.db.upcast()).container.into()),
|
||||||
AttrDefId::ImplId(iid) => Some(iid.lookup(self.db.upcast()).container.into()),
|
AttrDefId::ImplId(iid) => Some(iid.lookup(self.db.upcast()).container.into()),
|
||||||
AttrDefId::ExternBlockId(id) => Some(id.lookup(self.db.upcast()).container.into()),
|
AttrDefId::ExternBlockId(id) => Some(id.lookup(self.db.upcast()).container.into()),
|
||||||
// These warnings should not explore macro definitions at all
|
// These warnings should not explore macro definitions at all
|
||||||
|
|
|
@ -868,7 +868,10 @@ impl<'a> InferenceContext<'a> {
|
||||||
// FIXME potentially resolve assoc type
|
// FIXME potentially resolve assoc type
|
||||||
(self.err_ty(), None)
|
(self.err_ty(), None)
|
||||||
}
|
}
|
||||||
TypeNs::AdtId(AdtId::EnumId(_)) | TypeNs::BuiltinType(_) | TypeNs::TraitId(_) => {
|
TypeNs::AdtId(AdtId::EnumId(_))
|
||||||
|
| TypeNs::BuiltinType(_)
|
||||||
|
| TypeNs::TraitId(_)
|
||||||
|
| TypeNs::TraitAliasId(_) => {
|
||||||
// FIXME diagnostic
|
// FIXME diagnostic
|
||||||
(self.err_ty(), None)
|
(self.err_ty(), None)
|
||||||
}
|
}
|
||||||
|
|
|
@ -522,6 +522,10 @@ impl<'a> TyLoweringContext<'a> {
|
||||||
};
|
};
|
||||||
return (ty, None);
|
return (ty, None);
|
||||||
}
|
}
|
||||||
|
TypeNs::TraitAliasId(_) => {
|
||||||
|
// FIXME(trait_alias): Implement trait alias.
|
||||||
|
return (TyKind::Error.intern(Interner), None);
|
||||||
|
}
|
||||||
TypeNs::GenericParam(param_id) => {
|
TypeNs::GenericParam(param_id) => {
|
||||||
let generics = generics(
|
let generics = generics(
|
||||||
self.db.upcast(),
|
self.db.upcast(),
|
||||||
|
@ -877,6 +881,7 @@ impl<'a> TyLoweringContext<'a> {
|
||||||
) -> Option<TraitRef> {
|
) -> Option<TraitRef> {
|
||||||
let resolved =
|
let resolved =
|
||||||
match self.resolver.resolve_path_in_type_ns_fully(self.db.upcast(), path.mod_path())? {
|
match self.resolver.resolve_path_in_type_ns_fully(self.db.upcast(), path.mod_path())? {
|
||||||
|
// FIXME(trait_alias): We need to handle trait alias here.
|
||||||
TypeNs::TraitId(tr) => tr,
|
TypeNs::TraitId(tr) => tr,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
@ -1442,6 +1447,7 @@ pub(crate) fn trait_environment_query(
|
||||||
GenericDefId::FunctionId(f) => Some(f.lookup(db.upcast()).container),
|
GenericDefId::FunctionId(f) => Some(f.lookup(db.upcast()).container),
|
||||||
GenericDefId::AdtId(_) => None,
|
GenericDefId::AdtId(_) => None,
|
||||||
GenericDefId::TraitId(_) => None,
|
GenericDefId::TraitId(_) => None,
|
||||||
|
GenericDefId::TraitAliasId(_) => None,
|
||||||
GenericDefId::TypeAliasId(t) => Some(t.lookup(db.upcast()).container),
|
GenericDefId::TypeAliasId(t) => Some(t.lookup(db.upcast()).container),
|
||||||
GenericDefId::ImplId(_) => None,
|
GenericDefId::ImplId(_) => None,
|
||||||
GenericDefId::EnumVariantId(_) => None,
|
GenericDefId::EnumVariantId(_) => None,
|
||||||
|
|
|
@ -315,7 +315,10 @@ fn parent_generic_def(db: &dyn DefDatabase, def: GenericDefId) -> Option<Generic
|
||||||
GenericDefId::TypeAliasId(it) => it.lookup(db).container,
|
GenericDefId::TypeAliasId(it) => it.lookup(db).container,
|
||||||
GenericDefId::ConstId(it) => it.lookup(db).container,
|
GenericDefId::ConstId(it) => it.lookup(db).container,
|
||||||
GenericDefId::EnumVariantId(it) => return Some(it.parent.into()),
|
GenericDefId::EnumVariantId(it) => return Some(it.parent.into()),
|
||||||
GenericDefId::AdtId(_) | GenericDefId::TraitId(_) | GenericDefId::ImplId(_) => return None,
|
GenericDefId::AdtId(_)
|
||||||
|
| GenericDefId::TraitId(_)
|
||||||
|
| GenericDefId::ImplId(_)
|
||||||
|
| GenericDefId::TraitAliasId(_) => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
match container {
|
match container {
|
||||||
|
|
|
@ -14,7 +14,8 @@ use syntax::{ast, AstNode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Adt, AssocItem, Const, ConstParam, Enum, Field, Function, GenericParam, Impl, LifetimeParam,
|
Adt, AssocItem, Const, ConstParam, Enum, Field, Function, GenericParam, Impl, LifetimeParam,
|
||||||
Macro, Module, ModuleDef, Static, Struct, Trait, TypeAlias, TypeParam, Union, Variant,
|
Macro, Module, ModuleDef, Static, Struct, Trait, TraitAlias, TypeAlias, TypeParam, Union,
|
||||||
|
Variant,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait HasAttrs {
|
pub trait HasAttrs {
|
||||||
|
@ -60,6 +61,7 @@ impl_has_attrs![
|
||||||
(Static, StaticId),
|
(Static, StaticId),
|
||||||
(Const, ConstId),
|
(Const, ConstId),
|
||||||
(Trait, TraitId),
|
(Trait, TraitId),
|
||||||
|
(TraitAlias, TraitAliasId),
|
||||||
(TypeAlias, TypeAliasId),
|
(TypeAlias, TypeAliasId),
|
||||||
(Macro, MacroId),
|
(Macro, MacroId),
|
||||||
(Function, FunctionId),
|
(Function, FunctionId),
|
||||||
|
@ -134,6 +136,7 @@ fn resolve_doc_path(
|
||||||
AttrDefId::StaticId(it) => it.resolver(db.upcast()),
|
AttrDefId::StaticId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::ConstId(it) => it.resolver(db.upcast()),
|
AttrDefId::ConstId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::TraitId(it) => it.resolver(db.upcast()),
|
AttrDefId::TraitId(it) => it.resolver(db.upcast()),
|
||||||
|
AttrDefId::TraitAliasId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::TypeAliasId(it) => it.resolver(db.upcast()),
|
AttrDefId::TypeAliasId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::ImplId(it) => it.resolver(db.upcast()),
|
AttrDefId::ImplId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::ExternBlockId(it) => it.resolver(db.upcast()),
|
AttrDefId::ExternBlockId(it) => it.resolver(db.upcast()),
|
||||||
|
|
|
@ -18,8 +18,8 @@ use hir_ty::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Adt, AsAssocItem, AssocItemContainer, Const, ConstParam, Enum, Field, Function, GenericParam,
|
Adt, AsAssocItem, AssocItemContainer, Const, ConstParam, Enum, Field, Function, GenericParam,
|
||||||
HasCrate, HasVisibility, LifetimeParam, Macro, Module, Static, Struct, Trait, TyBuilder, Type,
|
HasCrate, HasVisibility, LifetimeParam, Macro, Module, Static, Struct, Trait, TraitAlias,
|
||||||
TypeAlias, TypeOrConstParam, TypeParam, Union, Variant,
|
TyBuilder, Type, TypeAlias, TypeOrConstParam, TypeParam, Union, Variant,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl HirDisplay for Function {
|
impl HirDisplay for Function {
|
||||||
|
@ -501,6 +501,22 @@ impl HirDisplay for Trait {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HirDisplay for TraitAlias {
|
||||||
|
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
||||||
|
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
|
||||||
|
let data = f.db.trait_alias_data(self.id);
|
||||||
|
write!(f, "trait {}", data.name)?;
|
||||||
|
let def_id = GenericDefId::TraitAliasId(self.id);
|
||||||
|
write_generic_params(def_id, f)?;
|
||||||
|
f.write_str(" = ")?;
|
||||||
|
// FIXME: Currently we lower every bounds in a trait alias as a trait bound on `Self` i.e.
|
||||||
|
// `trait Foo = Bar` is stored and displayed as `trait Foo = where Self: Bar`, which might
|
||||||
|
// be less readable.
|
||||||
|
write_where_clause(def_id, f)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl HirDisplay for TypeAlias {
|
impl HirDisplay for TypeAlias {
|
||||||
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
||||||
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
|
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
|
||||||
|
|
|
@ -37,6 +37,7 @@ from_id![
|
||||||
(hir_def::EnumId, crate::Enum),
|
(hir_def::EnumId, crate::Enum),
|
||||||
(hir_def::TypeAliasId, crate::TypeAlias),
|
(hir_def::TypeAliasId, crate::TypeAlias),
|
||||||
(hir_def::TraitId, crate::Trait),
|
(hir_def::TraitId, crate::Trait),
|
||||||
|
(hir_def::TraitAliasId, crate::TraitAlias),
|
||||||
(hir_def::StaticId, crate::Static),
|
(hir_def::StaticId, crate::Static),
|
||||||
(hir_def::ConstId, crate::Const),
|
(hir_def::ConstId, crate::Const),
|
||||||
(hir_def::FunctionId, crate::Function),
|
(hir_def::FunctionId, crate::Function),
|
||||||
|
@ -110,6 +111,7 @@ impl From<ModuleDefId> for ModuleDef {
|
||||||
ModuleDefId::ConstId(it) => ModuleDef::Const(it.into()),
|
ModuleDefId::ConstId(it) => ModuleDef::Const(it.into()),
|
||||||
ModuleDefId::StaticId(it) => ModuleDef::Static(it.into()),
|
ModuleDefId::StaticId(it) => ModuleDef::Static(it.into()),
|
||||||
ModuleDefId::TraitId(it) => ModuleDef::Trait(it.into()),
|
ModuleDefId::TraitId(it) => ModuleDef::Trait(it.into()),
|
||||||
|
ModuleDefId::TraitAliasId(it) => ModuleDef::TraitAlias(it.into()),
|
||||||
ModuleDefId::TypeAliasId(it) => ModuleDef::TypeAlias(it.into()),
|
ModuleDefId::TypeAliasId(it) => ModuleDef::TypeAlias(it.into()),
|
||||||
ModuleDefId::BuiltinType(it) => ModuleDef::BuiltinType(it.into()),
|
ModuleDefId::BuiltinType(it) => ModuleDef::BuiltinType(it.into()),
|
||||||
ModuleDefId::MacroId(it) => ModuleDef::Macro(it.into()),
|
ModuleDefId::MacroId(it) => ModuleDef::Macro(it.into()),
|
||||||
|
@ -127,6 +129,7 @@ impl From<ModuleDef> for ModuleDefId {
|
||||||
ModuleDef::Const(it) => ModuleDefId::ConstId(it.into()),
|
ModuleDef::Const(it) => ModuleDefId::ConstId(it.into()),
|
||||||
ModuleDef::Static(it) => ModuleDefId::StaticId(it.into()),
|
ModuleDef::Static(it) => ModuleDefId::StaticId(it.into()),
|
||||||
ModuleDef::Trait(it) => ModuleDefId::TraitId(it.into()),
|
ModuleDef::Trait(it) => ModuleDefId::TraitId(it.into()),
|
||||||
|
ModuleDef::TraitAlias(it) => ModuleDefId::TraitAliasId(it.into()),
|
||||||
ModuleDef::TypeAlias(it) => ModuleDefId::TypeAliasId(it.into()),
|
ModuleDef::TypeAlias(it) => ModuleDefId::TypeAliasId(it.into()),
|
||||||
ModuleDef::BuiltinType(it) => ModuleDefId::BuiltinType(it.into()),
|
ModuleDef::BuiltinType(it) => ModuleDefId::BuiltinType(it.into()),
|
||||||
ModuleDef::Macro(it) => ModuleDefId::MacroId(it.into()),
|
ModuleDef::Macro(it) => ModuleDefId::MacroId(it.into()),
|
||||||
|
@ -172,6 +175,7 @@ impl From<GenericDef> for GenericDefId {
|
||||||
GenericDef::Function(it) => GenericDefId::FunctionId(it.id),
|
GenericDef::Function(it) => GenericDefId::FunctionId(it.id),
|
||||||
GenericDef::Adt(it) => GenericDefId::AdtId(it.into()),
|
GenericDef::Adt(it) => GenericDefId::AdtId(it.into()),
|
||||||
GenericDef::Trait(it) => GenericDefId::TraitId(it.id),
|
GenericDef::Trait(it) => GenericDefId::TraitId(it.id),
|
||||||
|
GenericDef::TraitAlias(it) => GenericDefId::TraitAliasId(it.id),
|
||||||
GenericDef::TypeAlias(it) => GenericDefId::TypeAliasId(it.id),
|
GenericDef::TypeAlias(it) => GenericDefId::TypeAliasId(it.id),
|
||||||
GenericDef::Impl(it) => GenericDefId::ImplId(it.id),
|
GenericDef::Impl(it) => GenericDefId::ImplId(it.id),
|
||||||
GenericDef::Variant(it) => GenericDefId::EnumVariantId(it.into()),
|
GenericDef::Variant(it) => GenericDefId::EnumVariantId(it.into()),
|
||||||
|
@ -186,6 +190,7 @@ impl From<GenericDefId> for GenericDef {
|
||||||
GenericDefId::FunctionId(it) => GenericDef::Function(it.into()),
|
GenericDefId::FunctionId(it) => GenericDef::Function(it.into()),
|
||||||
GenericDefId::AdtId(it) => GenericDef::Adt(it.into()),
|
GenericDefId::AdtId(it) => GenericDef::Adt(it.into()),
|
||||||
GenericDefId::TraitId(it) => GenericDef::Trait(it.into()),
|
GenericDefId::TraitId(it) => GenericDef::Trait(it.into()),
|
||||||
|
GenericDefId::TraitAliasId(it) => GenericDef::TraitAlias(it.into()),
|
||||||
GenericDefId::TypeAliasId(it) => GenericDef::TypeAlias(it.into()),
|
GenericDefId::TypeAliasId(it) => GenericDef::TypeAlias(it.into()),
|
||||||
GenericDefId::ImplId(it) => GenericDef::Impl(it.into()),
|
GenericDefId::ImplId(it) => GenericDef::Impl(it.into()),
|
||||||
GenericDefId::EnumVariantId(it) => GenericDef::Variant(it.into()),
|
GenericDefId::EnumVariantId(it) => GenericDef::Variant(it.into()),
|
||||||
|
|
|
@ -11,7 +11,7 @@ use syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, Adt, Const, Enum, Field, FieldSource, Function, Impl, LifetimeParam, Macro,
|
db::HirDatabase, Adt, Const, Enum, Field, FieldSource, Function, Impl, LifetimeParam, Macro,
|
||||||
Module, Static, Struct, Trait, TypeAlias, TypeOrConstParam, Union, Variant,
|
Module, Static, Struct, Trait, TraitAlias, TypeAlias, TypeOrConstParam, Union, Variant,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait HasSource {
|
pub trait HasSource {
|
||||||
|
@ -122,6 +122,12 @@ impl HasSource for Trait {
|
||||||
Some(self.id.lookup(db.upcast()).source(db.upcast()))
|
Some(self.id.lookup(db.upcast()).source(db.upcast()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl HasSource for TraitAlias {
|
||||||
|
type Ast = ast::TraitAlias;
|
||||||
|
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
|
||||||
|
Some(self.id.lookup(db.upcast()).source(db.upcast()))
|
||||||
|
}
|
||||||
|
}
|
||||||
impl HasSource for TypeAlias {
|
impl HasSource for TypeAlias {
|
||||||
type Ast = ast::TypeAlias;
|
type Ast = ast::TypeAlias;
|
||||||
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
|
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
|
||||||
|
@ -158,7 +164,7 @@ impl HasSource for Impl {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasSource for TypeOrConstParam {
|
impl HasSource for TypeOrConstParam {
|
||||||
type Ast = Either<ast::TypeOrConstParam, ast::Trait>;
|
type Ast = Either<ast::TypeOrConstParam, ast::TraitOrAlias>;
|
||||||
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
|
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
|
||||||
let child_source = self.id.parent.child_source(db.upcast());
|
let child_source = self.id.parent.child_source(db.upcast());
|
||||||
Some(child_source.map(|it| it[self.id.local_id].clone()))
|
Some(child_source.map(|it| it[self.id.local_id].clone()))
|
||||||
|
|
|
@ -53,7 +53,7 @@ use hir_def::{
|
||||||
AdtId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, DefWithBodyId, EnumId,
|
AdtId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, DefWithBodyId, EnumId,
|
||||||
EnumVariantId, FunctionId, GenericDefId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
|
EnumVariantId, FunctionId, GenericDefId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
|
||||||
LocalEnumVariantId, LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId,
|
LocalEnumVariantId, LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId,
|
||||||
TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
|
TraitAliasId, TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
|
||||||
};
|
};
|
||||||
use hir_expand::{name::name, MacroCallKind};
|
use hir_expand::{name::name, MacroCallKind};
|
||||||
use hir_ty::{
|
use hir_ty::{
|
||||||
|
@ -272,6 +272,7 @@ pub enum ModuleDef {
|
||||||
Const(Const),
|
Const(Const),
|
||||||
Static(Static),
|
Static(Static),
|
||||||
Trait(Trait),
|
Trait(Trait),
|
||||||
|
TraitAlias(TraitAlias),
|
||||||
TypeAlias(TypeAlias),
|
TypeAlias(TypeAlias),
|
||||||
BuiltinType(BuiltinType),
|
BuiltinType(BuiltinType),
|
||||||
Macro(Macro),
|
Macro(Macro),
|
||||||
|
@ -284,6 +285,7 @@ impl_from!(
|
||||||
Const,
|
Const,
|
||||||
Static,
|
Static,
|
||||||
Trait,
|
Trait,
|
||||||
|
TraitAlias,
|
||||||
TypeAlias,
|
TypeAlias,
|
||||||
BuiltinType,
|
BuiltinType,
|
||||||
Macro
|
Macro
|
||||||
|
@ -310,6 +312,7 @@ impl ModuleDef {
|
||||||
ModuleDef::Const(it) => Some(it.module(db)),
|
ModuleDef::Const(it) => Some(it.module(db)),
|
||||||
ModuleDef::Static(it) => Some(it.module(db)),
|
ModuleDef::Static(it) => Some(it.module(db)),
|
||||||
ModuleDef::Trait(it) => Some(it.module(db)),
|
ModuleDef::Trait(it) => Some(it.module(db)),
|
||||||
|
ModuleDef::TraitAlias(it) => Some(it.module(db)),
|
||||||
ModuleDef::TypeAlias(it) => Some(it.module(db)),
|
ModuleDef::TypeAlias(it) => Some(it.module(db)),
|
||||||
ModuleDef::Macro(it) => Some(it.module(db)),
|
ModuleDef::Macro(it) => Some(it.module(db)),
|
||||||
ModuleDef::BuiltinType(_) => None,
|
ModuleDef::BuiltinType(_) => None,
|
||||||
|
@ -338,6 +341,7 @@ impl ModuleDef {
|
||||||
ModuleDef::Const(it) => it.name(db)?,
|
ModuleDef::Const(it) => it.name(db)?,
|
||||||
ModuleDef::Adt(it) => it.name(db),
|
ModuleDef::Adt(it) => it.name(db),
|
||||||
ModuleDef::Trait(it) => it.name(db),
|
ModuleDef::Trait(it) => it.name(db),
|
||||||
|
ModuleDef::TraitAlias(it) => it.name(db),
|
||||||
ModuleDef::Function(it) => it.name(db),
|
ModuleDef::Function(it) => it.name(db),
|
||||||
ModuleDef::Variant(it) => it.name(db),
|
ModuleDef::Variant(it) => it.name(db),
|
||||||
ModuleDef::TypeAlias(it) => it.name(db),
|
ModuleDef::TypeAlias(it) => it.name(db),
|
||||||
|
@ -356,6 +360,7 @@ impl ModuleDef {
|
||||||
Adt::Union(it) => it.id.into(),
|
Adt::Union(it) => it.id.into(),
|
||||||
},
|
},
|
||||||
ModuleDef::Trait(it) => it.id.into(),
|
ModuleDef::Trait(it) => it.id.into(),
|
||||||
|
ModuleDef::TraitAlias(it) => it.id.into(),
|
||||||
ModuleDef::Function(it) => it.id.into(),
|
ModuleDef::Function(it) => it.id.into(),
|
||||||
ModuleDef::TypeAlias(it) => it.id.into(),
|
ModuleDef::TypeAlias(it) => it.id.into(),
|
||||||
ModuleDef::Module(it) => it.id.into(),
|
ModuleDef::Module(it) => it.id.into(),
|
||||||
|
@ -398,6 +403,7 @@ impl ModuleDef {
|
||||||
ModuleDef::Module(_)
|
ModuleDef::Module(_)
|
||||||
| ModuleDef::Adt(_)
|
| ModuleDef::Adt(_)
|
||||||
| ModuleDef::Trait(_)
|
| ModuleDef::Trait(_)
|
||||||
|
| ModuleDef::TraitAlias(_)
|
||||||
| ModuleDef::TypeAlias(_)
|
| ModuleDef::TypeAlias(_)
|
||||||
| ModuleDef::Macro(_)
|
| ModuleDef::Macro(_)
|
||||||
| ModuleDef::BuiltinType(_) => None,
|
| ModuleDef::BuiltinType(_) => None,
|
||||||
|
@ -413,6 +419,7 @@ impl ModuleDef {
|
||||||
ModuleDef::Const(it) => it.attrs(db),
|
ModuleDef::Const(it) => it.attrs(db),
|
||||||
ModuleDef::Static(it) => it.attrs(db),
|
ModuleDef::Static(it) => it.attrs(db),
|
||||||
ModuleDef::Trait(it) => it.attrs(db),
|
ModuleDef::Trait(it) => it.attrs(db),
|
||||||
|
ModuleDef::TraitAlias(it) => it.attrs(db),
|
||||||
ModuleDef::TypeAlias(it) => it.attrs(db),
|
ModuleDef::TypeAlias(it) => it.attrs(db),
|
||||||
ModuleDef::Macro(it) => it.attrs(db),
|
ModuleDef::Macro(it) => it.attrs(db),
|
||||||
ModuleDef::BuiltinType(_) => return None,
|
ModuleDef::BuiltinType(_) => return None,
|
||||||
|
@ -429,6 +436,7 @@ impl HasVisibility for ModuleDef {
|
||||||
ModuleDef::Const(it) => it.visibility(db),
|
ModuleDef::Const(it) => it.visibility(db),
|
||||||
ModuleDef::Static(it) => it.visibility(db),
|
ModuleDef::Static(it) => it.visibility(db),
|
||||||
ModuleDef::Trait(it) => it.visibility(db),
|
ModuleDef::Trait(it) => it.visibility(db),
|
||||||
|
ModuleDef::TraitAlias(it) => it.visibility(db),
|
||||||
ModuleDef::TypeAlias(it) => it.visibility(db),
|
ModuleDef::TypeAlias(it) => it.visibility(db),
|
||||||
ModuleDef::Variant(it) => it.visibility(db),
|
ModuleDef::Variant(it) => it.visibility(db),
|
||||||
ModuleDef::Macro(it) => it.visibility(db),
|
ModuleDef::Macro(it) => it.visibility(db),
|
||||||
|
@ -1934,6 +1942,27 @@ impl HasVisibility for Trait {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub struct TraitAlias {
|
||||||
|
pub(crate) id: TraitAliasId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TraitAlias {
|
||||||
|
pub fn module(self, db: &dyn HirDatabase) -> Module {
|
||||||
|
Module { id: self.id.lookup(db.upcast()).container }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn name(self, db: &dyn HirDatabase) -> Name {
|
||||||
|
db.trait_alias_data(self.id).name.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HasVisibility for TraitAlias {
|
||||||
|
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
|
||||||
|
db.trait_alias_data(self.id).visibility.resolve(db.upcast(), &self.id.resolver(db.upcast()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct TypeAlias {
|
pub struct TypeAlias {
|
||||||
pub(crate) id: TypeAliasId,
|
pub(crate) id: TypeAliasId,
|
||||||
|
@ -2306,6 +2335,7 @@ pub enum GenericDef {
|
||||||
Function(Function),
|
Function(Function),
|
||||||
Adt(Adt),
|
Adt(Adt),
|
||||||
Trait(Trait),
|
Trait(Trait),
|
||||||
|
TraitAlias(TraitAlias),
|
||||||
TypeAlias(TypeAlias),
|
TypeAlias(TypeAlias),
|
||||||
Impl(Impl),
|
Impl(Impl),
|
||||||
// enum variants cannot have generics themselves, but their parent enums
|
// enum variants cannot have generics themselves, but their parent enums
|
||||||
|
@ -2318,6 +2348,7 @@ impl_from!(
|
||||||
Function,
|
Function,
|
||||||
Adt(Struct, Enum, Union),
|
Adt(Struct, Enum, Union),
|
||||||
Trait,
|
Trait,
|
||||||
|
TraitAlias,
|
||||||
TypeAlias,
|
TypeAlias,
|
||||||
Impl,
|
Impl,
|
||||||
Variant,
|
Variant,
|
||||||
|
@ -4066,6 +4097,12 @@ impl HasCrate for Trait {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasCrate for TraitAlias {
|
||||||
|
fn krate(&self, db: &dyn HirDatabase) -> Crate {
|
||||||
|
self.module(db).krate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl HasCrate for Static {
|
impl HasCrate for Static {
|
||||||
fn krate(&self, db: &dyn HirDatabase) -> Crate {
|
fn krate(&self, db: &dyn HirDatabase) -> Crate {
|
||||||
self.module(db).krate()
|
self.module(db).krate()
|
||||||
|
|
|
@ -68,7 +68,8 @@ impl PathResolution {
|
||||||
| ModuleDef::Function(_)
|
| ModuleDef::Function(_)
|
||||||
| ModuleDef::Module(_)
|
| ModuleDef::Module(_)
|
||||||
| ModuleDef::Static(_)
|
| ModuleDef::Static(_)
|
||||||
| ModuleDef::Trait(_),
|
| ModuleDef::Trait(_)
|
||||||
|
| ModuleDef::TraitAlias(_),
|
||||||
) => None,
|
) => None,
|
||||||
PathResolution::Def(ModuleDef::TypeAlias(alias)) => {
|
PathResolution::Def(ModuleDef::TypeAlias(alias)) => {
|
||||||
Some(TypeNs::TypeAliasId((*alias).into()))
|
Some(TypeNs::TypeAliasId((*alias).into()))
|
||||||
|
@ -1330,6 +1331,7 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ChildContainer::TraitId(it) => it.resolver(self.db.upcast()),
|
ChildContainer::TraitId(it) => it.resolver(self.db.upcast()),
|
||||||
|
ChildContainer::TraitAliasId(it) => it.resolver(self.db.upcast()),
|
||||||
ChildContainer::ImplId(it) => it.resolver(self.db.upcast()),
|
ChildContainer::ImplId(it) => it.resolver(self.db.upcast()),
|
||||||
ChildContainer::ModuleId(it) => it.resolver(self.db.upcast()),
|
ChildContainer::ModuleId(it) => it.resolver(self.db.upcast()),
|
||||||
ChildContainer::EnumId(it) => it.resolver(self.db.upcast()),
|
ChildContainer::EnumId(it) => it.resolver(self.db.upcast()),
|
||||||
|
@ -1556,6 +1558,7 @@ to_def_impls![
|
||||||
(crate::Enum, ast::Enum, enum_to_def),
|
(crate::Enum, ast::Enum, enum_to_def),
|
||||||
(crate::Union, ast::Union, union_to_def),
|
(crate::Union, ast::Union, union_to_def),
|
||||||
(crate::Trait, ast::Trait, trait_to_def),
|
(crate::Trait, ast::Trait, trait_to_def),
|
||||||
|
(crate::TraitAlias, ast::TraitAlias, trait_alias_to_def),
|
||||||
(crate::Impl, ast::Impl, impl_to_def),
|
(crate::Impl, ast::Impl, impl_to_def),
|
||||||
(crate::TypeAlias, ast::TypeAlias, type_alias_to_def),
|
(crate::TypeAlias, ast::TypeAlias, type_alias_to_def),
|
||||||
(crate::Const, ast::Const, const_to_def),
|
(crate::Const, ast::Const, const_to_def),
|
||||||
|
|
|
@ -93,7 +93,7 @@ use hir_def::{
|
||||||
keys::{self, Key},
|
keys::{self, Key},
|
||||||
AdtId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId,
|
AdtId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId,
|
||||||
GenericDefId, GenericParamId, ImplId, LifetimeParamId, MacroId, ModuleId, StaticId, StructId,
|
GenericDefId, GenericParamId, ImplId, LifetimeParamId, MacroId, ModuleId, StaticId, StructId,
|
||||||
TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
|
TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
|
||||||
};
|
};
|
||||||
use hir_expand::{attrs::AttrId, name::AsName, HirFileId, MacroCallId};
|
use hir_expand::{attrs::AttrId, name::AsName, HirFileId, MacroCallId};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
@ -159,6 +159,12 @@ impl SourceToDefCtx<'_, '_> {
|
||||||
pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> {
|
pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> {
|
||||||
self.to_def(src, keys::TRAIT)
|
self.to_def(src, keys::TRAIT)
|
||||||
}
|
}
|
||||||
|
pub(super) fn trait_alias_to_def(
|
||||||
|
&mut self,
|
||||||
|
src: InFile<ast::TraitAlias>,
|
||||||
|
) -> Option<TraitAliasId> {
|
||||||
|
self.to_def(src, keys::TRAIT_ALIAS)
|
||||||
|
}
|
||||||
pub(super) fn impl_to_def(&mut self, src: InFile<ast::Impl>) -> Option<ImplId> {
|
pub(super) fn impl_to_def(&mut self, src: InFile<ast::Impl>) -> Option<ImplId> {
|
||||||
self.to_def(src, keys::IMPL)
|
self.to_def(src, keys::IMPL)
|
||||||
}
|
}
|
||||||
|
@ -353,6 +359,9 @@ impl SourceToDefCtx<'_, '_> {
|
||||||
match item {
|
match item {
|
||||||
ast::Item::Module(it) => self.module_to_def(container.with_value(it))?.into(),
|
ast::Item::Module(it) => self.module_to_def(container.with_value(it))?.into(),
|
||||||
ast::Item::Trait(it) => self.trait_to_def(container.with_value(it))?.into(),
|
ast::Item::Trait(it) => self.trait_to_def(container.with_value(it))?.into(),
|
||||||
|
ast::Item::TraitAlias(it) => {
|
||||||
|
self.trait_alias_to_def(container.with_value(it))?.into()
|
||||||
|
}
|
||||||
ast::Item::Impl(it) => self.impl_to_def(container.with_value(it))?.into(),
|
ast::Item::Impl(it) => self.impl_to_def(container.with_value(it))?.into(),
|
||||||
ast::Item::Enum(it) => self.enum_to_def(container.with_value(it))?.into(),
|
ast::Item::Enum(it) => self.enum_to_def(container.with_value(it))?.into(),
|
||||||
ast::Item::TypeAlias(it) => {
|
ast::Item::TypeAlias(it) => {
|
||||||
|
@ -400,6 +409,9 @@ impl SourceToDefCtx<'_, '_> {
|
||||||
ast::Item::Struct(it) => self.struct_to_def(InFile::new(file_id, it))?.into(),
|
ast::Item::Struct(it) => self.struct_to_def(InFile::new(file_id, it))?.into(),
|
||||||
ast::Item::Enum(it) => self.enum_to_def(InFile::new(file_id, it))?.into(),
|
ast::Item::Enum(it) => self.enum_to_def(InFile::new(file_id, it))?.into(),
|
||||||
ast::Item::Trait(it) => self.trait_to_def(InFile::new(file_id, it))?.into(),
|
ast::Item::Trait(it) => self.trait_to_def(InFile::new(file_id, it))?.into(),
|
||||||
|
ast::Item::TraitAlias(it) => {
|
||||||
|
self.trait_alias_to_def(InFile::new(file_id, it))?.into()
|
||||||
|
}
|
||||||
ast::Item::TypeAlias(it) => {
|
ast::Item::TypeAlias(it) => {
|
||||||
self.type_alias_to_def(InFile::new(file_id, it))?.into()
|
self.type_alias_to_def(InFile::new(file_id, it))?.into()
|
||||||
}
|
}
|
||||||
|
@ -435,6 +447,7 @@ pub(crate) enum ChildContainer {
|
||||||
DefWithBodyId(DefWithBodyId),
|
DefWithBodyId(DefWithBodyId),
|
||||||
ModuleId(ModuleId),
|
ModuleId(ModuleId),
|
||||||
TraitId(TraitId),
|
TraitId(TraitId),
|
||||||
|
TraitAliasId(TraitAliasId),
|
||||||
ImplId(ImplId),
|
ImplId(ImplId),
|
||||||
EnumId(EnumId),
|
EnumId(EnumId),
|
||||||
VariantId(VariantId),
|
VariantId(VariantId),
|
||||||
|
@ -447,6 +460,7 @@ impl_from! {
|
||||||
DefWithBodyId,
|
DefWithBodyId,
|
||||||
ModuleId,
|
ModuleId,
|
||||||
TraitId,
|
TraitId,
|
||||||
|
TraitAliasId,
|
||||||
ImplId,
|
ImplId,
|
||||||
EnumId,
|
EnumId,
|
||||||
VariantId,
|
VariantId,
|
||||||
|
@ -462,6 +476,7 @@ impl ChildContainer {
|
||||||
ChildContainer::DefWithBodyId(it) => it.child_by_source(db, file_id),
|
ChildContainer::DefWithBodyId(it) => it.child_by_source(db, file_id),
|
||||||
ChildContainer::ModuleId(it) => it.child_by_source(db, file_id),
|
ChildContainer::ModuleId(it) => it.child_by_source(db, file_id),
|
||||||
ChildContainer::TraitId(it) => it.child_by_source(db, file_id),
|
ChildContainer::TraitId(it) => it.child_by_source(db, file_id),
|
||||||
|
ChildContainer::TraitAliasId(_) => DynMap::default(),
|
||||||
ChildContainer::ImplId(it) => it.child_by_source(db, file_id),
|
ChildContainer::ImplId(it) => it.child_by_source(db, file_id),
|
||||||
ChildContainer::EnumId(it) => it.child_by_source(db, file_id),
|
ChildContainer::EnumId(it) => it.child_by_source(db, file_id),
|
||||||
ChildContainer::VariantId(it) => it.child_by_source(db, file_id),
|
ChildContainer::VariantId(it) => it.child_by_source(db, file_id),
|
||||||
|
|
|
@ -51,7 +51,7 @@ use syntax::{
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, semantics::PathResolution, Adt, AssocItem, BindingMode, BuiltinAttr,
|
db::HirDatabase, semantics::PathResolution, Adt, AssocItem, BindingMode, BuiltinAttr,
|
||||||
BuiltinType, Callable, Const, DeriveHelper, Field, Function, Local, Macro, ModuleDef, Static,
|
BuiltinType, Callable, Const, DeriveHelper, Field, Function, Local, Macro, ModuleDef, Static,
|
||||||
Struct, ToolModule, Trait, Type, TypeAlias, Variant,
|
Struct, ToolModule, Trait, TraitAlias, Type, TypeAlias, Variant,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
|
/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
|
||||||
|
@ -978,6 +978,7 @@ fn resolve_hir_path_(
|
||||||
TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
|
TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
|
||||||
TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()),
|
TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()),
|
||||||
TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
|
TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
|
||||||
|
TypeNs::TraitAliasId(it) => PathResolution::Def(TraitAlias::from(it).into()),
|
||||||
};
|
};
|
||||||
match unresolved {
|
match unresolved {
|
||||||
Some(unresolved) => resolver
|
Some(unresolved) => resolver
|
||||||
|
@ -1065,6 +1066,7 @@ fn resolve_hir_path_qualifier(
|
||||||
TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
|
TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
|
||||||
TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()),
|
TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()),
|
||||||
TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
|
TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
|
||||||
|
TypeNs::TraitAliasId(it) => PathResolution::Def(TraitAlias::from(it).into()),
|
||||||
})
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
resolver
|
resolver
|
||||||
|
|
|
@ -68,6 +68,7 @@ pub enum FileSymbolKind {
|
||||||
Static,
|
Static,
|
||||||
Struct,
|
Struct,
|
||||||
Trait,
|
Trait,
|
||||||
|
TraitAlias,
|
||||||
TypeAlias,
|
TypeAlias,
|
||||||
Union,
|
Union,
|
||||||
}
|
}
|
||||||
|
@ -153,6 +154,9 @@ impl<'a> SymbolCollector<'a> {
|
||||||
self.push_decl(id, FileSymbolKind::Trait);
|
self.push_decl(id, FileSymbolKind::Trait);
|
||||||
self.collect_from_trait(id);
|
self.collect_from_trait(id);
|
||||||
}
|
}
|
||||||
|
ModuleDefId::TraitAliasId(id) => {
|
||||||
|
self.push_decl(id, FileSymbolKind::TraitAlias);
|
||||||
|
}
|
||||||
ModuleDefId::TypeAliasId(id) => {
|
ModuleDefId::TypeAliasId(id) => {
|
||||||
self.push_decl_assoc(id, FileSymbolKind::TypeAlias);
|
self.push_decl_assoc(id, FileSymbolKind::TypeAlias);
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,6 +192,10 @@ fn target_data_for_def(
|
||||||
target_name = Some(t.name(db));
|
target_name = Some(t.name(db));
|
||||||
offset_target_and_file_id(db, t)?
|
offset_target_and_file_id(db, t)?
|
||||||
}
|
}
|
||||||
|
hir::ModuleDef::TraitAlias(t) => {
|
||||||
|
target_name = Some(t.name(db));
|
||||||
|
offset_target_and_file_id(db, t)?
|
||||||
|
}
|
||||||
hir::ModuleDef::TypeAlias(t) => {
|
hir::ModuleDef::TypeAlias(t) => {
|
||||||
target_name = Some(t.name(db));
|
target_name = Some(t.name(db));
|
||||||
offset_target_and_file_id(db, t)?
|
offset_target_and_file_id(db, t)?
|
||||||
|
|
|
@ -33,7 +33,9 @@ pub(crate) fn complete_type_path(
|
||||||
// Don't suggest attribute macros and derives.
|
// Don't suggest attribute macros and derives.
|
||||||
ScopeDef::ModuleDef(Macro(mac)) => mac.is_fn_like(ctx.db),
|
ScopeDef::ModuleDef(Macro(mac)) => mac.is_fn_like(ctx.db),
|
||||||
// Type things are fine
|
// Type things are fine
|
||||||
ScopeDef::ModuleDef(BuiltinType(_) | Adt(_) | Module(_) | Trait(_) | TypeAlias(_))
|
ScopeDef::ModuleDef(
|
||||||
|
BuiltinType(_) | Adt(_) | Module(_) | Trait(_) | TraitAlias(_) | TypeAlias(_),
|
||||||
|
)
|
||||||
| ScopeDef::AdtSelfType(_)
|
| ScopeDef::AdtSelfType(_)
|
||||||
| ScopeDef::Unknown
|
| ScopeDef::Unknown
|
||||||
| ScopeDef::GenericParam(TypeParam(_)) => true,
|
| ScopeDef::GenericParam(TypeParam(_)) => true,
|
||||||
|
|
|
@ -416,6 +416,7 @@ impl<'a> CompletionContext<'a> {
|
||||||
hir::ModuleDef::Const(it) => self.is_visible(it),
|
hir::ModuleDef::Const(it) => self.is_visible(it),
|
||||||
hir::ModuleDef::Static(it) => self.is_visible(it),
|
hir::ModuleDef::Static(it) => self.is_visible(it),
|
||||||
hir::ModuleDef::Trait(it) => self.is_visible(it),
|
hir::ModuleDef::Trait(it) => self.is_visible(it),
|
||||||
|
hir::ModuleDef::TraitAlias(it) => self.is_visible(it),
|
||||||
hir::ModuleDef::TypeAlias(it) => self.is_visible(it),
|
hir::ModuleDef::TypeAlias(it) => self.is_visible(it),
|
||||||
hir::ModuleDef::Macro(it) => self.is_visible(it),
|
hir::ModuleDef::Macro(it) => self.is_visible(it),
|
||||||
hir::ModuleDef::BuiltinType(_) => Visible::Yes,
|
hir::ModuleDef::BuiltinType(_) => Visible::Yes,
|
||||||
|
|
|
@ -288,7 +288,7 @@ impl_from!(SymbolKind for CompletionItemKind);
|
||||||
|
|
||||||
impl CompletionItemKind {
|
impl CompletionItemKind {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn tag(&self) -> &'static str {
|
pub(crate) fn tag(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
CompletionItemKind::SymbolKind(kind) => match kind {
|
CompletionItemKind::SymbolKind(kind) => match kind {
|
||||||
SymbolKind::Attribute => "at",
|
SymbolKind::Attribute => "at",
|
||||||
|
@ -312,6 +312,7 @@ impl CompletionItemKind {
|
||||||
SymbolKind::Struct => "st",
|
SymbolKind::Struct => "st",
|
||||||
SymbolKind::ToolModule => "tm",
|
SymbolKind::ToolModule => "tm",
|
||||||
SymbolKind::Trait => "tt",
|
SymbolKind::Trait => "tt",
|
||||||
|
SymbolKind::TraitAlias => "tr",
|
||||||
SymbolKind::TypeAlias => "ta",
|
SymbolKind::TypeAlias => "ta",
|
||||||
SymbolKind::TypeParam => "tp",
|
SymbolKind::TypeParam => "tp",
|
||||||
SymbolKind::Union => "un",
|
SymbolKind::Union => "un",
|
||||||
|
|
|
@ -367,6 +367,9 @@ fn res_to_kind(resolution: ScopeDef) -> CompletionItemKind {
|
||||||
ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::SymbolKind(SymbolKind::Const),
|
ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::SymbolKind(SymbolKind::Const),
|
||||||
ScopeDef::ModuleDef(Static(..)) => CompletionItemKind::SymbolKind(SymbolKind::Static),
|
ScopeDef::ModuleDef(Static(..)) => CompletionItemKind::SymbolKind(SymbolKind::Static),
|
||||||
ScopeDef::ModuleDef(Trait(..)) => CompletionItemKind::SymbolKind(SymbolKind::Trait),
|
ScopeDef::ModuleDef(Trait(..)) => CompletionItemKind::SymbolKind(SymbolKind::Trait),
|
||||||
|
ScopeDef::ModuleDef(TraitAlias(..)) => {
|
||||||
|
CompletionItemKind::SymbolKind(SymbolKind::TraitAlias)
|
||||||
|
}
|
||||||
ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::SymbolKind(SymbolKind::TypeAlias),
|
ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::SymbolKind(SymbolKind::TypeAlias),
|
||||||
ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
|
ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
|
||||||
ScopeDef::GenericParam(param) => CompletionItemKind::SymbolKind(match param {
|
ScopeDef::GenericParam(param) => CompletionItemKind::SymbolKind(match param {
|
||||||
|
|
|
@ -96,6 +96,7 @@ pub fn generic_def_for_node(
|
||||||
hir::PathResolution::Def(hir::ModuleDef::Adt(it)) => it.into(),
|
hir::PathResolution::Def(hir::ModuleDef::Adt(it)) => it.into(),
|
||||||
hir::PathResolution::Def(hir::ModuleDef::Function(it)) => it.into(),
|
hir::PathResolution::Def(hir::ModuleDef::Function(it)) => it.into(),
|
||||||
hir::PathResolution::Def(hir::ModuleDef::Trait(it)) => it.into(),
|
hir::PathResolution::Def(hir::ModuleDef::Trait(it)) => it.into(),
|
||||||
|
hir::PathResolution::Def(hir::ModuleDef::TraitAlias(it)) => it.into(),
|
||||||
hir::PathResolution::Def(hir::ModuleDef::TypeAlias(it)) => it.into(),
|
hir::PathResolution::Def(hir::ModuleDef::TypeAlias(it)) => it.into(),
|
||||||
hir::PathResolution::Def(hir::ModuleDef::Variant(it)) => it.into(),
|
hir::PathResolution::Def(hir::ModuleDef::Variant(it)) => it.into(),
|
||||||
hir::PathResolution::Def(hir::ModuleDef::BuiltinType(_))
|
hir::PathResolution::Def(hir::ModuleDef::BuiltinType(_))
|
||||||
|
|
|
@ -9,7 +9,8 @@ use arrayvec::ArrayVec;
|
||||||
use hir::{
|
use hir::{
|
||||||
Adt, AsAssocItem, AssocItem, BuiltinAttr, BuiltinType, Const, Crate, DeriveHelper, Field,
|
Adt, AsAssocItem, AssocItem, BuiltinAttr, BuiltinType, Const, Crate, DeriveHelper, Field,
|
||||||
Function, GenericParam, HasVisibility, Impl, ItemInNs, Label, Local, Macro, Module, ModuleDef,
|
Function, GenericParam, HasVisibility, Impl, ItemInNs, Label, Local, Macro, Module, ModuleDef,
|
||||||
Name, PathResolution, Semantics, Static, ToolModule, Trait, TypeAlias, Variant, Visibility,
|
Name, PathResolution, Semantics, Static, ToolModule, Trait, TraitAlias, TypeAlias, Variant,
|
||||||
|
Visibility,
|
||||||
};
|
};
|
||||||
use stdx::impl_from;
|
use stdx::impl_from;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
|
@ -31,6 +32,7 @@ pub enum Definition {
|
||||||
Const(Const),
|
Const(Const),
|
||||||
Static(Static),
|
Static(Static),
|
||||||
Trait(Trait),
|
Trait(Trait),
|
||||||
|
TraitAlias(TraitAlias),
|
||||||
TypeAlias(TypeAlias),
|
TypeAlias(TypeAlias),
|
||||||
BuiltinType(BuiltinType),
|
BuiltinType(BuiltinType),
|
||||||
SelfType(Impl),
|
SelfType(Impl),
|
||||||
|
@ -64,6 +66,7 @@ impl Definition {
|
||||||
Definition::Const(it) => it.module(db),
|
Definition::Const(it) => it.module(db),
|
||||||
Definition::Static(it) => it.module(db),
|
Definition::Static(it) => it.module(db),
|
||||||
Definition::Trait(it) => it.module(db),
|
Definition::Trait(it) => it.module(db),
|
||||||
|
Definition::TraitAlias(it) => it.module(db),
|
||||||
Definition::TypeAlias(it) => it.module(db),
|
Definition::TypeAlias(it) => it.module(db),
|
||||||
Definition::Variant(it) => it.module(db),
|
Definition::Variant(it) => it.module(db),
|
||||||
Definition::SelfType(it) => it.module(db),
|
Definition::SelfType(it) => it.module(db),
|
||||||
|
@ -87,6 +90,7 @@ impl Definition {
|
||||||
Definition::Const(it) => it.visibility(db),
|
Definition::Const(it) => it.visibility(db),
|
||||||
Definition::Static(it) => it.visibility(db),
|
Definition::Static(it) => it.visibility(db),
|
||||||
Definition::Trait(it) => it.visibility(db),
|
Definition::Trait(it) => it.visibility(db),
|
||||||
|
Definition::TraitAlias(it) => it.visibility(db),
|
||||||
Definition::TypeAlias(it) => it.visibility(db),
|
Definition::TypeAlias(it) => it.visibility(db),
|
||||||
Definition::Variant(it) => it.visibility(db),
|
Definition::Variant(it) => it.visibility(db),
|
||||||
Definition::BuiltinType(_) => Visibility::Public,
|
Definition::BuiltinType(_) => Visibility::Public,
|
||||||
|
@ -113,6 +117,7 @@ impl Definition {
|
||||||
Definition::Const(it) => it.name(db)?,
|
Definition::Const(it) => it.name(db)?,
|
||||||
Definition::Static(it) => it.name(db),
|
Definition::Static(it) => it.name(db),
|
||||||
Definition::Trait(it) => it.name(db),
|
Definition::Trait(it) => it.name(db),
|
||||||
|
Definition::TraitAlias(it) => it.name(db),
|
||||||
Definition::TypeAlias(it) => it.name(db),
|
Definition::TypeAlias(it) => it.name(db),
|
||||||
Definition::BuiltinType(it) => it.name(),
|
Definition::BuiltinType(it) => it.name(),
|
||||||
Definition::SelfType(_) => return None,
|
Definition::SelfType(_) => return None,
|
||||||
|
@ -300,6 +305,7 @@ impl NameClass {
|
||||||
ast::Item::Module(it) => Definition::Module(sema.to_def(&it)?),
|
ast::Item::Module(it) => Definition::Module(sema.to_def(&it)?),
|
||||||
ast::Item::Static(it) => Definition::Static(sema.to_def(&it)?),
|
ast::Item::Static(it) => Definition::Static(sema.to_def(&it)?),
|
||||||
ast::Item::Trait(it) => Definition::Trait(sema.to_def(&it)?),
|
ast::Item::Trait(it) => Definition::Trait(sema.to_def(&it)?),
|
||||||
|
ast::Item::TraitAlias(it) => Definition::TraitAlias(sema.to_def(&it)?),
|
||||||
ast::Item::TypeAlias(it) => Definition::TypeAlias(sema.to_def(&it)?),
|
ast::Item::TypeAlias(it) => Definition::TypeAlias(sema.to_def(&it)?),
|
||||||
ast::Item::Enum(it) => Definition::Adt(hir::Adt::Enum(sema.to_def(&it)?)),
|
ast::Item::Enum(it) => Definition::Adt(hir::Adt::Enum(sema.to_def(&it)?)),
|
||||||
ast::Item::Struct(it) => Definition::Adt(hir::Adt::Struct(sema.to_def(&it)?)),
|
ast::Item::Struct(it) => Definition::Adt(hir::Adt::Struct(sema.to_def(&it)?)),
|
||||||
|
@ -542,7 +548,7 @@ impl NameRefClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_from!(
|
impl_from!(
|
||||||
Field, Module, Function, Adt, Variant, Const, Static, Trait, TypeAlias, BuiltinType, Local,
|
Field, Module, Function, Adt, Variant, Const, Static, Trait, TraitAlias, TypeAlias, BuiltinType, Local,
|
||||||
GenericParam, Label, Macro
|
GenericParam, Label, Macro
|
||||||
for Definition
|
for Definition
|
||||||
);
|
);
|
||||||
|
@ -599,6 +605,7 @@ impl From<ModuleDef> for Definition {
|
||||||
ModuleDef::Const(it) => Definition::Const(it),
|
ModuleDef::Const(it) => Definition::Const(it),
|
||||||
ModuleDef::Static(it) => Definition::Static(it),
|
ModuleDef::Static(it) => Definition::Static(it),
|
||||||
ModuleDef::Trait(it) => Definition::Trait(it),
|
ModuleDef::Trait(it) => Definition::Trait(it),
|
||||||
|
ModuleDef::TraitAlias(it) => Definition::TraitAlias(it),
|
||||||
ModuleDef::TypeAlias(it) => Definition::TypeAlias(it),
|
ModuleDef::TypeAlias(it) => Definition::TypeAlias(it),
|
||||||
ModuleDef::Macro(it) => Definition::Macro(it),
|
ModuleDef::Macro(it) => Definition::Macro(it),
|
||||||
ModuleDef::BuiltinType(it) => Definition::BuiltinType(it),
|
ModuleDef::BuiltinType(it) => Definition::BuiltinType(it),
|
||||||
|
@ -616,6 +623,7 @@ impl From<Definition> for Option<ItemInNs> {
|
||||||
Definition::Const(it) => ModuleDef::Const(it),
|
Definition::Const(it) => ModuleDef::Const(it),
|
||||||
Definition::Static(it) => ModuleDef::Static(it),
|
Definition::Static(it) => ModuleDef::Static(it),
|
||||||
Definition::Trait(it) => ModuleDef::Trait(it),
|
Definition::Trait(it) => ModuleDef::Trait(it),
|
||||||
|
Definition::TraitAlias(it) => ModuleDef::TraitAlias(it),
|
||||||
Definition::TypeAlias(it) => ModuleDef::TypeAlias(it),
|
Definition::TypeAlias(it) => ModuleDef::TypeAlias(it),
|
||||||
Definition::BuiltinType(it) => ModuleDef::BuiltinType(it),
|
Definition::BuiltinType(it) => ModuleDef::BuiltinType(it),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
|
|
|
@ -191,6 +191,7 @@ pub enum SymbolKind {
|
||||||
Struct,
|
Struct,
|
||||||
ToolModule,
|
ToolModule,
|
||||||
Trait,
|
Trait,
|
||||||
|
TraitAlias,
|
||||||
TypeAlias,
|
TypeAlias,
|
||||||
TypeParam,
|
TypeParam,
|
||||||
Union,
|
Union,
|
||||||
|
@ -221,6 +222,7 @@ impl From<FileSymbolKind> for SymbolKind {
|
||||||
FileSymbolKind::Static => SymbolKind::Static,
|
FileSymbolKind::Static => SymbolKind::Static,
|
||||||
FileSymbolKind::Struct => SymbolKind::Struct,
|
FileSymbolKind::Struct => SymbolKind::Struct,
|
||||||
FileSymbolKind::Trait => SymbolKind::Trait,
|
FileSymbolKind::Trait => SymbolKind::Trait,
|
||||||
|
FileSymbolKind::TraitAlias => SymbolKind::TraitAlias,
|
||||||
FileSymbolKind::TypeAlias => SymbolKind::TypeAlias,
|
FileSymbolKind::TypeAlias => SymbolKind::TypeAlias,
|
||||||
FileSymbolKind::Union => SymbolKind::Union,
|
FileSymbolKind::Union => SymbolKind::Union,
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,7 @@ impl Definition {
|
||||||
Definition::Const(it) => name_range(it, sema),
|
Definition::Const(it) => name_range(it, sema),
|
||||||
Definition::Static(it) => name_range(it, sema),
|
Definition::Static(it) => name_range(it, sema),
|
||||||
Definition::Trait(it) => name_range(it, sema),
|
Definition::Trait(it) => name_range(it, sema),
|
||||||
|
Definition::TraitAlias(it) => name_range(it, sema),
|
||||||
Definition::TypeAlias(it) => name_range(it, sema),
|
Definition::TypeAlias(it) => name_range(it, sema),
|
||||||
Definition::Local(local) => {
|
Definition::Local(local) => {
|
||||||
let src = local.source(sema.db);
|
let src = local.source(sema.db);
|
||||||
|
|
|
@ -261,6 +261,7 @@ impl Definition {
|
||||||
hir::GenericDef::Function(it) => it.source(db).map(|src| src.syntax().cloned()),
|
hir::GenericDef::Function(it) => it.source(db).map(|src| src.syntax().cloned()),
|
||||||
hir::GenericDef::Adt(it) => it.source(db).map(|src| src.syntax().cloned()),
|
hir::GenericDef::Adt(it) => it.source(db).map(|src| src.syntax().cloned()),
|
||||||
hir::GenericDef::Trait(it) => it.source(db).map(|src| src.syntax().cloned()),
|
hir::GenericDef::Trait(it) => it.source(db).map(|src| src.syntax().cloned()),
|
||||||
|
hir::GenericDef::TraitAlias(it) => it.source(db).map(|src| src.syntax().cloned()),
|
||||||
hir::GenericDef::TypeAlias(it) => it.source(db).map(|src| src.syntax().cloned()),
|
hir::GenericDef::TypeAlias(it) => it.source(db).map(|src| src.syntax().cloned()),
|
||||||
hir::GenericDef::Impl(it) => it.source(db).map(|src| src.syntax().cloned()),
|
hir::GenericDef::Impl(it) => it.source(db).map(|src| src.syntax().cloned()),
|
||||||
hir::GenericDef::Variant(it) => it.source(db).map(|src| src.syntax().cloned()),
|
hir::GenericDef::Variant(it) => it.source(db).map(|src| src.syntax().cloned()),
|
||||||
|
|
|
@ -192,6 +192,7 @@ pub(crate) fn resolve_doc_path_for_def(
|
||||||
Definition::Const(it) => it.resolve_doc_path(db, link, ns),
|
Definition::Const(it) => it.resolve_doc_path(db, link, ns),
|
||||||
Definition::Static(it) => it.resolve_doc_path(db, link, ns),
|
Definition::Static(it) => it.resolve_doc_path(db, link, ns),
|
||||||
Definition::Trait(it) => it.resolve_doc_path(db, link, ns),
|
Definition::Trait(it) => it.resolve_doc_path(db, link, ns),
|
||||||
|
Definition::TraitAlias(it) => it.resolve_doc_path(db, link, ns),
|
||||||
Definition::TypeAlias(it) => it.resolve_doc_path(db, link, ns),
|
Definition::TypeAlias(it) => it.resolve_doc_path(db, link, ns),
|
||||||
Definition::Macro(it) => it.resolve_doc_path(db, link, ns),
|
Definition::Macro(it) => it.resolve_doc_path(db, link, ns),
|
||||||
Definition::Field(it) => it.resolve_doc_path(db, link, ns),
|
Definition::Field(it) => it.resolve_doc_path(db, link, ns),
|
||||||
|
@ -504,6 +505,7 @@ fn filename_and_frag_for_def(
|
||||||
None => String::from("index.html"),
|
None => String::from("index.html"),
|
||||||
},
|
},
|
||||||
Definition::Trait(t) => format!("trait.{}.html", t.name(db)),
|
Definition::Trait(t) => format!("trait.{}.html", t.name(db)),
|
||||||
|
Definition::TraitAlias(t) => format!("traitalias.{}.html", t.name(db)),
|
||||||
Definition::TypeAlias(t) => format!("type.{}.html", t.name(db)),
|
Definition::TypeAlias(t) => format!("type.{}.html", t.name(db)),
|
||||||
Definition::BuiltinType(t) => format!("primitive.{}.html", t.name()),
|
Definition::BuiltinType(t) => format!("primitive.{}.html", t.name()),
|
||||||
Definition::Function(f) => format!("fn.{}.html", f.name(db)),
|
Definition::Function(f) => format!("fn.{}.html", f.name(db)),
|
||||||
|
|
|
@ -454,6 +454,7 @@ pub(super) fn definition(
|
||||||
Some(body.to_string())
|
Some(body.to_string())
|
||||||
}),
|
}),
|
||||||
Definition::Trait(it) => label_and_docs(db, it),
|
Definition::Trait(it) => label_and_docs(db, it),
|
||||||
|
Definition::TraitAlias(it) => label_and_docs(db, it),
|
||||||
Definition::TypeAlias(it) => label_and_docs(db, it),
|
Definition::TypeAlias(it) => label_and_docs(db, it),
|
||||||
Definition::BuiltinType(it) => {
|
Definition::BuiltinType(it) => {
|
||||||
return famous_defs
|
return famous_defs
|
||||||
|
|
|
@ -208,6 +208,9 @@ pub(crate) fn def_to_moniker(
|
||||||
Definition::Trait(trait_) => {
|
Definition::Trait(trait_) => {
|
||||||
MonikerDescriptor { name: trait_.name(db), desc: MonikerDescriptorKind::Type }
|
MonikerDescriptor { name: trait_.name(db), desc: MonikerDescriptorKind::Type }
|
||||||
}
|
}
|
||||||
|
Definition::TraitAlias(ta) => {
|
||||||
|
MonikerDescriptor { name: ta.name(db), desc: MonikerDescriptorKind::Type }
|
||||||
|
}
|
||||||
Definition::TypeAlias(ta) => {
|
Definition::TypeAlias(ta) => {
|
||||||
MonikerDescriptor { name: ta.name(db), desc: MonikerDescriptorKind::TypeParameter }
|
MonikerDescriptor { name: ta.name(db), desc: MonikerDescriptorKind::TypeParameter }
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,6 +192,7 @@ impl TryToNav for Definition {
|
||||||
Definition::Const(it) => it.try_to_nav(db),
|
Definition::Const(it) => it.try_to_nav(db),
|
||||||
Definition::Static(it) => it.try_to_nav(db),
|
Definition::Static(it) => it.try_to_nav(db),
|
||||||
Definition::Trait(it) => it.try_to_nav(db),
|
Definition::Trait(it) => it.try_to_nav(db),
|
||||||
|
Definition::TraitAlias(it) => it.try_to_nav(db),
|
||||||
Definition::TypeAlias(it) => it.try_to_nav(db),
|
Definition::TypeAlias(it) => it.try_to_nav(db),
|
||||||
Definition::BuiltinType(_) => None,
|
Definition::BuiltinType(_) => None,
|
||||||
Definition::ToolModule(_) => None,
|
Definition::ToolModule(_) => None,
|
||||||
|
@ -212,6 +213,7 @@ impl TryToNav for hir::ModuleDef {
|
||||||
hir::ModuleDef::Const(it) => it.try_to_nav(db),
|
hir::ModuleDef::Const(it) => it.try_to_nav(db),
|
||||||
hir::ModuleDef::Static(it) => it.try_to_nav(db),
|
hir::ModuleDef::Static(it) => it.try_to_nav(db),
|
||||||
hir::ModuleDef::Trait(it) => it.try_to_nav(db),
|
hir::ModuleDef::Trait(it) => it.try_to_nav(db),
|
||||||
|
hir::ModuleDef::TraitAlias(it) => it.try_to_nav(db),
|
||||||
hir::ModuleDef::TypeAlias(it) => it.try_to_nav(db),
|
hir::ModuleDef::TypeAlias(it) => it.try_to_nav(db),
|
||||||
hir::ModuleDef::Macro(it) => it.try_to_nav(db),
|
hir::ModuleDef::Macro(it) => it.try_to_nav(db),
|
||||||
hir::ModuleDef::BuiltinType(_) => None,
|
hir::ModuleDef::BuiltinType(_) => None,
|
||||||
|
@ -249,6 +251,9 @@ impl ToNavFromAst for hir::TypeAlias {
|
||||||
impl ToNavFromAst for hir::Trait {
|
impl ToNavFromAst for hir::Trait {
|
||||||
const KIND: SymbolKind = SymbolKind::Trait;
|
const KIND: SymbolKind = SymbolKind::Trait;
|
||||||
}
|
}
|
||||||
|
impl ToNavFromAst for hir::TraitAlias {
|
||||||
|
const KIND: SymbolKind = SymbolKind::TraitAlias;
|
||||||
|
}
|
||||||
|
|
||||||
impl<D> TryToNav for D
|
impl<D> TryToNav for D
|
||||||
where
|
where
|
||||||
|
|
|
@ -252,6 +252,10 @@ fn signature_help_for_generics(
|
||||||
res.doc = it.docs(db).map(|it| it.into());
|
res.doc = it.docs(db).map(|it| it.into());
|
||||||
format_to!(res.signature, "trait {}", it.name(db));
|
format_to!(res.signature, "trait {}", it.name(db));
|
||||||
}
|
}
|
||||||
|
hir::GenericDef::TraitAlias(it) => {
|
||||||
|
res.doc = it.docs(db).map(|it| it.into());
|
||||||
|
format_to!(res.signature, "trait {}", it.name(db));
|
||||||
|
}
|
||||||
hir::GenericDef::TypeAlias(it) => {
|
hir::GenericDef::TypeAlias(it) => {
|
||||||
res.doc = it.docs(db).map(|it| it.into());
|
res.doc = it.docs(db).map(|it| it.into());
|
||||||
format_to!(res.signature, "type {}", it.name(db));
|
format_to!(res.signature, "type {}", it.name(db));
|
||||||
|
|
|
@ -410,6 +410,7 @@ fn highlight_def(
|
||||||
h
|
h
|
||||||
}
|
}
|
||||||
Definition::Trait(_) => Highlight::new(HlTag::Symbol(SymbolKind::Trait)),
|
Definition::Trait(_) => Highlight::new(HlTag::Symbol(SymbolKind::Trait)),
|
||||||
|
Definition::TraitAlias(_) => Highlight::new(HlTag::Symbol(SymbolKind::TraitAlias)),
|
||||||
Definition::TypeAlias(type_) => {
|
Definition::TypeAlias(type_) => {
|
||||||
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias));
|
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias));
|
||||||
|
|
||||||
|
|
|
@ -274,6 +274,7 @@ fn module_def_to_hl_tag(def: Definition) -> HlTag {
|
||||||
Definition::Const(_) => SymbolKind::Const,
|
Definition::Const(_) => SymbolKind::Const,
|
||||||
Definition::Static(_) => SymbolKind::Static,
|
Definition::Static(_) => SymbolKind::Static,
|
||||||
Definition::Trait(_) => SymbolKind::Trait,
|
Definition::Trait(_) => SymbolKind::Trait,
|
||||||
|
Definition::TraitAlias(_) => SymbolKind::TraitAlias,
|
||||||
Definition::TypeAlias(_) => SymbolKind::TypeAlias,
|
Definition::TypeAlias(_) => SymbolKind::TypeAlias,
|
||||||
Definition::BuiltinType(_) => return HlTag::BuiltinType,
|
Definition::BuiltinType(_) => return HlTag::BuiltinType,
|
||||||
Definition::Macro(_) => SymbolKind::Macro,
|
Definition::Macro(_) => SymbolKind::Macro,
|
||||||
|
|
|
@ -150,6 +150,7 @@ impl HlTag {
|
||||||
SymbolKind::Struct => "struct",
|
SymbolKind::Struct => "struct",
|
||||||
SymbolKind::ToolModule => "tool_module",
|
SymbolKind::ToolModule => "tool_module",
|
||||||
SymbolKind::Trait => "trait",
|
SymbolKind::Trait => "trait",
|
||||||
|
SymbolKind::TraitAlias => "trait_alias",
|
||||||
SymbolKind::TypeAlias => "type_alias",
|
SymbolKind::TypeAlias => "type_alias",
|
||||||
SymbolKind::TypeParam => "type_param",
|
SymbolKind::TypeParam => "type_param",
|
||||||
SymbolKind::Union => "union",
|
SymbolKind::Union => "union",
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub(crate) fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind {
|
||||||
SymbolKind::Struct => lsp_types::SymbolKind::STRUCT,
|
SymbolKind::Struct => lsp_types::SymbolKind::STRUCT,
|
||||||
SymbolKind::Enum => lsp_types::SymbolKind::ENUM,
|
SymbolKind::Enum => lsp_types::SymbolKind::ENUM,
|
||||||
SymbolKind::Variant => lsp_types::SymbolKind::ENUM_MEMBER,
|
SymbolKind::Variant => lsp_types::SymbolKind::ENUM_MEMBER,
|
||||||
SymbolKind::Trait => lsp_types::SymbolKind::INTERFACE,
|
SymbolKind::Trait | SymbolKind::TraitAlias => lsp_types::SymbolKind::INTERFACE,
|
||||||
SymbolKind::Macro
|
SymbolKind::Macro
|
||||||
| SymbolKind::BuiltinAttr
|
| SymbolKind::BuiltinAttr
|
||||||
| SymbolKind::Attribute
|
| SymbolKind::Attribute
|
||||||
|
@ -135,6 +135,7 @@ pub(crate) fn completion_item_kind(
|
||||||
SymbolKind::Static => lsp_types::CompletionItemKind::VALUE,
|
SymbolKind::Static => lsp_types::CompletionItemKind::VALUE,
|
||||||
SymbolKind::Struct => lsp_types::CompletionItemKind::STRUCT,
|
SymbolKind::Struct => lsp_types::CompletionItemKind::STRUCT,
|
||||||
SymbolKind::Trait => lsp_types::CompletionItemKind::INTERFACE,
|
SymbolKind::Trait => lsp_types::CompletionItemKind::INTERFACE,
|
||||||
|
SymbolKind::TraitAlias => lsp_types::CompletionItemKind::INTERFACE,
|
||||||
SymbolKind::TypeAlias => lsp_types::CompletionItemKind::STRUCT,
|
SymbolKind::TypeAlias => lsp_types::CompletionItemKind::STRUCT,
|
||||||
SymbolKind::TypeParam => lsp_types::CompletionItemKind::TYPE_PARAMETER,
|
SymbolKind::TypeParam => lsp_types::CompletionItemKind::TYPE_PARAMETER,
|
||||||
SymbolKind::Union => lsp_types::CompletionItemKind::STRUCT,
|
SymbolKind::Union => lsp_types::CompletionItemKind::STRUCT,
|
||||||
|
@ -656,6 +657,7 @@ fn semantic_token_type_and_modifiers(
|
||||||
SymbolKind::Union => semantic_tokens::UNION,
|
SymbolKind::Union => semantic_tokens::UNION,
|
||||||
SymbolKind::TypeAlias => semantic_tokens::TYPE_ALIAS,
|
SymbolKind::TypeAlias => semantic_tokens::TYPE_ALIAS,
|
||||||
SymbolKind::Trait => semantic_tokens::INTERFACE,
|
SymbolKind::Trait => semantic_tokens::INTERFACE,
|
||||||
|
SymbolKind::TraitAlias => semantic_tokens::INTERFACE,
|
||||||
SymbolKind::Macro => semantic_tokens::MACRO,
|
SymbolKind::Macro => semantic_tokens::MACRO,
|
||||||
SymbolKind::BuiltinAttr => semantic_tokens::BUILTIN_ATTRIBUTE,
|
SymbolKind::BuiltinAttr => semantic_tokens::BUILTIN_ATTRIBUTE,
|
||||||
SymbolKind::ToolModule => semantic_tokens::TOOL_MODULE,
|
SymbolKind::ToolModule => semantic_tokens::TOOL_MODULE,
|
||||||
|
|
Loading…
Reference in a new issue