mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-02 18:12:51 +00:00
Use chalk_ir::ForeignDefId
This commit is contained in:
parent
d453378569
commit
dfafcd926a
@ -11,9 +11,9 @@ use hir_def::{
|
||||
use hir_expand::name::Name;
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase, primitive, utils::generics, AdtId, AliasTy, CallableDefId, CallableSig,
|
||||
GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar,
|
||||
Substs, TraitRef, Ty, TyKind,
|
||||
db::HirDatabase, from_foreign_def_id, primitive, utils::generics, AdtId, AliasTy,
|
||||
CallableDefId, CallableSig, GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy,
|
||||
OpaqueTyId, ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind,
|
||||
};
|
||||
|
||||
pub struct HirFormatter<'a> {
|
||||
@ -491,7 +491,7 @@ impl HirDisplay for Ty {
|
||||
}
|
||||
}
|
||||
TyKind::ForeignType(type_alias) => {
|
||||
let type_alias = f.db.type_alias_data(*type_alias);
|
||||
let type_alias = f.db.type_alias_data(from_foreign_def_id(*type_alias));
|
||||
write!(f, "{}", type_alias.name)?;
|
||||
}
|
||||
TyKind::OpaqueType(opaque_ty_id, parameters) => {
|
||||
|
@ -51,6 +51,8 @@ pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Scalar, TyVariabl
|
||||
|
||||
pub use crate::traits::chalk::Interner;
|
||||
|
||||
pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum Lifetime {
|
||||
Parameter(LifetimeParamId),
|
||||
@ -194,7 +196,7 @@ pub enum TyKind {
|
||||
Closure(DefWithBodyId, ExprId, Substs),
|
||||
|
||||
/// Represents a foreign type declared in external blocks.
|
||||
ForeignType(TypeAliasId),
|
||||
ForeignType(ForeignDefId),
|
||||
|
||||
/// A pointer to a function. Written as `fn() -> i32`.
|
||||
///
|
||||
@ -705,7 +707,7 @@ impl Ty {
|
||||
TyKind::Adt(AdtId(adt), ..) => Some(adt.into()),
|
||||
TyKind::FnDef(callable, ..) => Some(callable.into()),
|
||||
TyKind::AssociatedType(type_alias, ..) => Some(type_alias.into()),
|
||||
TyKind::ForeignType(type_alias, ..) => Some(type_alias.into()),
|
||||
TyKind::ForeignType(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -724,8 +726,10 @@ impl Ty {
|
||||
(TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_), TyKind::Array(_)) => true,
|
||||
(TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2,
|
||||
(TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2,
|
||||
(TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..))
|
||||
| (TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2,
|
||||
(TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => {
|
||||
ty_id == ty_id2
|
||||
}
|
||||
(TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2,
|
||||
(TyKind::Closure(def, expr, _), TyKind::Closure(def2, expr2, _)) => {
|
||||
expr == expr2 && def == def2
|
||||
}
|
||||
@ -1116,3 +1120,11 @@ pub struct ReturnTypeImplTraits {
|
||||
pub(crate) struct ReturnTypeImplTrait {
|
||||
pub(crate) bounds: Binders<Vec<GenericPredicate>>,
|
||||
}
|
||||
|
||||
pub(crate) fn to_foreign_def_id(id: TypeAliasId) -> chalk_ir::ForeignDefId<Interner> {
|
||||
chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id))
|
||||
}
|
||||
|
||||
pub(crate) fn from_foreign_def_id(id: chalk_ir::ForeignDefId<Interner>) -> TypeAliasId {
|
||||
salsa::InternKey::from_intern_id(id.0)
|
||||
}
|
||||
|
@ -1143,7 +1143,7 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
|
||||
let ctx =
|
||||
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
|
||||
if db.type_alias_data(t).is_extern {
|
||||
Binders::new(0, TyKind::ForeignType(t).intern(&Interner))
|
||||
Binders::new(0, TyKind::ForeignType(crate::to_foreign_def_id(t)).intern(&Interner))
|
||||
} else {
|
||||
let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
|
||||
let type_ref = &db.type_alias_data(t).type_ref;
|
||||
|
@ -9,7 +9,7 @@ use base_db::CrateId;
|
||||
use chalk_ir::Mutability;
|
||||
use hir_def::{
|
||||
lang_item::LangItemTarget, AssocContainerId, AssocItemId, FunctionId, GenericDefId, HasModule,
|
||||
ImplId, Lookup, ModuleId, TraitId, TypeAliasId,
|
||||
ImplId, Lookup, ModuleId, TraitId,
|
||||
};
|
||||
use hir_expand::name::Name;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
@ -17,10 +17,11 @@ use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use crate::{
|
||||
autoderef,
|
||||
db::HirDatabase,
|
||||
from_foreign_def_id,
|
||||
primitive::{self, FloatTy, IntTy, UintTy},
|
||||
utils::all_super_traits,
|
||||
AdtId, Canonical, DebruijnIndex, FnPointer, FnSig, InEnvironment, Interner, Scalar, Substs,
|
||||
TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk,
|
||||
AdtId, Canonical, DebruijnIndex, FnPointer, FnSig, ForeignDefId, InEnvironment, Interner,
|
||||
Scalar, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk,
|
||||
};
|
||||
|
||||
/// This is used as a key for indexing impls.
|
||||
@ -35,7 +36,7 @@ pub enum TyFingerprint {
|
||||
Adt(hir_def::AdtId),
|
||||
Dyn(TraitId),
|
||||
Tuple(usize),
|
||||
ForeignType(TypeAliasId),
|
||||
ForeignType(ForeignDefId),
|
||||
FnPtr(usize, FnSig),
|
||||
}
|
||||
|
||||
@ -236,8 +237,10 @@ impl Ty {
|
||||
TyKind::Adt(AdtId(def_id), _) => {
|
||||
return mod_to_crate_ids(def_id.module(db.upcast()));
|
||||
}
|
||||
TyKind::ForeignType(type_alias_id) => {
|
||||
return mod_to_crate_ids(type_alias_id.lookup(db.upcast()).module(db.upcast()));
|
||||
TyKind::ForeignType(id) => {
|
||||
return mod_to_crate_ids(
|
||||
from_foreign_def_id(*id).lookup(db.upcast()).module(db.upcast()),
|
||||
);
|
||||
}
|
||||
TyKind::Scalar(Scalar::Bool) => lang_item_crate!("bool"),
|
||||
TyKind::Scalar(Scalar::Char) => lang_item_crate!("char"),
|
||||
|
@ -12,7 +12,6 @@ pub struct Interner;
|
||||
|
||||
pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
|
||||
pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
|
||||
pub(crate) type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
|
||||
pub(crate) type TraitId = chalk_ir::TraitId<Interner>;
|
||||
pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
|
||||
pub(crate) type AdtId = chalk_ir::AdtId<Interner>;
|
||||
|
@ -51,11 +51,7 @@ impl ToChalk for Ty {
|
||||
chalk_ir::TyKind::OpaqueType(id, substitution).intern(&Interner)
|
||||
}
|
||||
|
||||
TyKind::ForeignType(type_alias) => {
|
||||
let foreign_type = TypeAliasAsForeignType(type_alias);
|
||||
let foreign_type_id = foreign_type.to_chalk(db);
|
||||
chalk_ir::TyKind::Foreign(foreign_type_id).intern(&Interner)
|
||||
}
|
||||
TyKind::ForeignType(id) => chalk_ir::TyKind::Foreign(id).intern(&Interner),
|
||||
|
||||
TyKind::Scalar(scalar) => chalk_ir::TyKind::Scalar(scalar).intern(&Interner),
|
||||
|
||||
@ -217,9 +213,7 @@ impl ToChalk for Ty {
|
||||
TyKind::Closure(def, expr, from_chalk(db, subst))
|
||||
}
|
||||
|
||||
chalk_ir::TyKind::Foreign(foreign_def_id) => {
|
||||
TyKind::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0)
|
||||
}
|
||||
chalk_ir::TyKind::Foreign(foreign_def_id) => TyKind::ForeignType(foreign_def_id),
|
||||
chalk_ir::TyKind::Generator(_, _) => unimplemented!(), // FIXME
|
||||
chalk_ir::TyKind::GeneratorWitness(_, _) => unimplemented!(), // FIXME
|
||||
}
|
||||
@ -352,20 +346,6 @@ impl ToChalk for TypeAliasAsAssocType {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct TypeAliasAsForeignType(pub(crate) TypeAliasId);
|
||||
|
||||
impl ToChalk for TypeAliasAsForeignType {
|
||||
type Chalk = ForeignDefId;
|
||||
|
||||
fn to_chalk(self, _db: &dyn HirDatabase) -> ForeignDefId {
|
||||
chalk_ir::ForeignDefId(self.0.as_intern_id())
|
||||
}
|
||||
|
||||
fn from_chalk(_db: &dyn HirDatabase, foreign_def_id: ForeignDefId) -> TypeAliasAsForeignType {
|
||||
TypeAliasAsForeignType(InternKey::from_intern_id(foreign_def_id.0))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId);
|
||||
|
||||
impl ToChalk for TypeAliasAsValue {
|
||||
|
Loading…
Reference in New Issue
Block a user