mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 19:23:10 +00:00
Support for nested traits
This commit is contained in:
parent
fe1b160dcf
commit
f42697e54b
@ -553,7 +553,7 @@ pub struct Trait {
|
|||||||
|
|
||||||
impl Trait {
|
impl Trait {
|
||||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
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 {
|
pub fn name(self, db: &impl DefDatabase) -> Name {
|
||||||
|
@ -26,7 +26,7 @@ use crate::{
|
|||||||
path::Path,
|
path::Path,
|
||||||
type_ref::{Mutability, TypeRef},
|
type_ref::{Mutability, TypeRef},
|
||||||
ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc,
|
ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc,
|
||||||
StructLoc, TypeAliasLoc, UnionLoc,
|
StructLoc, TraitLoc, TypeAliasLoc, UnionLoc,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(super) fn lower(
|
pub(super) fn lower(
|
||||||
@ -522,7 +522,14 @@ where
|
|||||||
let ast_id = self.expander.ast_id(&def);
|
let ast_id = self.expander.ast_id(&def);
|
||||||
UnionLoc { container, ast_id }.intern(self.db).into()
|
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)
|
self.body.defs.push(def)
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ impl_intern_key!(TraitId);
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct TraitLoc {
|
pub struct TraitLoc {
|
||||||
pub container: ModuleId,
|
pub container: ContainerId,
|
||||||
pub ast_id: AstId<ast::TraitDef>,
|
pub ast_id: AstId<ast::TraitDef>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ impl HasModule for AssocContainerId {
|
|||||||
match *self {
|
match *self {
|
||||||
AssocContainerId::ContainerId(it) => it.module(db),
|
AssocContainerId::ContainerId(it) => it.module(db),
|
||||||
AssocContainerId::ImplId(it) => it.lookup(db).container,
|
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 {
|
match self {
|
||||||
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.module(db),
|
||||||
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.module(db),
|
GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db),
|
||||||
|
@ -802,7 +802,7 @@ where
|
|||||||
PerNs::values(def.into())
|
PerNs::values(def.into())
|
||||||
}
|
}
|
||||||
raw::DefKind::Trait(ast_id) => {
|
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);
|
.intern(self.def_collector.db);
|
||||||
|
|
||||||
PerNs::types(def.into())
|
PerNs::types(def.into())
|
||||||
|
@ -9,7 +9,9 @@ use chalk_ir::{
|
|||||||
};
|
};
|
||||||
use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
|
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::{
|
use ra_db::{
|
||||||
salsa::{InternId, InternKey},
|
salsa::{InternId, InternKey},
|
||||||
CrateId,
|
CrateId,
|
||||||
@ -591,7 +593,7 @@ pub(crate) fn trait_datum_query(
|
|||||||
let bound_vars = Substs::bound_vars(&generic_params);
|
let bound_vars = Substs::bound_vars(&generic_params);
|
||||||
let flags = chalk_rust_ir::TraitFlags {
|
let flags = chalk_rust_ir::TraitFlags {
|
||||||
auto: trait_data.auto,
|
auto: trait_data.auto,
|
||||||
upstream: trait_.lookup(db).container.krate != krate,
|
upstream: trait_.lookup(db).container.module(db).krate != krate,
|
||||||
non_enumerable: true,
|
non_enumerable: true,
|
||||||
coinductive: false, // only relevant for Chalk testing
|
coinductive: false, // only relevant for Chalk testing
|
||||||
// FIXME set these flags correctly
|
// FIXME set these flags correctly
|
||||||
|
Loading…
Reference in New Issue
Block a user