mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Fix compilation of other crates
This commit is contained in:
parent
a3d8cffde3
commit
0718682cff
3 changed files with 25 additions and 14 deletions
|
@ -13,6 +13,7 @@ use hir_def::{
|
|||
AdtId, ConstId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, LocalEnumVariantId,
|
||||
LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId,
|
||||
TypeParamId, UnionId,
|
||||
GenericDefId
|
||||
};
|
||||
use hir_expand::{
|
||||
diagnostics::DiagnosticSink,
|
||||
|
@ -21,7 +22,8 @@ use hir_expand::{
|
|||
};
|
||||
use hir_ty::{
|
||||
autoderef, display::HirFormatter, expr::ExprValidator, method_resolution, ApplicationTy,
|
||||
Canonical, InEnvironment, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk,
|
||||
Canonical, InEnvironment, TraitEnvironment, Ty, TyDefId, TypeCtor,
|
||||
Substs
|
||||
};
|
||||
use ra_db::{CrateId, Edition, FileId};
|
||||
use ra_prof::profile;
|
||||
|
@ -270,7 +272,13 @@ impl StructField {
|
|||
|
||||
pub fn ty(&self, db: &impl HirDatabase) -> Type {
|
||||
let var_id = self.parent.into();
|
||||
let ty = db.field_types(var_id)[self.id].clone();
|
||||
let generic_def_id: GenericDefId = match self.parent {
|
||||
VariantDef::Struct(it) => it.id.into(),
|
||||
VariantDef::Union(it) => it.id.into(),
|
||||
VariantDef::EnumVariant(it) => it.parent.id.into(),
|
||||
};
|
||||
let substs = Substs::type_params(db, generic_def_id);
|
||||
let ty = db.field_types(var_id)[self.id].clone().subst(&substs);
|
||||
Type::new(db, self.parent.module(db).id.krate.into(), var_id, ty)
|
||||
}
|
||||
|
||||
|
@ -789,11 +797,7 @@ impl ImplBlock {
|
|||
pub fn target_ty(&self, db: &impl HirDatabase) -> Type {
|
||||
let impl_data = db.impl_data(self.id);
|
||||
let resolver = self.id.resolver(db);
|
||||
let ctx = hir_ty::TyLoweringContext {
|
||||
db,
|
||||
resolver: &resolver,
|
||||
impl_trait_mode: hir_ty::ImplTraitLoweringMode::Disallowed,
|
||||
};
|
||||
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
|
||||
let environment = TraitEnvironment::lower(db, &resolver);
|
||||
let ty = Ty::from_hir(&ctx, &impl_data.target_type);
|
||||
Type {
|
||||
|
@ -856,9 +860,10 @@ impl Type {
|
|||
fn from_def(
|
||||
db: &impl HirDatabase,
|
||||
krate: CrateId,
|
||||
def: impl HasResolver + Into<TyDefId>,
|
||||
def: impl HasResolver + Into<TyDefId> + Into<GenericDefId>,
|
||||
) -> Type {
|
||||
let ty = db.ty(def.into());
|
||||
let substs = Substs::type_params(db, def);
|
||||
let ty = db.ty(def.into()).subst(&substs);
|
||||
Type::new(db, krate, def, ty)
|
||||
}
|
||||
|
||||
|
@ -955,7 +960,7 @@ impl Type {
|
|||
match a_ty.ctor {
|
||||
TypeCtor::Tuple { .. } => {
|
||||
for ty in a_ty.parameters.iter() {
|
||||
let ty = ty.clone().subst(&a_ty.parameters);
|
||||
let ty = ty.clone();
|
||||
res.push(self.derived(ty));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -361,10 +361,16 @@ impl Substs {
|
|||
}
|
||||
|
||||
/// Return Substs that replace each parameter by itself (i.e. `Ty::Param`).
|
||||
pub(crate) fn type_params(generic_params: &Generics) -> Substs {
|
||||
pub(crate) fn type_params_for_generics(generic_params: &Generics) -> Substs {
|
||||
Substs(generic_params.iter().map(|(id, _)| Ty::Param(id)).collect())
|
||||
}
|
||||
|
||||
/// Return Substs that replace each parameter by itself (i.e. `Ty::Param`).
|
||||
pub fn type_params(db: &impl HirDatabase, def: impl Into<GenericDefId>) -> Substs {
|
||||
let params = generics(db, def.into());
|
||||
Substs::type_params_for_generics(¶ms)
|
||||
}
|
||||
|
||||
/// Return Substs that replace each parameter by a bound variable.
|
||||
pub(crate) fn bound_vars(generic_params: &Generics) -> Substs {
|
||||
Substs(generic_params.iter().enumerate().map(|(idx, _)| Ty::Bound(idx as u32)).collect())
|
||||
|
@ -1026,7 +1032,7 @@ impl HirDisplay for Ty {
|
|||
TypeParamProvenance::ArgumentImplTrait => {
|
||||
write!(f, "impl ")?;
|
||||
let bounds = f.db.generic_predicates_for_param(*id);
|
||||
let substs = Substs::type_params(&generics);
|
||||
let substs = Substs::type_params_for_generics(&generics);
|
||||
write_bounds_like_dyn_trait(&bounds.iter().map(|b| b.clone().subst(&substs)).collect::<Vec<_>>(), f)?;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,7 +276,7 @@ impl Ty {
|
|||
TypeNs::SelfType(impl_id) => {
|
||||
let generics = generics(ctx.db, impl_id.into());
|
||||
let substs = match ctx.type_param_mode {
|
||||
TypeParamLoweringMode::Placeholder => Substs::type_params(&generics),
|
||||
TypeParamLoweringMode::Placeholder => Substs::type_params_for_generics(&generics),
|
||||
TypeParamLoweringMode::Variable => Substs::bound_vars(&generics),
|
||||
};
|
||||
ctx.db.impl_self_ty(impl_id).subst(&substs)
|
||||
|
@ -284,7 +284,7 @@ impl Ty {
|
|||
TypeNs::AdtSelfType(adt) => {
|
||||
let generics = generics(ctx.db, adt.into());
|
||||
let substs = match ctx.type_param_mode {
|
||||
TypeParamLoweringMode::Placeholder => Substs::type_params(&generics),
|
||||
TypeParamLoweringMode::Placeholder => Substs::type_params_for_generics(&generics),
|
||||
TypeParamLoweringMode::Variable => Substs::bound_vars(&generics),
|
||||
};
|
||||
ctx.db.ty(adt.into()).subst(&substs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue