Support for nested traits

This commit is contained in:
Aleksey Kladov 2019-12-20 12:29:25 +01:00
parent fe1b160dcf
commit f42697e54b
5 changed files with 18 additions and 9 deletions

View file

@ -553,7 +553,7 @@ pub struct Trait {
impl Trait {
pub fn module(self, db: &impl DefDatabase) -> Module {
Module { id: self.id.lookup(db).container }
Module { id: self.id.lookup(db).container.module(db) }
}
pub fn name(self, db: &impl DefDatabase) -> Name {

View file

@ -26,7 +26,7 @@ use crate::{
path::Path,
type_ref::{Mutability, TypeRef},
ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc,
StructLoc, TypeAliasLoc, UnionLoc,
StructLoc, TraitLoc, TypeAliasLoc, UnionLoc,
};
pub(super) fn lower(
@ -522,7 +522,14 @@ where
let ast_id = self.expander.ast_id(&def);
UnionLoc { container, ast_id }.intern(self.db).into()
}
_ => continue,
ast::ModuleItem::TraitDef(def) => {
let ast_id = self.expander.ast_id(&def);
TraitLoc { container, ast_id }.intern(self.db).into()
}
ast::ModuleItem::ImplBlock(_)
| ast::ModuleItem::UseItem(_)
| ast::ModuleItem::ExternCrateItem(_)
| ast::ModuleItem::Module(_) => continue,
};
self.body.defs.push(def)
}

View file

@ -235,7 +235,7 @@ impl_intern_key!(TraitId);
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TraitLoc {
pub container: ModuleId,
pub container: ContainerId,
pub ast_id: AstId<ast::TraitDef>,
}
@ -499,7 +499,7 @@ impl HasModule for AssocContainerId {
match *self {
AssocContainerId::ContainerId(it) => it.module(db),
AssocContainerId::ImplId(it) => it.lookup(db).container,
AssocContainerId::TraitId(it) => it.lookup(db).container,
AssocContainerId::TraitId(it) => it.lookup(db).container.module(db),
}
}
}
@ -548,7 +548,7 @@ impl HasModule for GenericDefId {
match self {
GenericDefId::FunctionId(it) => it.lookup(db).module(db),
GenericDefId::AdtId(it) => it.module(db),
GenericDefId::TraitId(it) => it.lookup(db).container,
GenericDefId::TraitId(it) => it.lookup(db).container.module(db),
GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
GenericDefId::ImplId(it) => it.lookup(db).container,
GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db),

View file

@ -802,7 +802,7 @@ where
PerNs::values(def.into())
}
raw::DefKind::Trait(ast_id) => {
let def = TraitLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
let def = TraitLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
.intern(self.def_collector.db);
PerNs::types(def.into())

View file

@ -9,7 +9,9 @@ use chalk_ir::{
};
use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
use hir_def::{AssocContainerId, AssocItemId, GenericDefId, ImplId, Lookup, TraitId, TypeAliasId};
use hir_def::{
AssocContainerId, AssocItemId, GenericDefId, HasModule, ImplId, Lookup, TraitId, TypeAliasId,
};
use ra_db::{
salsa::{InternId, InternKey},
CrateId,
@ -591,7 +593,7 @@ pub(crate) fn trait_datum_query(
let bound_vars = Substs::bound_vars(&generic_params);
let flags = chalk_rust_ir::TraitFlags {
auto: trait_data.auto,
upstream: trait_.lookup(db).container.krate != krate,
upstream: trait_.lookup(db).container.module(db).krate != krate,
non_enumerable: true,
coinductive: false, // only relevant for Chalk testing
// FIXME set these flags correctly