mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-25 11:17:13 +00:00
Merge pull request #20733 from jackh726/next-trait-solver-next3
Convert more things from chalk to next solver
This commit is contained in:
commit
4d4a1dd464
@ -3,17 +3,20 @@
|
||||
use chalk_ir::{
|
||||
AdtId, DebruijnIndex, Scalar,
|
||||
cast::{Cast, CastTo, Caster},
|
||||
fold::TypeFoldable,
|
||||
interner::HasInterner,
|
||||
};
|
||||
use hir_def::{GenericDefId, GenericParamId, TraitId, TypeAliasId, builtin_type::BuiltinType};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{
|
||||
Binders, BoundVar, CallableSig, GenericArg, GenericArgData, Interner, ProjectionTy,
|
||||
Substitution, TraitRef, Ty, TyDefId, TyExt, TyKind, consteval::unknown_const_as_generic,
|
||||
db::HirDatabase, error_lifetime, generics::generics, infer::unify::InferenceTable, primitive,
|
||||
to_assoc_type_id, to_chalk_trait_id,
|
||||
BoundVar, CallableSig, GenericArg, GenericArgData, Interner, ProjectionTy, Substitution,
|
||||
TraitRef, Ty, TyDefId, TyExt, TyKind,
|
||||
consteval::unknown_const_as_generic,
|
||||
db::HirDatabase,
|
||||
error_lifetime,
|
||||
generics::generics,
|
||||
infer::unify::InferenceTable,
|
||||
next_solver::{DbInterner, EarlyBinder, mapping::ChalkToNextSolver},
|
||||
primitive, to_assoc_type_id, to_chalk_trait_id,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@ -345,19 +348,20 @@ impl TyBuilder<TypeAliasId> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>> TyBuilder<Binders<T>> {
|
||||
pub fn build(self) -> T {
|
||||
impl<'db, T: rustc_type_ir::TypeFoldable<DbInterner<'db>>> TyBuilder<EarlyBinder<'db, T>> {
|
||||
pub fn build(self, interner: DbInterner<'db>) -> T {
|
||||
let (b, subst) = self.build_internal();
|
||||
b.substitute(Interner, &subst)
|
||||
let args: crate::next_solver::GenericArgs<'db> = subst.to_nextsolver(interner);
|
||||
b.instantiate(interner, args)
|
||||
}
|
||||
}
|
||||
|
||||
impl TyBuilder<Binders<Ty>> {
|
||||
impl<'db> TyBuilder<EarlyBinder<'db, crate::next_solver::Ty<'db>>> {
|
||||
pub fn def_ty(
|
||||
db: &dyn HirDatabase,
|
||||
db: &'db dyn HirDatabase,
|
||||
def: TyDefId,
|
||||
parent_subst: Option<Substitution>,
|
||||
) -> TyBuilder<Binders<Ty>> {
|
||||
) -> TyBuilder<EarlyBinder<'db, crate::next_solver::Ty<'db>>> {
|
||||
let poly_ty = db.ty(def);
|
||||
let id: GenericDefId = match def {
|
||||
TyDefId::BuiltinType(_) => {
|
||||
@ -370,7 +374,10 @@ impl TyBuilder<Binders<Ty>> {
|
||||
TyBuilder::subst_for_def(db, id, parent_subst).with_data(poly_ty)
|
||||
}
|
||||
|
||||
pub fn impl_self_ty(db: &dyn HirDatabase, def: hir_def::ImplId) -> TyBuilder<Binders<Ty>> {
|
||||
TyBuilder::subst_for_def(db, def, None).with_data(db.impl_self_ty(def))
|
||||
pub fn impl_self_ty(
|
||||
db: &'db dyn HirDatabase,
|
||||
def: hir_def::ImplId,
|
||||
) -> TyBuilder<EarlyBinder<'db, crate::next_solver::Ty<'db>>> {
|
||||
TyBuilder::subst_for_def(db, def, None).with_data(db.impl_self_ty_ns(def))
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ use smallvec::SmallVec;
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::{
|
||||
Binders, Const, ImplTraitId, ImplTraits, InferenceResult, PolyFnSig, Substitution,
|
||||
TraitEnvironment, TraitRef, Ty, TyDefId, ValueTyDefId, chalk_db,
|
||||
Binders, Const, ImplTraitId, ImplTraits, InferenceResult, Substitution, TraitEnvironment,
|
||||
TraitRef, Ty, TyDefId, ValueTyDefId, chalk_db,
|
||||
consteval::ConstEvalError,
|
||||
drop::DropGlue,
|
||||
dyn_compatibility::DynCompatibilityViolation,
|
||||
@ -114,55 +114,88 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
||||
#[salsa::invoke(crate::dyn_compatibility::dyn_compatibility_of_trait_query)]
|
||||
fn dyn_compatibility_of_trait(&self, trait_: TraitId) -> Option<DynCompatibilityViolation>;
|
||||
|
||||
#[salsa::invoke(crate::lower::ty_query)]
|
||||
#[salsa::invoke(crate::lower_nextsolver::ty_query)]
|
||||
#[salsa::transparent]
|
||||
fn ty(&self, def: TyDefId) -> Binders<Ty>;
|
||||
fn ty<'db>(
|
||||
&'db self,
|
||||
def: TyDefId,
|
||||
) -> crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>;
|
||||
|
||||
#[salsa::invoke(crate::lower::type_for_type_alias_with_diagnostics_query)]
|
||||
#[salsa::cycle(cycle_result = crate::lower::type_for_type_alias_with_diagnostics_cycle_result)]
|
||||
fn type_for_type_alias_with_diagnostics(&self, def: TypeAliasId) -> (Binders<Ty>, Diagnostics);
|
||||
#[salsa::invoke(crate::lower_nextsolver::type_for_type_alias_with_diagnostics_query)]
|
||||
#[salsa::cycle(cycle_result = crate::lower_nextsolver::type_for_type_alias_with_diagnostics_cycle_result)]
|
||||
fn type_for_type_alias_with_diagnostics<'db>(
|
||||
&'db self,
|
||||
def: TypeAliasId,
|
||||
) -> (crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>, Diagnostics);
|
||||
|
||||
/// Returns the type of the value of the given constant, or `None` if the `ValueTyDefId` is
|
||||
/// a `StructId` or `EnumVariantId` with a record constructor.
|
||||
#[salsa::invoke(crate::lower::value_ty_query)]
|
||||
fn value_ty(&self, def: ValueTyDefId) -> Option<Binders<Ty>>;
|
||||
#[salsa::invoke(crate::lower_nextsolver::value_ty_query)]
|
||||
fn value_ty<'db>(
|
||||
&'db self,
|
||||
def: ValueTyDefId,
|
||||
) -> Option<crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>>;
|
||||
|
||||
#[salsa::invoke(crate::lower::impl_self_ty_with_diagnostics_query)]
|
||||
#[salsa::cycle(cycle_result = crate::lower::impl_self_ty_with_diagnostics_cycle_result)]
|
||||
fn impl_self_ty_with_diagnostics(&self, def: ImplId) -> (Binders<Ty>, Diagnostics);
|
||||
#[salsa::invoke(crate::lower_nextsolver::impl_self_ty_with_diagnostics_query)]
|
||||
#[salsa::cycle(cycle_result = crate::lower_nextsolver::impl_self_ty_with_diagnostics_cycle_result)]
|
||||
fn impl_self_ty_with_diagnostics<'db>(
|
||||
&'db self,
|
||||
def: ImplId,
|
||||
) -> (crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>, Diagnostics);
|
||||
|
||||
#[salsa::invoke(crate::lower::impl_self_ty_query)]
|
||||
#[salsa::transparent]
|
||||
fn impl_self_ty(&self, def: ImplId) -> Binders<Ty>;
|
||||
|
||||
// FIXME: Make this a non-interned query.
|
||||
#[salsa::invoke_interned(crate::lower::const_param_ty_with_diagnostics_query)]
|
||||
#[salsa::cycle(cycle_result = crate::lower::const_param_ty_with_diagnostics_cycle_result)]
|
||||
fn const_param_ty_with_diagnostics(&self, def: ConstParamId) -> (Ty, Diagnostics);
|
||||
#[salsa::invoke_interned(crate::lower_nextsolver::const_param_ty_with_diagnostics_query)]
|
||||
#[salsa::cycle(cycle_result = crate::lower_nextsolver::const_param_ty_with_diagnostics_cycle_result)]
|
||||
fn const_param_ty_with_diagnostics<'db>(
|
||||
&'db self,
|
||||
def: ConstParamId,
|
||||
) -> (crate::next_solver::Ty<'db>, Diagnostics);
|
||||
|
||||
#[salsa::invoke(crate::lower::const_param_ty_query)]
|
||||
#[salsa::transparent]
|
||||
// FIXME: Make this a non-interned query.
|
||||
#[salsa::invoke_interned(crate::lower::const_param_ty_query)]
|
||||
#[salsa::cycle(cycle_result = crate::lower::const_param_ty_cycle_result)]
|
||||
fn const_param_ty(&self, def: ConstParamId) -> Ty;
|
||||
|
||||
#[salsa::invoke(crate::lower::impl_trait_with_diagnostics_query)]
|
||||
fn impl_trait_with_diagnostics(&self, def: ImplId) -> Option<(Binders<TraitRef>, Diagnostics)>;
|
||||
#[salsa::invoke(crate::lower_nextsolver::impl_trait_with_diagnostics_query)]
|
||||
fn impl_trait_with_diagnostics<'db>(
|
||||
&'db self,
|
||||
def: ImplId,
|
||||
) -> Option<(
|
||||
crate::next_solver::EarlyBinder<'db, crate::next_solver::TraitRef<'db>>,
|
||||
Diagnostics,
|
||||
)>;
|
||||
|
||||
#[salsa::invoke(crate::lower::impl_trait_query)]
|
||||
#[salsa::transparent]
|
||||
fn impl_trait(&self, def: ImplId) -> Option<Binders<TraitRef>>;
|
||||
|
||||
#[salsa::invoke(crate::lower::field_types_with_diagnostics_query)]
|
||||
fn field_types_with_diagnostics(
|
||||
&self,
|
||||
#[salsa::invoke(crate::lower_nextsolver::field_types_with_diagnostics_query)]
|
||||
fn field_types_with_diagnostics<'db>(
|
||||
&'db self,
|
||||
var: VariantId,
|
||||
) -> (Arc<ArenaMap<LocalFieldId, Binders<Ty>>>, Diagnostics);
|
||||
) -> (
|
||||
Arc<
|
||||
ArenaMap<
|
||||
LocalFieldId,
|
||||
crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>,
|
||||
>,
|
||||
>,
|
||||
Diagnostics,
|
||||
);
|
||||
|
||||
#[salsa::invoke(crate::lower::field_types_query)]
|
||||
#[salsa::transparent]
|
||||
fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalFieldId, Binders<Ty>>>;
|
||||
|
||||
#[salsa::invoke(crate::lower::callable_item_signature_query)]
|
||||
fn callable_item_signature(&self, def: CallableDefId) -> PolyFnSig;
|
||||
#[salsa::invoke(crate::lower_nextsolver::callable_item_signature_query)]
|
||||
fn callable_item_signature<'db>(
|
||||
&'db self,
|
||||
def: CallableDefId,
|
||||
) -> crate::next_solver::EarlyBinder<'db, crate::next_solver::PolyFnSig<'db>>;
|
||||
|
||||
#[salsa::invoke(crate::lower::return_type_impl_traits)]
|
||||
fn return_type_impl_traits(&self, def: FunctionId) -> Option<Arc<Binders<ImplTraits>>>;
|
||||
@ -182,6 +215,21 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
||||
#[salsa::invoke(crate::lower::generic_predicates_query)]
|
||||
fn generic_predicates(&self, def: GenericDefId) -> GenericPredicates;
|
||||
|
||||
#[salsa::invoke(
|
||||
crate::lower_nextsolver::generic_predicates_without_parent_with_diagnostics_query
|
||||
)]
|
||||
fn generic_predicates_without_parent_with_diagnostics<'db>(
|
||||
&'db self,
|
||||
def: GenericDefId,
|
||||
) -> (crate::lower_nextsolver::GenericPredicates<'db>, Diagnostics);
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::generic_predicates_without_parent_query)]
|
||||
#[salsa::transparent]
|
||||
fn generic_predicates_without_parent<'db>(
|
||||
&'db self,
|
||||
def: GenericDefId,
|
||||
) -> crate::lower_nextsolver::GenericPredicates<'db>;
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::trait_environment_for_body_query)]
|
||||
#[salsa::transparent]
|
||||
fn trait_environment_for_body<'db>(&'db self, def: DefWithBodyId)
|
||||
@ -277,35 +325,6 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
||||
|
||||
// next trait solver
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::ty_query)]
|
||||
#[salsa::transparent]
|
||||
fn ty_ns<'db>(
|
||||
&'db self,
|
||||
def: TyDefId,
|
||||
) -> crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>;
|
||||
|
||||
/// Returns the type of the value of the given constant, or `None` if the `ValueTyDefId` is
|
||||
/// a `StructId` or `EnumVariantId` with a record constructor.
|
||||
#[salsa::invoke(crate::lower_nextsolver::value_ty_query)]
|
||||
fn value_ty_ns<'db>(
|
||||
&'db self,
|
||||
def: ValueTyDefId,
|
||||
) -> Option<crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>>;
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::type_for_type_alias_with_diagnostics_query)]
|
||||
#[salsa::cycle(cycle_result = crate::lower_nextsolver::type_for_type_alias_with_diagnostics_cycle_result)]
|
||||
fn type_for_type_alias_with_diagnostics_ns<'db>(
|
||||
&'db self,
|
||||
def: TypeAliasId,
|
||||
) -> (crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>, Diagnostics);
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::impl_self_ty_with_diagnostics_query)]
|
||||
#[salsa::cycle(cycle_result = crate::lower_nextsolver::impl_self_ty_with_diagnostics_cycle_result)]
|
||||
fn impl_self_ty_with_diagnostics_ns<'db>(
|
||||
&'db self,
|
||||
def: ImplId,
|
||||
) -> (crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>, Diagnostics);
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::impl_self_ty_query)]
|
||||
#[salsa::transparent]
|
||||
fn impl_self_ty_ns<'db>(
|
||||
@ -313,26 +332,10 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
||||
def: ImplId,
|
||||
) -> crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>;
|
||||
|
||||
// FIXME: Make this a non-interned query.
|
||||
#[salsa::invoke_interned(crate::lower_nextsolver::const_param_ty_with_diagnostics_query)]
|
||||
fn const_param_ty_with_diagnostics_ns<'db>(
|
||||
&'db self,
|
||||
def: ConstParamId,
|
||||
) -> (crate::next_solver::Ty<'db>, Diagnostics);
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::const_param_ty_query)]
|
||||
#[salsa::transparent]
|
||||
fn const_param_ty_ns<'db>(&'db self, def: ConstParamId) -> crate::next_solver::Ty<'db>;
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::impl_trait_with_diagnostics_query)]
|
||||
fn impl_trait_with_diagnostics_ns<'db>(
|
||||
&'db self,
|
||||
def: ImplId,
|
||||
) -> Option<(
|
||||
crate::next_solver::EarlyBinder<'db, crate::next_solver::TraitRef<'db>>,
|
||||
Diagnostics,
|
||||
)>;
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::impl_trait_query)]
|
||||
#[salsa::transparent]
|
||||
fn impl_trait_ns<'db>(
|
||||
@ -340,20 +343,6 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
||||
def: ImplId,
|
||||
) -> Option<crate::next_solver::EarlyBinder<'db, crate::next_solver::TraitRef<'db>>>;
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::field_types_with_diagnostics_query)]
|
||||
fn field_types_with_diagnostics_ns<'db>(
|
||||
&'db self,
|
||||
var: VariantId,
|
||||
) -> (
|
||||
Arc<
|
||||
ArenaMap<
|
||||
LocalFieldId,
|
||||
crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>,
|
||||
>,
|
||||
>,
|
||||
Diagnostics,
|
||||
);
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::field_types_query)]
|
||||
#[salsa::transparent]
|
||||
fn field_types_ns<'db>(
|
||||
@ -363,12 +352,6 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
||||
ArenaMap<LocalFieldId, crate::next_solver::EarlyBinder<'db, crate::next_solver::Ty<'db>>>,
|
||||
>;
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::callable_item_signature_query)]
|
||||
fn callable_item_signature_ns<'db>(
|
||||
&'db self,
|
||||
def: CallableDefId,
|
||||
) -> crate::next_solver::EarlyBinder<'db, crate::next_solver::PolyFnSig<'db>>;
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::return_type_impl_traits)]
|
||||
fn return_type_impl_traits_ns<'db>(
|
||||
&'db self,
|
||||
@ -395,21 +378,6 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
||||
&'db self,
|
||||
def: GenericDefId,
|
||||
) -> crate::lower_nextsolver::GenericPredicates<'db>;
|
||||
|
||||
#[salsa::invoke(
|
||||
crate::lower_nextsolver::generic_predicates_without_parent_with_diagnostics_query
|
||||
)]
|
||||
fn generic_predicates_without_parent_with_diagnostics_ns<'db>(
|
||||
&'db self,
|
||||
def: GenericDefId,
|
||||
) -> (crate::lower_nextsolver::GenericPredicates<'db>, Diagnostics);
|
||||
|
||||
#[salsa::invoke(crate::lower_nextsolver::generic_predicates_without_parent_query)]
|
||||
#[salsa::transparent]
|
||||
fn generic_predicates_without_parent_ns<'db>(
|
||||
&'db self,
|
||||
def: GenericDefId,
|
||||
) -> crate::lower_nextsolver::GenericPredicates<'db>;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -46,8 +46,8 @@ use span::Edition;
|
||||
use stdx::never;
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::next_solver::infer::DbInternerInferExt;
|
||||
use crate::next_solver::infer::traits::ObligationCause;
|
||||
use crate::next_solver::{infer::DbInternerInferExt, mapping::NextSolverToChalk};
|
||||
use crate::{
|
||||
AliasEq, AliasTy, Binders, CallableDefId, CallableSig, ConcreteConst, Const, ConstScalar,
|
||||
ConstValue, DomainGoal, FnAbi, GenericArg, ImplTraitId, Interner, Lifetime, LifetimeData,
|
||||
@ -1298,7 +1298,9 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
|
||||
let def = def.0;
|
||||
let sig = db
|
||||
.callable_item_signature(def)
|
||||
.substitute(Interner, &convert_args_for_result(interner, args.as_slice()));
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.to_chalk(interner);
|
||||
|
||||
if f.display_kind.is_source_code() {
|
||||
// `FnDef` is anonymous and there's no surface syntax for it. Show it as a
|
||||
|
@ -329,7 +329,7 @@ where
|
||||
cb(MethodViolationCode::AsyncFn)?;
|
||||
}
|
||||
|
||||
let sig = db.callable_item_signature_ns(func.into());
|
||||
let sig = db.callable_item_signature(func.into());
|
||||
if sig
|
||||
.skip_binder()
|
||||
.inputs()
|
||||
@ -364,7 +364,7 @@ where
|
||||
cb(MethodViolationCode::UndispatchableReceiver)?;
|
||||
}
|
||||
|
||||
let predicates = &*db.generic_predicates_without_parent_ns(func.into());
|
||||
let predicates = &*db.generic_predicates_without_parent(func.into());
|
||||
for pred in predicates {
|
||||
let pred = pred.kind().skip_binder();
|
||||
|
||||
|
@ -1708,6 +1708,7 @@ impl<'db> InferenceContext<'db> {
|
||||
LifetimeElisionKind::Infer,
|
||||
);
|
||||
let mut path_ctx = ctx.at_path(path, node);
|
||||
let interner = DbInterner::conjure();
|
||||
let (resolution, unresolved) = if value_ns {
|
||||
let Some(res) = path_ctx.resolve_path_in_value_ns(HygieneId::ROOT) else {
|
||||
return (self.err_ty(), None);
|
||||
@ -1717,15 +1718,27 @@ impl<'db> InferenceContext<'db> {
|
||||
ValueNs::EnumVariantId(var) => {
|
||||
let substs = path_ctx.substs_from_path(var.into(), true, false);
|
||||
drop(ctx);
|
||||
let ty = self.db.ty(var.lookup(self.db).parent.into());
|
||||
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
|
||||
let args: crate::next_solver::GenericArgs<'_> =
|
||||
substs.to_nextsolver(interner);
|
||||
let ty = self
|
||||
.db
|
||||
.ty(var.lookup(self.db).parent.into())
|
||||
.instantiate(interner, args)
|
||||
.to_chalk(interner);
|
||||
let ty = self.insert_type_vars(ty);
|
||||
return (ty, Some(var.into()));
|
||||
}
|
||||
ValueNs::StructId(strukt) => {
|
||||
let substs = path_ctx.substs_from_path(strukt.into(), true, false);
|
||||
drop(ctx);
|
||||
let ty = self.db.ty(strukt.into());
|
||||
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
|
||||
let args: crate::next_solver::GenericArgs<'_> =
|
||||
substs.to_nextsolver(interner);
|
||||
let ty = self
|
||||
.db
|
||||
.ty(strukt.into())
|
||||
.instantiate(interner, args)
|
||||
.to_chalk(interner);
|
||||
let ty = self.insert_type_vars(ty);
|
||||
return (ty, Some(strukt.into()));
|
||||
}
|
||||
ValueNs::ImplSelf(impl_id) => (TypeNs::SelfType(impl_id), None),
|
||||
@ -1746,22 +1759,29 @@ impl<'db> InferenceContext<'db> {
|
||||
TypeNs::AdtId(AdtId::StructId(strukt)) => {
|
||||
let substs = path_ctx.substs_from_path(strukt.into(), true, false);
|
||||
drop(ctx);
|
||||
let ty = self.db.ty(strukt.into());
|
||||
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let ty = self.db.ty(strukt.into()).instantiate(interner, args).to_chalk(interner);
|
||||
let ty = self.insert_type_vars(ty);
|
||||
forbid_unresolved_segments((ty, Some(strukt.into())), unresolved)
|
||||
}
|
||||
TypeNs::AdtId(AdtId::UnionId(u)) => {
|
||||
let substs = path_ctx.substs_from_path(u.into(), true, false);
|
||||
drop(ctx);
|
||||
let ty = self.db.ty(u.into());
|
||||
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let ty = self.db.ty(u.into()).instantiate(interner, args).to_chalk(interner);
|
||||
let ty = self.insert_type_vars(ty);
|
||||
forbid_unresolved_segments((ty, Some(u.into())), unresolved)
|
||||
}
|
||||
TypeNs::EnumVariantId(var) => {
|
||||
let substs = path_ctx.substs_from_path(var.into(), true, false);
|
||||
drop(ctx);
|
||||
let ty = self.db.ty(var.lookup(self.db).parent.into());
|
||||
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let ty = self
|
||||
.db
|
||||
.ty(var.lookup(self.db).parent.into())
|
||||
.instantiate(interner, args)
|
||||
.to_chalk(interner);
|
||||
let ty = self.insert_type_vars(ty);
|
||||
forbid_unresolved_segments((ty, Some(var.into())), unresolved)
|
||||
}
|
||||
TypeNs::SelfType(impl_id) => {
|
||||
@ -1844,8 +1864,10 @@ impl<'db> InferenceContext<'db> {
|
||||
};
|
||||
let substs = path_ctx.substs_from_path_segment(it.into(), true, None, false);
|
||||
drop(ctx);
|
||||
let ty = self.db.ty(it.into());
|
||||
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
|
||||
let interner = DbInterner::conjure();
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let ty = self.db.ty(it.into()).instantiate(interner, args).to_chalk(interner);
|
||||
let ty = self.insert_type_vars(ty);
|
||||
|
||||
self.resolve_variant_on_alias(ty, unresolved, mod_path)
|
||||
}
|
||||
|
@ -23,13 +23,13 @@ use syntax::ast::RangeOp;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::autoderef::overloaded_deref_ty;
|
||||
use crate::next_solver::ErrorGuaranteed;
|
||||
use crate::next_solver::infer::DefineOpaqueTypes;
|
||||
use crate::next_solver::obligation_ctxt::ObligationCtxt;
|
||||
use crate::next_solver::{DbInterner, ErrorGuaranteed};
|
||||
use crate::{
|
||||
Adjust, Adjustment, AdtId, AutoBorrow, Binders, CallableDefId, CallableSig, DeclContext,
|
||||
DeclOrigin, IncorrectGenericsLenKind, Interner, LifetimeElisionKind, Rawness, Scalar,
|
||||
Substitution, TraitEnvironment, TraitRef, Ty, TyBuilder, TyExt, TyKind, consteval,
|
||||
Adjust, Adjustment, AdtId, AutoBorrow, CallableDefId, CallableSig, DeclContext, DeclOrigin,
|
||||
IncorrectGenericsLenKind, Interner, LifetimeElisionKind, Rawness, Scalar, Substitution,
|
||||
TraitEnvironment, TraitRef, Ty, TyBuilder, TyExt, TyKind, consteval,
|
||||
generics::generics,
|
||||
infer::{
|
||||
AllowTwoPhase, BreakableKind,
|
||||
@ -1481,7 +1481,10 @@ impl<'db> InferenceContext<'db> {
|
||||
|
||||
self.write_method_resolution(tgt_expr, func, subst.clone());
|
||||
|
||||
let method_ty = self.db.value_ty(func.into()).unwrap().substitute(Interner, &subst);
|
||||
let interner = DbInterner::new_with(self.db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = subst.to_nextsolver(interner);
|
||||
let method_ty =
|
||||
self.db.value_ty(func.into()).unwrap().instantiate(interner, args).to_chalk(interner);
|
||||
self.register_obligations_for_call(&method_ty);
|
||||
|
||||
self.infer_expr_coerce(rhs, &Expectation::has_type(rhs_ty.clone()), ExprIsRead::Yes);
|
||||
@ -1800,11 +1803,17 @@ impl<'db> InferenceContext<'db> {
|
||||
self.write_expr_adj(receiver, adjustments.into_boxed_slice());
|
||||
self.write_method_resolution(tgt_expr, func, substs.clone());
|
||||
|
||||
let interner = DbInterner::new_with(self.db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> =
|
||||
substs.to_nextsolver(interner);
|
||||
self.check_method_call(
|
||||
tgt_expr,
|
||||
&[],
|
||||
self.db.value_ty(func.into()).unwrap(),
|
||||
substs,
|
||||
self.db
|
||||
.value_ty(func.into())
|
||||
.unwrap()
|
||||
.instantiate(interner, args)
|
||||
.to_chalk(interner),
|
||||
ty,
|
||||
expected,
|
||||
)
|
||||
@ -1963,11 +1972,16 @@ impl<'db> InferenceContext<'db> {
|
||||
|
||||
let substs = self.substs_for_method_call(tgt_expr, func.into(), generic_args);
|
||||
self.write_method_resolution(tgt_expr, func, substs.clone());
|
||||
let interner = DbInterner::new_with(self.db, None, None);
|
||||
let gen_args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
self.check_method_call(
|
||||
tgt_expr,
|
||||
args,
|
||||
self.db.value_ty(func.into()).expect("we have a function def"),
|
||||
substs,
|
||||
self.db
|
||||
.value_ty(func.into())
|
||||
.expect("we have a function def")
|
||||
.instantiate(interner, gen_args)
|
||||
.to_chalk(interner),
|
||||
ty,
|
||||
expected,
|
||||
)
|
||||
@ -2012,11 +2026,15 @@ impl<'db> InferenceContext<'db> {
|
||||
let recovered = match assoc_func_with_same_name {
|
||||
Some(f) => {
|
||||
let substs = self.substs_for_method_call(tgt_expr, f.into(), generic_args);
|
||||
let interner = DbInterner::new_with(self.db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> =
|
||||
substs.to_nextsolver(interner);
|
||||
let f = self
|
||||
.db
|
||||
.value_ty(f.into())
|
||||
.expect("we have a function def")
|
||||
.substitute(Interner, &substs);
|
||||
.instantiate(interner, args)
|
||||
.to_chalk(interner);
|
||||
let sig = f.callable_sig(self.db).expect("we have a function def");
|
||||
Some((f, sig, true))
|
||||
}
|
||||
@ -2056,12 +2074,10 @@ impl<'db> InferenceContext<'db> {
|
||||
&mut self,
|
||||
tgt_expr: ExprId,
|
||||
args: &[ExprId],
|
||||
method_ty: Binders<Ty>,
|
||||
substs: Substitution,
|
||||
method_ty: Ty,
|
||||
receiver_ty: Ty,
|
||||
expected: &Expectation,
|
||||
) -> Ty {
|
||||
let method_ty = method_ty.substitute(Interner, &substs);
|
||||
self.register_obligations_for_call(&method_ty);
|
||||
let interner = self.table.interner;
|
||||
let ((formal_receiver_ty, param_tys), ret_ty, is_varargs) =
|
||||
|
@ -17,7 +17,10 @@ use crate::{
|
||||
generics::generics,
|
||||
infer::diagnostics::InferenceTyLoweringContext as TyLoweringContext,
|
||||
method_resolution::{self, VisibleFromModule},
|
||||
next_solver::mapping::ChalkToNextSolver,
|
||||
next_solver::{
|
||||
DbInterner,
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk},
|
||||
},
|
||||
to_chalk_trait_id,
|
||||
};
|
||||
|
||||
@ -36,7 +39,9 @@ impl<'db> InferenceContext<'db> {
|
||||
|
||||
self.add_required_obligations_for_value_path(generic_def, &substs);
|
||||
|
||||
let ty = self.db.value_ty(value_def)?.substitute(Interner, &substs);
|
||||
let interner = DbInterner::new_with(self.db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let ty = self.db.value_ty(value_def)?.instantiate(interner, args).to_chalk(interner);
|
||||
let ty = self.process_remote_user_written_ty(ty);
|
||||
Some(ty)
|
||||
}
|
||||
@ -89,9 +94,9 @@ impl<'db> InferenceContext<'db> {
|
||||
|
||||
let generic_def = value_def.to_generic_def_id(self.db);
|
||||
if let GenericDefId::StaticId(_) = generic_def {
|
||||
let interner = DbInterner::new_with(self.db, None, None);
|
||||
// `Static` is the kind of item that can never be generic currently. We can just skip the binders to get its type.
|
||||
let (ty, binders) = self.db.value_ty(value_def)?.into_value_and_skipped_binders();
|
||||
stdx::always!(binders.is_empty(Interner), "non-empty binders for non-generic def",);
|
||||
let ty = self.db.value_ty(value_def)?.skip_binder().to_chalk(interner);
|
||||
return Some(ValuePathResolution::NonGeneric(ty));
|
||||
};
|
||||
|
||||
|
@ -780,7 +780,7 @@ impl<'db> InferenceTable<'db> {
|
||||
}
|
||||
|
||||
pub(crate) fn structurally_resolve_type(&mut self, ty: &Ty) -> Ty {
|
||||
if let TyKind::Alias(..) = ty.kind(Interner) {
|
||||
if let TyKind::Alias(chalk_ir::AliasTy::Projection(..)) = ty.kind(Interner) {
|
||||
self.structurally_normalize_ty(ty)
|
||||
} else {
|
||||
self.resolve_vars_with_obligations(ty.to_nextsolver(self.interner))
|
||||
|
@ -1,18 +1,17 @@
|
||||
use base_db::target::TargetData;
|
||||
use chalk_ir::{AdtId, TyKind};
|
||||
use either::Either;
|
||||
use hir_def::db::DefDatabase;
|
||||
use project_model::{Sysroot, toolchain_info::QueryConfig};
|
||||
use rustc_hash::FxHashMap;
|
||||
use rustc_type_ir::inherent::{GenericArgs as _, Ty as _};
|
||||
use syntax::ToSmolStr;
|
||||
use test_fixture::WithFixture;
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::{
|
||||
Interner, Substitution,
|
||||
db::HirDatabase,
|
||||
layout::{Layout, LayoutError},
|
||||
next_solver::{DbInterner, mapping::ChalkToNextSolver},
|
||||
next_solver::{AdtDef, DbInterner, GenericArgs, mapping::ChalkToNextSolver},
|
||||
setup_tracing,
|
||||
test_db::TestDB,
|
||||
};
|
||||
@ -80,18 +79,18 @@ fn eval_goal(
|
||||
Some(adt_or_type_alias_id)
|
||||
})
|
||||
.unwrap();
|
||||
let goal_ty = match adt_or_type_alias_id {
|
||||
Either::Left(adt_id) => {
|
||||
TyKind::Adt(AdtId(adt_id), Substitution::empty(Interner)).intern(Interner)
|
||||
}
|
||||
Either::Right(ty_id) => {
|
||||
db.ty(ty_id.into()).substitute(Interner, &Substitution::empty(Interner))
|
||||
}
|
||||
};
|
||||
salsa::attach(&db, || {
|
||||
let interner = DbInterner::new_with(&db, None, None);
|
||||
let goal_ty = match adt_or_type_alias_id {
|
||||
Either::Left(adt_id) => crate::next_solver::Ty::new_adt(
|
||||
interner,
|
||||
AdtDef::new(adt_id, interner),
|
||||
GenericArgs::identity_for_item(interner, adt_id.into()),
|
||||
),
|
||||
Either::Right(ty_id) => db.ty(ty_id.into()).instantiate_identity(),
|
||||
};
|
||||
db.layout_of_ty(
|
||||
goal_ty.to_nextsolver(interner),
|
||||
goal_ty,
|
||||
db.trait_environment(match adt_or_type_alias_id {
|
||||
Either::Left(adt) => hir_def::GenericDefId::AdtId(adt),
|
||||
Either::Right(ty) => hir_def::GenericDefId::TypeAliasId(ty),
|
||||
|
@ -578,8 +578,10 @@ impl CallableSig {
|
||||
|
||||
pub fn from_def(db: &dyn HirDatabase, def: FnDefId, substs: &Substitution) -> CallableSig {
|
||||
let callable_def = ToChalk::from_chalk(db, def);
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let sig = db.callable_item_signature(callable_def);
|
||||
sig.substitute(Interner, substs)
|
||||
sig.instantiate(interner, args).skip_binder().to_chalk(interner)
|
||||
}
|
||||
pub fn from_fn_ptr(fn_ptr: &FnPointer) -> CallableSig {
|
||||
CallableSig {
|
||||
|
@ -24,16 +24,15 @@ use chalk_ir::{
|
||||
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
AdtId, AssocItemId, CallableDefId, ConstId, ConstParamId, EnumId, EnumVariantId, FunctionId,
|
||||
GenericDefId, GenericParamId, ImplId, ItemContainerId, LocalFieldId, Lookup, StaticId,
|
||||
StructId, TypeAliasId, TypeOrConstParamId, UnionId, VariantId,
|
||||
AdtId, AssocItemId, ConstId, ConstParamId, EnumId, EnumVariantId, FunctionId, GenericDefId,
|
||||
GenericParamId, ImplId, ItemContainerId, LocalFieldId, Lookup, StaticId, StructId, TypeAliasId,
|
||||
TypeOrConstParamId, UnionId, VariantId,
|
||||
builtin_type::BuiltinType,
|
||||
expr_store::{ExpressionStore, path::Path},
|
||||
hir::generics::{GenericParamDataRef, TypeOrConstParamData, WherePredicate},
|
||||
item_tree::FieldsShape,
|
||||
lang_item::LangItem,
|
||||
resolver::{HasResolver, LifetimeNs, Resolver, TypeNs},
|
||||
signatures::{FunctionSignature, TraitFlags, TypeAliasFlags},
|
||||
signatures::{FunctionSignature, TraitFlags},
|
||||
type_ref::{
|
||||
ConstRef, LifetimeRefId, LiteralConstRef, PathId, TraitBoundModifier,
|
||||
TraitRef as HirTraitRef, TypeBound, TypeRef, TypeRefId,
|
||||
@ -46,10 +45,10 @@ use stdx::{impl_from, never};
|
||||
use triomphe::{Arc, ThinArc};
|
||||
|
||||
use crate::{
|
||||
AliasTy, Binders, BoundVar, CallableSig, Const, DebruijnIndex, DynTy, FnAbi, FnPointer, FnSig,
|
||||
FnSubst, ImplTrait, ImplTraitId, ImplTraits, Interner, Lifetime, LifetimeData,
|
||||
LifetimeOutlives, PolyFnSig, QuantifiedWhereClause, QuantifiedWhereClauses, Substitution,
|
||||
TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, WhereClause, all_super_traits,
|
||||
AliasTy, Binders, BoundVar, Const, DebruijnIndex, DynTy, FnAbi, FnPointer, FnSig, FnSubst,
|
||||
ImplTrait, ImplTraitId, ImplTraits, Interner, Lifetime, LifetimeData, LifetimeOutlives,
|
||||
QuantifiedWhereClause, QuantifiedWhereClauses, Substitution, TraitRef, TraitRefExt, Ty,
|
||||
TyBuilder, TyKind, WhereClause, all_super_traits,
|
||||
consteval::{intern_const_ref, path_to_const, unknown_const, unknown_const_as_generic},
|
||||
db::HirDatabase,
|
||||
error_lifetime,
|
||||
@ -59,7 +58,7 @@ use crate::{
|
||||
path::{PathDiagnosticCallback, PathLoweringContext},
|
||||
},
|
||||
make_binders,
|
||||
mapping::{ToChalk, from_chalk_trait_id, lt_to_placeholder_idx},
|
||||
mapping::{from_chalk_trait_id, lt_to_placeholder_idx},
|
||||
static_lifetime, to_chalk_trait_id, to_placeholder_idx,
|
||||
utils::all_super_trait_refs,
|
||||
variable_kinds_from_iter,
|
||||
@ -825,15 +824,6 @@ impl<'a> TyLoweringContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the signature of a callable item (function, struct or enum variant).
|
||||
pub(crate) fn callable_item_signature_query(db: &dyn HirDatabase, def: CallableDefId) -> PolyFnSig {
|
||||
match def {
|
||||
CallableDefId::FunctionId(f) => fn_sig_for_fn(db, f),
|
||||
CallableDefId::StructId(s) => fn_sig_for_struct_constructor(db, s),
|
||||
CallableDefId::EnumVariantId(e) => fn_sig_for_enum_variant_constructor(db, e),
|
||||
}
|
||||
}
|
||||
|
||||
fn named_associated_type_shorthand_candidates<R>(
|
||||
db: &dyn HirDatabase,
|
||||
// If the type parameter is defined in an impl and we're in a method, there
|
||||
@ -918,7 +908,7 @@ pub(crate) fn field_types_query(
|
||||
db: &dyn HirDatabase,
|
||||
variant_id: VariantId,
|
||||
) -> Arc<ArenaMap<LocalFieldId, Binders<Ty>>> {
|
||||
db.field_types_with_diagnostics(variant_id).0
|
||||
field_types_with_diagnostics_query(db, variant_id).0
|
||||
}
|
||||
|
||||
/// Build the type of all specific fields of a struct or enum variant.
|
||||
@ -1313,208 +1303,6 @@ pub(crate) fn generic_defaults_with_diagnostics_cycle_result(
|
||||
(GenericDefaults(None), None)
|
||||
}
|
||||
|
||||
fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig {
|
||||
let data = db.function_signature(def);
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx_params = TyLoweringContext::new(
|
||||
db,
|
||||
&resolver,
|
||||
&data.store,
|
||||
def.into(),
|
||||
LifetimeElisionKind::for_fn_params(&data),
|
||||
)
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
let params = data.params.iter().map(|&tr| ctx_params.lower_ty(tr));
|
||||
|
||||
let ret = match data.ret_type {
|
||||
Some(ret_type) => {
|
||||
let mut ctx_ret = TyLoweringContext::new(
|
||||
db,
|
||||
&resolver,
|
||||
&data.store,
|
||||
def.into(),
|
||||
LifetimeElisionKind::for_fn_ret(),
|
||||
)
|
||||
.with_impl_trait_mode(ImplTraitLoweringMode::Opaque)
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
ctx_ret.lower_ty(ret_type)
|
||||
}
|
||||
None => TyKind::Tuple(0, Substitution::empty(Interner)).intern(Interner),
|
||||
};
|
||||
let generics = generics(db, def.into());
|
||||
let sig = CallableSig::from_params_and_return(
|
||||
params,
|
||||
ret,
|
||||
data.is_varargs(),
|
||||
if data.is_unsafe() { Safety::Unsafe } else { Safety::Safe },
|
||||
data.abi.as_ref().map_or(FnAbi::Rust, FnAbi::from_symbol),
|
||||
);
|
||||
make_binders(db, &generics, sig)
|
||||
}
|
||||
|
||||
/// Build the declared type of a function. This should not need to look at the
|
||||
/// function body.
|
||||
fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> {
|
||||
let generics = generics(db, def.into());
|
||||
let substs = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
make_binders(
|
||||
db,
|
||||
&generics,
|
||||
TyKind::FnDef(CallableDefId::FunctionId(def).to_chalk(db), substs).intern(Interner),
|
||||
)
|
||||
}
|
||||
|
||||
/// Build the declared type of a const.
|
||||
fn type_for_const(db: &dyn HirDatabase, def: ConstId) -> Binders<Ty> {
|
||||
let data = db.const_signature(def);
|
||||
let generics = generics(db, def.into());
|
||||
let resolver = def.resolver(db);
|
||||
let parent = def.loc(db).container;
|
||||
let mut ctx = TyLoweringContext::new(
|
||||
db,
|
||||
&resolver,
|
||||
&data.store,
|
||||
def.into(),
|
||||
LifetimeElisionKind::for_const(parent),
|
||||
)
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
|
||||
make_binders(db, &generics, ctx.lower_ty(data.type_ref))
|
||||
}
|
||||
|
||||
/// Build the declared type of a static.
|
||||
fn type_for_static(db: &dyn HirDatabase, def: StaticId) -> Binders<Ty> {
|
||||
let data = db.static_signature(def);
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx = TyLoweringContext::new(
|
||||
db,
|
||||
&resolver,
|
||||
&data.store,
|
||||
def.into(),
|
||||
LifetimeElisionKind::Elided(static_lifetime()),
|
||||
);
|
||||
|
||||
Binders::empty(Interner, ctx.lower_ty(data.type_ref))
|
||||
}
|
||||
|
||||
fn fn_sig_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> PolyFnSig {
|
||||
let field_tys = db.field_types(def.into());
|
||||
let params = field_tys.iter().map(|(_, ty)| ty.skip_binders().clone());
|
||||
let (ret, binders) = type_for_adt(db, def.into()).into_value_and_skipped_binders();
|
||||
Binders::new(
|
||||
binders,
|
||||
CallableSig::from_params_and_return(params, ret, false, Safety::Safe, FnAbi::RustCall),
|
||||
)
|
||||
}
|
||||
|
||||
/// Build the type of a tuple struct constructor.
|
||||
fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Option<Binders<Ty>> {
|
||||
let struct_data = def.fields(db);
|
||||
match struct_data.shape {
|
||||
FieldsShape::Record => None,
|
||||
FieldsShape::Unit => Some(type_for_adt(db, def.into())),
|
||||
FieldsShape::Tuple => {
|
||||
let generics = generics(db, AdtId::from(def).into());
|
||||
let substs = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
Some(make_binders(
|
||||
db,
|
||||
&generics,
|
||||
TyKind::FnDef(CallableDefId::StructId(def).to_chalk(db), substs).intern(Interner),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fn_sig_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -> PolyFnSig {
|
||||
let field_tys = db.field_types(def.into());
|
||||
let params = field_tys.iter().map(|(_, ty)| ty.skip_binders().clone());
|
||||
let parent = def.lookup(db).parent;
|
||||
let (ret, binders) = type_for_adt(db, parent.into()).into_value_and_skipped_binders();
|
||||
Binders::new(
|
||||
binders,
|
||||
CallableSig::from_params_and_return(params, ret, false, Safety::Safe, FnAbi::RustCall),
|
||||
)
|
||||
}
|
||||
|
||||
/// Build the type of a tuple enum variant constructor.
|
||||
fn type_for_enum_variant_constructor(
|
||||
db: &dyn HirDatabase,
|
||||
def: EnumVariantId,
|
||||
) -> Option<Binders<Ty>> {
|
||||
let e = def.lookup(db).parent;
|
||||
match def.fields(db).shape {
|
||||
FieldsShape::Record => None,
|
||||
FieldsShape::Unit => Some(type_for_adt(db, e.into())),
|
||||
FieldsShape::Tuple => {
|
||||
let generics = generics(db, e.into());
|
||||
let substs = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
Some(make_binders(
|
||||
db,
|
||||
&generics,
|
||||
TyKind::FnDef(CallableDefId::EnumVariantId(def).to_chalk(db), substs)
|
||||
.intern(Interner),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[salsa_macros::tracked(cycle_result = type_for_adt_cycle_result)]
|
||||
fn type_for_adt_tracked(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> {
|
||||
type_for_adt(db, adt)
|
||||
}
|
||||
|
||||
fn type_for_adt_cycle_result(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> {
|
||||
let generics = generics(db, adt.into());
|
||||
make_binders(db, &generics, TyKind::Error.intern(Interner))
|
||||
}
|
||||
|
||||
fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> {
|
||||
let generics = generics(db, adt.into());
|
||||
let subst = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
let ty = TyKind::Adt(crate::AdtId(adt), subst).intern(Interner);
|
||||
make_binders(db, &generics, ty)
|
||||
}
|
||||
|
||||
pub(crate) fn type_for_type_alias_with_diagnostics_query(
|
||||
db: &dyn HirDatabase,
|
||||
t: TypeAliasId,
|
||||
) -> (Binders<Ty>, Diagnostics) {
|
||||
let generics = generics(db, t.into());
|
||||
let type_alias_data = db.type_alias_signature(t);
|
||||
let mut diags = None;
|
||||
let inner = if type_alias_data.flags.contains(TypeAliasFlags::IS_EXTERN) {
|
||||
TyKind::Foreign(crate::to_foreign_def_id(t)).intern(Interner)
|
||||
} else {
|
||||
let resolver = t.resolver(db);
|
||||
let alias = db.type_alias_signature(t);
|
||||
let mut ctx = TyLoweringContext::new(
|
||||
db,
|
||||
&resolver,
|
||||
&alias.store,
|
||||
t.into(),
|
||||
LifetimeElisionKind::AnonymousReportError,
|
||||
)
|
||||
.with_impl_trait_mode(ImplTraitLoweringMode::Opaque)
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
let res = alias
|
||||
.ty
|
||||
.map(|type_ref| ctx.lower_ty(type_ref))
|
||||
.unwrap_or_else(|| TyKind::Error.intern(Interner));
|
||||
diags = create_diagnostics(ctx.diagnostics);
|
||||
res
|
||||
};
|
||||
|
||||
(make_binders(db, &generics, inner), diags)
|
||||
}
|
||||
|
||||
pub(crate) fn type_for_type_alias_with_diagnostics_cycle_result(
|
||||
db: &dyn HirDatabase,
|
||||
adt: TypeAliasId,
|
||||
) -> (Binders<Ty>, Diagnostics) {
|
||||
let generics = generics(db, adt.into());
|
||||
(make_binders(db, &generics, TyKind::Error.intern(Interner)), None)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum TyDefId {
|
||||
BuiltinType(BuiltinType),
|
||||
@ -1547,31 +1335,8 @@ impl ValueTyDefId {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the declared type of an item. This depends on the namespace; e.g. for
|
||||
/// `struct Foo(usize)`, we have two types: The type of the struct itself, and
|
||||
/// the constructor function `(usize) -> Foo` which lives in the values
|
||||
/// namespace.
|
||||
pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders<Ty> {
|
||||
match def {
|
||||
TyDefId::BuiltinType(it) => Binders::empty(Interner, TyBuilder::builtin(it)),
|
||||
TyDefId::AdtId(it) => type_for_adt_tracked(db, it),
|
||||
TyDefId::TypeAliasId(it) => db.type_for_type_alias_with_diagnostics(it).0,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn value_ty_query(db: &dyn HirDatabase, def: ValueTyDefId) -> Option<Binders<Ty>> {
|
||||
match def {
|
||||
ValueTyDefId::FunctionId(it) => Some(type_for_fn(db, it)),
|
||||
ValueTyDefId::StructId(it) => type_for_struct_constructor(db, it),
|
||||
ValueTyDefId::UnionId(it) => Some(type_for_adt(db, it.into())),
|
||||
ValueTyDefId::EnumVariantId(it) => type_for_enum_variant_constructor(db, it),
|
||||
ValueTyDefId::ConstId(it) => Some(type_for_const(db, it)),
|
||||
ValueTyDefId::StaticId(it) => Some(type_for_static(db, it)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn impl_self_ty_query(db: &dyn HirDatabase, impl_id: ImplId) -> Binders<Ty> {
|
||||
db.impl_self_ty_with_diagnostics(impl_id).0
|
||||
impl_self_ty_with_diagnostics_query(db, impl_id).0
|
||||
}
|
||||
|
||||
pub(crate) fn impl_self_ty_with_diagnostics_query(
|
||||
@ -1595,16 +1360,8 @@ pub(crate) fn impl_self_ty_with_diagnostics_query(
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn impl_self_ty_with_diagnostics_cycle_result(
|
||||
db: &dyn HirDatabase,
|
||||
impl_id: ImplId,
|
||||
) -> (Binders<Ty>, Diagnostics) {
|
||||
let generics = generics(db, impl_id.into());
|
||||
(make_binders(db, &generics, TyKind::Error.intern(Interner)), None)
|
||||
}
|
||||
|
||||
pub(crate) fn const_param_ty_query(db: &dyn HirDatabase, def: ConstParamId) -> Ty {
|
||||
db.const_param_ty_with_diagnostics(def).0
|
||||
const_param_ty_with_diagnostics_query(db, def).0
|
||||
}
|
||||
|
||||
// returns None if def is a type arg
|
||||
@ -1632,16 +1389,16 @@ pub(crate) fn const_param_ty_with_diagnostics_query(
|
||||
(ty, create_diagnostics(ctx.diagnostics))
|
||||
}
|
||||
|
||||
pub(crate) fn const_param_ty_with_diagnostics_cycle_result(
|
||||
pub(crate) fn const_param_ty_cycle_result(
|
||||
_: &dyn HirDatabase,
|
||||
_: crate::db::HirDatabaseData,
|
||||
_: ConstParamId,
|
||||
) -> (Ty, Diagnostics) {
|
||||
(TyKind::Error.intern(Interner), None)
|
||||
) -> Ty {
|
||||
TyKind::Error.intern(Interner)
|
||||
}
|
||||
|
||||
pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option<Binders<TraitRef>> {
|
||||
db.impl_trait_with_diagnostics(impl_id).map(|it| it.0)
|
||||
impl_trait_with_diagnostics_query(db, impl_id).map(|it| it.0)
|
||||
}
|
||||
|
||||
pub(crate) fn impl_trait_with_diagnostics_query(
|
||||
|
@ -28,6 +28,10 @@ use crate::{
|
||||
error_lifetime,
|
||||
generics::{Generics, generics},
|
||||
lower::{LifetimeElisionKind, named_associated_type_shorthand_candidates},
|
||||
next_solver::{
|
||||
DbInterner,
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk},
|
||||
},
|
||||
static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
|
||||
utils::associated_type_by_name_including_super_traits,
|
||||
};
|
||||
@ -256,7 +260,8 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
||||
}
|
||||
ParamLoweringMode::Variable => TyBuilder::impl_self_ty(self.ctx.db, impl_id)
|
||||
.fill_with_bound_vars(self.ctx.in_binders, 0)
|
||||
.build(),
|
||||
.build(DbInterner::conjure())
|
||||
.to_chalk(DbInterner::conjure()),
|
||||
}
|
||||
}
|
||||
TypeNs::AdtSelfType(adt) => {
|
||||
@ -267,7 +272,9 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
||||
generics.bound_vars_subst(self.ctx.db, self.ctx.in_binders)
|
||||
}
|
||||
};
|
||||
self.ctx.db.ty(adt.into()).substitute(Interner, &substs)
|
||||
let interner = DbInterner::conjure();
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
self.ctx.db.ty(adt.into()).instantiate(interner, args).to_chalk(interner)
|
||||
}
|
||||
|
||||
TypeNs::AdtId(it) => self.lower_path_inner(it.into(), infer_args),
|
||||
@ -537,7 +544,9 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
||||
TyDefId::TypeAliasId(it) => it.into(),
|
||||
};
|
||||
let substs = self.substs_from_path_segment(generic_def, infer_args, None, false);
|
||||
self.ctx.db.ty(typeable).substitute(Interner, &substs)
|
||||
let interner = DbInterner::conjure();
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
self.ctx.db.ty(typeable).instantiate(interner, args).to_chalk(interner)
|
||||
}
|
||||
|
||||
/// Collect generic arguments from a path into a `Substs`. See also
|
||||
|
@ -904,7 +904,7 @@ pub(crate) fn impl_trait_query<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
impl_id: ImplId,
|
||||
) -> Option<EarlyBinder<'db, TraitRef<'db>>> {
|
||||
db.impl_trait_with_diagnostics_ns(impl_id).map(|it| it.0)
|
||||
db.impl_trait_with_diagnostics(impl_id).map(|it| it.0)
|
||||
}
|
||||
|
||||
pub(crate) fn impl_trait_with_diagnostics_query<'db>(
|
||||
@ -986,7 +986,7 @@ pub(crate) fn ty_query<'db>(db: &'db dyn HirDatabase, def: TyDefId) -> EarlyBind
|
||||
AdtDef::new(it, interner),
|
||||
GenericArgs::identity_for_item(interner, it.into()),
|
||||
)),
|
||||
TyDefId::TypeAliasId(it) => db.type_for_type_alias_with_diagnostics_ns(it).0,
|
||||
TyDefId::TypeAliasId(it) => db.type_for_type_alias_with_diagnostics(it).0,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1131,7 +1131,7 @@ pub(crate) fn impl_self_ty_query<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
impl_id: ImplId,
|
||||
) -> EarlyBinder<'db, Ty<'db>> {
|
||||
db.impl_self_ty_with_diagnostics_ns(impl_id).0
|
||||
db.impl_self_ty_with_diagnostics(impl_id).0
|
||||
}
|
||||
|
||||
pub(crate) fn impl_self_ty_with_diagnostics_query<'db>(
|
||||
@ -1162,7 +1162,7 @@ pub(crate) fn impl_self_ty_with_diagnostics_cycle_result(
|
||||
}
|
||||
|
||||
pub(crate) fn const_param_ty_query<'db>(db: &'db dyn HirDatabase, def: ConstParamId) -> Ty<'db> {
|
||||
db.const_param_ty_with_diagnostics_ns(def).0
|
||||
db.const_param_ty_with_diagnostics(def).0
|
||||
}
|
||||
|
||||
// returns None if def is a type arg
|
||||
@ -1191,11 +1191,21 @@ pub(crate) fn const_param_ty_with_diagnostics_query<'db>(
|
||||
(ty, create_diagnostics(ctx.diagnostics))
|
||||
}
|
||||
|
||||
pub(crate) fn const_param_ty_with_diagnostics_cycle_result<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
_: crate::db::HirDatabaseData,
|
||||
def: ConstParamId,
|
||||
) -> (Ty<'db>, Diagnostics) {
|
||||
let resolver = def.parent().resolver(db);
|
||||
let interner = DbInterner::new_with(db, Some(resolver.krate()), None);
|
||||
(Ty::new_error(interner, ErrorGuaranteed), None)
|
||||
}
|
||||
|
||||
pub(crate) fn field_types_query<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
variant_id: VariantId,
|
||||
) -> Arc<ArenaMap<LocalFieldId, EarlyBinder<'db, Ty<'db>>>> {
|
||||
db.field_types_with_diagnostics_ns(variant_id).0
|
||||
db.field_types_with_diagnostics(variant_id).0
|
||||
}
|
||||
|
||||
/// Build the type of all specific fields of a struct or enum variant.
|
||||
@ -1960,7 +1970,8 @@ fn named_associated_type_shorthand_candidates<'db, R>(
|
||||
let mut search = |t: TraitRef<'db>| -> Option<R> {
|
||||
let trait_id = t.def_id.0;
|
||||
let mut checked_traits = FxHashSet::default();
|
||||
let mut check_trait = |trait_id: TraitId| {
|
||||
let mut check_trait = |trait_ref: TraitRef<'db>| {
|
||||
let trait_id = trait_ref.def_id.0;
|
||||
let name = &db.trait_signature(trait_id).name;
|
||||
tracing::debug!(?trait_id, ?name);
|
||||
if !checked_traits.insert(trait_id) {
|
||||
@ -1971,37 +1982,39 @@ fn named_associated_type_shorthand_candidates<'db, R>(
|
||||
tracing::debug!(?data.items);
|
||||
for (name, assoc_id) in &data.items {
|
||||
if let &AssocItemId::TypeAliasId(alias) = assoc_id
|
||||
&& let Some(ty) = check_alias(name, t, alias)
|
||||
&& let Some(ty) = check_alias(name, trait_ref, alias)
|
||||
{
|
||||
return Some(ty);
|
||||
}
|
||||
}
|
||||
None
|
||||
};
|
||||
let mut stack: SmallVec<[_; 4]> = smallvec![trait_id];
|
||||
while let Some(trait_def_id) = stack.pop() {
|
||||
if let Some(alias) = check_trait(trait_def_id) {
|
||||
let mut stack: SmallVec<[_; 4]> = smallvec![t];
|
||||
while let Some(trait_ref) = stack.pop() {
|
||||
if let Some(alias) = check_trait(trait_ref) {
|
||||
return Some(alias);
|
||||
}
|
||||
for pred in generic_predicates_filtered_by(
|
||||
db,
|
||||
GenericDefId::TraitId(trait_def_id),
|
||||
GenericDefId::TraitId(trait_ref.def_id.0),
|
||||
PredicateFilter::SelfTrait,
|
||||
// We are likely in the midst of lowering generic predicates of `def`.
|
||||
// So, if we allow `pred == def` we might fall into an infinite recursion.
|
||||
// Actually, we have already checked for the case `pred == def` above as we started
|
||||
// with a stack including `trait_id`
|
||||
|pred| pred != def && pred == GenericDefId::TraitId(trait_def_id),
|
||||
|pred| pred != def && pred == GenericDefId::TraitId(trait_ref.def_id.0),
|
||||
)
|
||||
.0
|
||||
.deref()
|
||||
{
|
||||
tracing::debug!(?pred);
|
||||
let trait_id = match pred.kind().skip_binder() {
|
||||
rustc_type_ir::ClauseKind::Trait(pred) => pred.def_id(),
|
||||
let sup_trait_ref = match pred.kind().skip_binder() {
|
||||
rustc_type_ir::ClauseKind::Trait(pred) => pred.trait_ref,
|
||||
_ => continue,
|
||||
};
|
||||
stack.push(trait_id.0);
|
||||
let sup_trait_ref =
|
||||
EarlyBinder::bind(sup_trait_ref).instantiate(interner, trait_ref.args);
|
||||
stack.push(sup_trait_ref);
|
||||
}
|
||||
tracing::debug!(?stack);
|
||||
}
|
||||
|
@ -1697,8 +1697,10 @@ fn is_valid_impl_method_candidate(
|
||||
return IsValidCandidate::NotVisible;
|
||||
}
|
||||
let self_ty_matches = table.run_in_snapshot(|table| {
|
||||
let expected_self_ty =
|
||||
TyBuilder::impl_self_ty(db, impl_id).fill_with_inference_vars(table).build();
|
||||
let expected_self_ty = TyBuilder::impl_self_ty(db, impl_id)
|
||||
.fill_with_inference_vars(table)
|
||||
.build(DbInterner::conjure())
|
||||
.to_chalk(DbInterner::conjure());
|
||||
table.unify(&expected_self_ty, self_ty)
|
||||
});
|
||||
if !self_ty_matches {
|
||||
@ -1744,9 +1746,13 @@ fn is_valid_trait_method_candidate(
|
||||
.fill_with_inference_vars(table)
|
||||
.build();
|
||||
|
||||
let args: crate::next_solver::GenericArgs<'_> =
|
||||
fn_subst.to_nextsolver(table.interner);
|
||||
let sig = db.callable_item_signature(fn_id.into());
|
||||
let expected_receiver =
|
||||
sig.map(|s| s.params()[0].clone()).substitute(Interner, &fn_subst);
|
||||
let expected_receiver = sig
|
||||
.map_bound(|s| s.skip_binder().inputs_and_output.as_slice()[0])
|
||||
.instantiate(table.interner, args)
|
||||
.to_chalk(table.interner);
|
||||
|
||||
// FIXME: Clean up this mess with some context struct like rustc's `ProbeContext`
|
||||
let variance = match mode {
|
||||
@ -1831,9 +1837,12 @@ fn is_valid_impl_fn_candidate(
|
||||
let fn_subst: crate::Substitution =
|
||||
table.infer_ctxt.fresh_args_for_item(fn_id.into()).to_chalk(table.interner);
|
||||
|
||||
let args: crate::next_solver::GenericArgs<'_> = fn_subst.to_nextsolver(table.interner);
|
||||
let sig = db.callable_item_signature(fn_id.into());
|
||||
let expected_receiver =
|
||||
sig.map(|s| s.params()[0].clone()).substitute(Interner, &fn_subst);
|
||||
let expected_receiver = sig
|
||||
.map_bound(|s| s.skip_binder().inputs_and_output.as_slice()[0])
|
||||
.instantiate(table.interner, args)
|
||||
.to_chalk(table.interner);
|
||||
|
||||
check_that!(table.unify(receiver_ty, &expected_receiver));
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ use hir_expand::name::Name;
|
||||
use intern::{Symbol, sym};
|
||||
use stdx::never;
|
||||
|
||||
use crate::next_solver::mapping::NextSolverToChalk;
|
||||
use crate::{
|
||||
DropGlue,
|
||||
display::DisplayTarget,
|
||||
@ -1371,9 +1372,8 @@ impl Evaluator<'_> {
|
||||
result = (l as i8).cmp(&(r as i8));
|
||||
}
|
||||
if let Some(e) = LangItem::Ordering.resolve_enum(self.db, self.crate_id) {
|
||||
let ty = self.db.ty(e.into());
|
||||
let r = self
|
||||
.compute_discriminant(ty.skip_binders().clone(), &[result as i8 as u8])?;
|
||||
let ty = self.db.ty(e.into()).skip_binder().to_chalk(interner);
|
||||
let r = self.compute_discriminant(ty.clone(), &[result as i8 as u8])?;
|
||||
destination.write_from_bytes(self, &r.to_le_bytes()[0..destination.size])?;
|
||||
Ok(())
|
||||
} else {
|
||||
|
@ -43,7 +43,10 @@ use crate::{
|
||||
Terminator, TerminatorKind, TupleFieldId, Ty, UnOp, VariantId, intern_const_scalar,
|
||||
return_slot,
|
||||
},
|
||||
next_solver::{DbInterner, mapping::ChalkToNextSolver},
|
||||
next_solver::{
|
||||
DbInterner,
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk},
|
||||
},
|
||||
static_lifetime,
|
||||
traits::FnTrait,
|
||||
utils::ClosureSubst,
|
||||
@ -2207,8 +2210,13 @@ pub fn lower_to_mir(
|
||||
// otherwise it's an inline const, and has no parameter
|
||||
if let DefWithBodyId::FunctionId(fid) = owner {
|
||||
let substs = TyBuilder::placeholder_subst(db, fid);
|
||||
let callable_sig =
|
||||
db.callable_item_signature(fid.into()).substitute(Interner, &substs);
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let callable_sig = db
|
||||
.callable_item_signature(fid.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.to_chalk(interner);
|
||||
let mut params = callable_sig.params().iter();
|
||||
let self_param = body.self_param.and_then(|id| Some((id, params.next()?.clone())));
|
||||
break 'b ctx.lower_params_and_bindings(
|
||||
|
@ -1091,23 +1091,21 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
|
||||
ItemContainerId::ImplId(it) => it,
|
||||
_ => panic!("assoc ty value should be in impl"),
|
||||
};
|
||||
self.db().ty_ns(id.into())
|
||||
self.db().ty(id.into())
|
||||
}
|
||||
SolverDefId::AdtId(id) => self.db().ty_ns(id.into()),
|
||||
SolverDefId::AdtId(id) => self.db().ty(id.into()),
|
||||
// FIXME(next-solver): This uses the types of `query mir_borrowck` in rustc.
|
||||
//
|
||||
// We currently always use the type from HIR typeck which ignores regions. This
|
||||
// should be fine.
|
||||
SolverDefId::InternedOpaqueTyId(_) => self.type_of_opaque_hir_typeck(def_id),
|
||||
SolverDefId::FunctionId(id) => self.db.value_ty_ns(id.into()).unwrap(),
|
||||
SolverDefId::FunctionId(id) => self.db.value_ty(id.into()).unwrap(),
|
||||
SolverDefId::Ctor(id) => {
|
||||
let id = match id {
|
||||
Ctor::Struct(id) => id.into(),
|
||||
Ctor::Enum(id) => id.into(),
|
||||
};
|
||||
self.db
|
||||
.value_ty_ns(id)
|
||||
.expect("`SolverDefId::Ctor` should have a function-like ctor")
|
||||
self.db.value_ty(id).expect("`SolverDefId::Ctor` should have a function-like ctor")
|
||||
}
|
||||
_ => panic!("Unexpected def_id `{def_id:?}` provided for `type_of`"),
|
||||
}
|
||||
@ -1227,7 +1225,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
|
||||
self,
|
||||
def_id: Self::FunctionId,
|
||||
) -> EarlyBinder<Self, rustc_type_ir::Binder<Self, rustc_type_ir::FnSig<Self>>> {
|
||||
self.db().callable_item_signature_ns(def_id.0)
|
||||
self.db().callable_item_signature(def_id.0)
|
||||
}
|
||||
|
||||
fn coroutine_movability(self, def_id: Self::CoroutineId) -> rustc_ast_ir::Movability {
|
||||
@ -1322,7 +1320,7 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
|
||||
self,
|
||||
def_id: Self::DefId,
|
||||
) -> EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>> {
|
||||
let predicates = self.db().generic_predicates_without_parent_ns(def_id.try_into().unwrap());
|
||||
let predicates = self.db().generic_predicates_without_parent(def_id.try_into().unwrap());
|
||||
let predicates: Vec<_> = predicates.iter().cloned().collect();
|
||||
EarlyBinder::bind(predicates.into_iter())
|
||||
}
|
||||
|
@ -575,6 +575,17 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db, T: NextSolverToChalk<'db, U>, U: HasInterner<Interner = Interner>>
|
||||
NextSolverToChalk<'db, chalk_ir::Binders<U>> for rustc_type_ir::Binder<DbInterner<'db>, T>
|
||||
{
|
||||
fn to_chalk(self, interner: DbInterner<'db>) -> chalk_ir::Binders<U> {
|
||||
chalk_ir::Binders::new(
|
||||
self.bound_vars().to_chalk(interner),
|
||||
self.skip_binder().to_chalk(interner),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> ChalkToNextSolver<'db, BoundVarKinds> for chalk_ir::VariableKinds<Interner> {
|
||||
fn to_nextsolver(&self, interner: DbInterner<'db>) -> BoundVarKinds {
|
||||
BoundVarKinds::new_from_iter(
|
||||
@ -584,6 +595,12 @@ impl<'db> ChalkToNextSolver<'db, BoundVarKinds> for chalk_ir::VariableKinds<Inte
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> NextSolverToChalk<'db, chalk_ir::VariableKinds<Interner>> for BoundVarKinds {
|
||||
fn to_chalk(self, interner: DbInterner<'db>) -> chalk_ir::VariableKinds<Interner> {
|
||||
chalk_ir::VariableKinds::from_iter(Interner, self.iter().map(|v| v.to_chalk(interner)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> ChalkToNextSolver<'db, BoundVarKind> for chalk_ir::VariableKind<Interner> {
|
||||
fn to_nextsolver(&self, interner: DbInterner<'db>) -> BoundVarKind {
|
||||
match self {
|
||||
@ -594,6 +611,18 @@ impl<'db> ChalkToNextSolver<'db, BoundVarKind> for chalk_ir::VariableKind<Intern
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> NextSolverToChalk<'db, chalk_ir::VariableKind<Interner>> for BoundVarKind {
|
||||
fn to_chalk(self, interner: DbInterner<'db>) -> chalk_ir::VariableKind<Interner> {
|
||||
match self {
|
||||
BoundVarKind::Ty(_) => chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
|
||||
BoundVarKind::Region(_) => chalk_ir::VariableKind::Lifetime,
|
||||
BoundVarKind::Const => {
|
||||
chalk_ir::VariableKind::Const(chalk_ir::TyKind::Error.intern(Interner))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> ChalkToNextSolver<'db, GenericArg<'db>> for chalk_ir::GenericArg<Interner> {
|
||||
fn to_nextsolver(&self, interner: DbInterner<'db>) -> GenericArg<'db> {
|
||||
match self.data(Interner) {
|
||||
@ -1233,6 +1262,22 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> NextSolverToChalk<'db, crate::CallableSig> for rustc_type_ir::FnSig<DbInterner<'db>> {
|
||||
fn to_chalk(self, interner: DbInterner<'db>) -> crate::CallableSig {
|
||||
crate::CallableSig {
|
||||
abi: self.abi,
|
||||
is_varargs: self.c_variadic,
|
||||
safety: match self.safety {
|
||||
super::abi::Safety::Safe => chalk_ir::Safety::Safe,
|
||||
super::abi::Safety::Unsafe => chalk_ir::Safety::Unsafe,
|
||||
},
|
||||
params_and_return: triomphe::Arc::from_iter(
|
||||
self.inputs_and_output.iter().map(|ty| convert_ty_for_result(interner, ty)),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn convert_canonical_args_for_result<'db>(
|
||||
interner: DbInterner<'db>,
|
||||
args: Canonical<'db, Vec<GenericArg<'db>>>,
|
||||
|
@ -504,14 +504,11 @@ impl SomeStruct {
|
||||
"crate_local_def_map",
|
||||
"trait_impls_in_crate_shim",
|
||||
"attrs_shim",
|
||||
"impl_trait_with_diagnostics_shim",
|
||||
"impl_signature_shim",
|
||||
"impl_signature_with_source_map_shim",
|
||||
"impl_self_ty_with_diagnostics_shim",
|
||||
"struct_signature_shim",
|
||||
"struct_signature_with_source_map_shim",
|
||||
"attrs_shim",
|
||||
"type_for_adt_tracked",
|
||||
]
|
||||
"#]],
|
||||
);
|
||||
@ -609,9 +606,6 @@ fn main() {
|
||||
"trait_impls_in_crate_shim",
|
||||
"impl_trait_with_diagnostics_shim",
|
||||
"impl_self_ty_with_diagnostics_shim",
|
||||
"type_for_adt_tracked",
|
||||
"impl_trait_with_diagnostics_ns_shim",
|
||||
"impl_self_ty_with_diagnostics_ns_shim",
|
||||
"generic_predicates_ns_shim",
|
||||
"value_ty_shim",
|
||||
"generic_predicates_shim",
|
||||
@ -700,8 +694,6 @@ fn main() {
|
||||
"trait_impls_in_crate_shim",
|
||||
"impl_trait_with_diagnostics_shim",
|
||||
"impl_self_ty_with_diagnostics_shim",
|
||||
"impl_trait_with_diagnostics_ns_shim",
|
||||
"impl_self_ty_with_diagnostics_ns_shim",
|
||||
"generic_predicates_ns_shim",
|
||||
"generic_predicates_shim",
|
||||
]
|
||||
|
@ -2053,7 +2053,7 @@ impl dyn Error + Send {
|
||||
// ^^^^ expected Box<dyn Error + '?>, got Box<dyn Error + Send + '?>
|
||||
// FIXME, type mismatch should not occur
|
||||
<dyn Error>::downcast(err).map_err(|_| loop {})
|
||||
//^^^^^^^^^^^^^^^^^^^^^ type: fn downcast<{unknown}>(Box<dyn Error + '?>) -> Result<Box<{unknown}>, Box<dyn Error + '?>>
|
||||
//^^^^^^^^^^^^^^^^^^^^^ type: fn downcast<{unknown}>(Box<dyn Error + 'static>) -> Result<Box<{unknown}>, Box<dyn Error + 'static>>
|
||||
}
|
||||
}
|
||||
"#,
|
||||
|
@ -1487,8 +1487,8 @@ fn test(x: Box<dyn Trait<u64>>, y: &dyn Trait<u64>) {
|
||||
268..269 'x': Box<dyn Trait<u64> + '?>
|
||||
275..276 'y': &'? (dyn Trait<u64> + '?)
|
||||
286..287 'z': Box<dyn Trait<u64> + '?>
|
||||
290..293 'bar': fn bar() -> Box<dyn Trait<u64> + '?>
|
||||
290..295 'bar()': Box<dyn Trait<u64> + '?>
|
||||
290..293 'bar': fn bar() -> Box<dyn Trait<u64> + 'static>
|
||||
290..295 'bar()': Box<dyn Trait<u64> + 'static>
|
||||
301..302 'x': Box<dyn Trait<u64> + '?>
|
||||
301..308 'x.foo()': u64
|
||||
314..315 'y': &'? (dyn Trait<u64> + '?)
|
||||
@ -1535,7 +1535,7 @@ fn test(s: S<u32, i32>) {
|
||||
251..252 's': S<u32, i32>
|
||||
267..289 '{ ...z(); }': ()
|
||||
273..274 's': S<u32, i32>
|
||||
273..280 's.bar()': &'? (dyn Trait<u32, i32> + '?)
|
||||
273..280 's.bar()': &'? (dyn Trait<u32, i32> + 'static)
|
||||
273..286 's.bar().baz()': (u32, i32)
|
||||
"#]],
|
||||
);
|
||||
@ -1568,8 +1568,8 @@ fn test(x: Trait, y: &Trait) -> u64 {
|
||||
106..107 'x': dyn Trait + '?
|
||||
113..114 'y': &'? (dyn Trait + '?)
|
||||
124..125 'z': dyn Trait + '?
|
||||
128..131 'bar': fn bar() -> dyn Trait + '?
|
||||
128..133 'bar()': dyn Trait + '?
|
||||
128..131 'bar': fn bar() -> dyn Trait + 'static
|
||||
128..133 'bar()': dyn Trait + 'static
|
||||
139..140 'x': dyn Trait + '?
|
||||
139..146 'x.foo()': u64
|
||||
152..153 'y': &'? (dyn Trait + '?)
|
||||
@ -1597,7 +1597,7 @@ fn main() {
|
||||
47..48 '_': &'? (dyn Fn(S) + '?)
|
||||
58..60 '{}': ()
|
||||
71..105 '{ ...()); }': ()
|
||||
77..78 'f': fn f(&'? (dyn Fn(S) + '?))
|
||||
77..78 'f': fn f(&'? (dyn Fn(S) + 'static))
|
||||
77..102 'f(&|nu...foo())': ()
|
||||
79..101 '&|numb....foo()': &'? impl Fn(S)
|
||||
80..101 '|numbe....foo()': impl Fn(S)
|
||||
@ -2952,7 +2952,7 @@ fn test(x: &dyn Foo) {
|
||||
34..36 '{}': ()
|
||||
46..47 'x': &'? (dyn Foo + '?)
|
||||
59..74 '{ foo(x); }': ()
|
||||
65..68 'foo': fn foo(&'? (dyn Foo + '?))
|
||||
65..68 'foo': fn foo(&'? (dyn Foo + 'static))
|
||||
65..71 'foo(x)': ()
|
||||
69..70 'x': &'? (dyn Foo + '?)
|
||||
"#]],
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
use crate::db::HirDatabase;
|
||||
use crate::generics::{Generics, generics};
|
||||
use crate::next_solver::DbInterner;
|
||||
use crate::next_solver::mapping::{ChalkToNextSolver, NextSolverToChalk};
|
||||
use crate::{
|
||||
AliasTy, Const, ConstScalar, DynTyExt, GenericArg, GenericArgData, Interner, Lifetime,
|
||||
LifetimeData, Ty, TyKind,
|
||||
@ -238,14 +240,15 @@ impl Context<'_> {
|
||||
}
|
||||
GenericDefId::FunctionId(f) => {
|
||||
let subst = self.generics.placeholder_subst(self.db);
|
||||
self.add_constraints_from_sig(
|
||||
self.db
|
||||
.callable_item_signature(f.into())
|
||||
.substitute(Interner, &subst)
|
||||
.params_and_return
|
||||
.iter(),
|
||||
Variance::Covariant,
|
||||
);
|
||||
let interner = DbInterner::new_with(self.db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = subst.to_nextsolver(interner);
|
||||
let sig = self
|
||||
.db
|
||||
.callable_item_signature(f.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.to_chalk(interner);
|
||||
self.add_constraints_from_sig(sig.params_and_return.iter(), Variance::Covariant);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -682,7 +682,7 @@ impl Module {
|
||||
push_ty_diagnostics(
|
||||
db,
|
||||
acc,
|
||||
db.field_types_with_diagnostics_ns(s.id.into()).1,
|
||||
db.field_types_with_diagnostics(s.id.into()).1,
|
||||
source_map,
|
||||
);
|
||||
}
|
||||
@ -694,7 +694,7 @@ impl Module {
|
||||
push_ty_diagnostics(
|
||||
db,
|
||||
acc,
|
||||
db.field_types_with_diagnostics_ns(u.id.into()).1,
|
||||
db.field_types_with_diagnostics(u.id.into()).1,
|
||||
source_map,
|
||||
);
|
||||
}
|
||||
@ -724,7 +724,7 @@ impl Module {
|
||||
push_ty_diagnostics(
|
||||
db,
|
||||
acc,
|
||||
db.field_types_with_diagnostics_ns(v.into()).1,
|
||||
db.field_types_with_diagnostics(v.into()).1,
|
||||
source_map,
|
||||
);
|
||||
expr_store_diagnostics(db, acc, source_map);
|
||||
@ -740,7 +740,7 @@ impl Module {
|
||||
push_ty_diagnostics(
|
||||
db,
|
||||
acc,
|
||||
db.type_for_type_alias_with_diagnostics_ns(type_alias.id).1,
|
||||
db.type_for_type_alias_with_diagnostics(type_alias.id).1,
|
||||
&source_map,
|
||||
);
|
||||
acc.extend(def.diagnostics(db, style_lints));
|
||||
@ -915,13 +915,13 @@ impl Module {
|
||||
push_ty_diagnostics(
|
||||
db,
|
||||
acc,
|
||||
db.impl_self_ty_with_diagnostics_ns(impl_def.id).1,
|
||||
db.impl_self_ty_with_diagnostics(impl_def.id).1,
|
||||
&source_map,
|
||||
);
|
||||
push_ty_diagnostics(
|
||||
db,
|
||||
acc,
|
||||
db.impl_trait_with_diagnostics_ns(impl_def.id).and_then(|it| it.1),
|
||||
db.impl_trait_with_diagnostics(impl_def.id).and_then(|it| it.1),
|
||||
&source_map,
|
||||
);
|
||||
|
||||
@ -1504,7 +1504,7 @@ impl<'db> InstantiatedStruct<'db> {
|
||||
let krate = self.inner.krate(db);
|
||||
let interner = DbInterner::new_with(db, Some(krate.base()), None);
|
||||
|
||||
let ty = db.ty_ns(self.inner.id.into());
|
||||
let ty = db.ty(self.inner.id.into());
|
||||
TypeNs::new(db, self.inner.id, ty.instantiate(interner, self.args))
|
||||
}
|
||||
}
|
||||
@ -1664,7 +1664,7 @@ impl<'db> InstantiatedEnum<'db> {
|
||||
let krate = self.inner.krate(db);
|
||||
let interner = DbInterner::new_with(db, Some(krate.base()), None);
|
||||
|
||||
let ty = db.ty_ns(self.inner.id.into());
|
||||
let ty = db.ty(self.inner.id.into());
|
||||
TypeNs::new(db, self.inner.id, ty.instantiate(interner, self.args))
|
||||
}
|
||||
}
|
||||
@ -1851,7 +1851,8 @@ impl Adt {
|
||||
ParamKind::Lifetime => error_lifetime().cast(Interner),
|
||||
}
|
||||
})
|
||||
.build();
|
||||
.build(DbInterner::conjure())
|
||||
.to_chalk(DbInterner::conjure());
|
||||
Type::new(db, id, ty)
|
||||
}
|
||||
|
||||
@ -2286,7 +2287,13 @@ impl Function {
|
||||
pub fn fn_ptr_type(self, db: &dyn HirDatabase) -> Type<'_> {
|
||||
let resolver = self.id.resolver(db);
|
||||
let substs = TyBuilder::placeholder_subst(db, self.id);
|
||||
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let callable_sig = db
|
||||
.callable_item_signature(self.id.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.to_chalk(interner);
|
||||
let ty = TyKind::Function(callable_sig.to_fn_ptr()).intern(Interner);
|
||||
Type::new_with_resolver_inner(db, &resolver, ty)
|
||||
}
|
||||
@ -2295,8 +2302,14 @@ impl Function {
|
||||
pub fn ret_type(self, db: &dyn HirDatabase) -> Type<'_> {
|
||||
let resolver = self.id.resolver(db);
|
||||
let substs = TyBuilder::placeholder_subst(db, self.id);
|
||||
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
|
||||
let ty = callable_sig.ret().clone();
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let ty = db
|
||||
.callable_item_signature(self.id.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.output()
|
||||
.to_chalk(interner);
|
||||
Type::new_with_resolver_inner(db, &resolver, ty)
|
||||
}
|
||||
|
||||
@ -2325,8 +2338,14 @@ impl Function {
|
||||
parent_id.map(|id| TyBuilder::subst_for_def(db, id, None).fill(&mut filler).build());
|
||||
let substs = TyBuilder::subst_for_def(db, self.id, parent_substs).fill(&mut filler).build();
|
||||
|
||||
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
|
||||
let ty = callable_sig.ret().clone();
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let ty = db
|
||||
.callable_item_signature(self.id.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.output()
|
||||
.to_chalk(interner);
|
||||
Type::new_with_resolver_inner(db, &resolver, ty)
|
||||
}
|
||||
|
||||
@ -2336,8 +2355,14 @@ impl Function {
|
||||
}
|
||||
let resolver = self.id.resolver(db);
|
||||
let substs = TyBuilder::placeholder_subst(db, self.id);
|
||||
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
|
||||
let ret_ty = callable_sig.ret().clone();
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let ret_ty = db
|
||||
.callable_item_signature(self.id.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.output()
|
||||
.to_chalk(interner);
|
||||
for pred in ret_ty.impl_trait_bounds(db).into_iter().flatten() {
|
||||
if let WhereClause::AliasEq(output_eq) = pred.into_value_and_skipped_binders().0 {
|
||||
return Type::new_with_resolver_inner(db, &resolver, output_eq.ty).into();
|
||||
@ -2357,7 +2382,13 @@ impl Function {
|
||||
pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param<'_>> {
|
||||
let environment = db.trait_environment(self.id.into());
|
||||
let substs = TyBuilder::placeholder_subst(db, self.id);
|
||||
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let callable_sig = db
|
||||
.callable_item_signature(self.id.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.to_chalk(interner);
|
||||
callable_sig
|
||||
.params()
|
||||
.iter()
|
||||
@ -2385,7 +2416,13 @@ impl Function {
|
||||
pub fn params_without_self(self, db: &dyn HirDatabase) -> Vec<Param<'_>> {
|
||||
let environment = db.trait_environment(self.id.into());
|
||||
let substs = TyBuilder::placeholder_subst(db, self.id);
|
||||
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let callable_sig = db
|
||||
.callable_item_signature(self.id.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.to_chalk(interner);
|
||||
let skip = if db.function_signature(self.id).has_self_param() { 1 } else { 0 };
|
||||
callable_sig
|
||||
.params()
|
||||
@ -2435,7 +2472,13 @@ impl Function {
|
||||
GenericArg::new(Interner, GenericArgData::Ty(ty))
|
||||
})
|
||||
.build();
|
||||
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let callable_sig = db
|
||||
.callable_item_signature(self.id.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.to_chalk(interner);
|
||||
let skip = if db.function_signature(self.id).has_self_param() { 1 } else { 0 };
|
||||
callable_sig
|
||||
.params()
|
||||
@ -2730,8 +2773,13 @@ impl SelfParam {
|
||||
|
||||
pub fn ty<'db>(&self, db: &'db dyn HirDatabase) -> Type<'db> {
|
||||
let substs = TyBuilder::placeholder_subst(db, self.func);
|
||||
let callable_sig =
|
||||
db.callable_item_signature(self.func.into()).substitute(Interner, &substs);
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let callable_sig = db
|
||||
.callable_item_signature(self.func.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.to_chalk(interner);
|
||||
let environment = db.trait_environment(self.func.into());
|
||||
let ty = callable_sig.params()[0].clone();
|
||||
Type { env: environment, ty, _pd: PhantomCovariantLifetime::new() }
|
||||
@ -2763,8 +2811,13 @@ impl SelfParam {
|
||||
let parent_substs = TyBuilder::subst_for_def(db, parent_id, None).fill(&mut filler).build();
|
||||
let substs =
|
||||
TyBuilder::subst_for_def(db, self.func, Some(parent_substs)).fill(&mut filler).build();
|
||||
let callable_sig =
|
||||
db.callable_item_signature(self.func.into()).substitute(Interner, &substs);
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let callable_sig = db
|
||||
.callable_item_signature(self.func.into())
|
||||
.instantiate(interner, args)
|
||||
.skip_binder()
|
||||
.to_chalk(interner);
|
||||
let environment = db.trait_environment(self.func.into());
|
||||
let ty = callable_sig.params()[0].clone();
|
||||
Type { env: environment, ty, _pd: PhantomCovariantLifetime::new() }
|
||||
@ -3640,7 +3693,7 @@ impl AssocItem {
|
||||
push_ty_diagnostics(
|
||||
db,
|
||||
acc,
|
||||
db.type_for_type_alias_with_diagnostics_ns(type_alias.id).1,
|
||||
db.type_for_type_alias_with_diagnostics(type_alias.id).1,
|
||||
&db.type_alias_signature_with_source_map(type_alias.id).1,
|
||||
);
|
||||
for diag in hir_ty::diagnostics::incorrect_case(db, type_alias.id.into()) {
|
||||
@ -3768,7 +3821,7 @@ impl GenericDef {
|
||||
push_ty_diagnostics(
|
||||
db,
|
||||
acc,
|
||||
db.generic_predicates_without_parent_with_diagnostics_ns(def).1,
|
||||
db.generic_predicates_without_parent_with_diagnostics(def).1,
|
||||
&source_map,
|
||||
);
|
||||
for (param_id, param) in generics.iter_type_or_consts() {
|
||||
@ -3776,7 +3829,7 @@ impl GenericDef {
|
||||
push_ty_diagnostics(
|
||||
db,
|
||||
acc,
|
||||
db.const_param_ty_with_diagnostics_ns(ConstParamId::from_unchecked(
|
||||
db.const_param_ty_with_diagnostics(ConstParamId::from_unchecked(
|
||||
TypeOrConstParamId { parent: def, local_id: param_id },
|
||||
))
|
||||
.1,
|
||||
@ -4828,32 +4881,40 @@ impl<'db> Type<'db> {
|
||||
}
|
||||
|
||||
fn from_def(db: &'db dyn HirDatabase, def: impl Into<TyDefId> + HasResolver) -> Self {
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let ty = db.ty(def.into());
|
||||
let substs = TyBuilder::unknown_subst(
|
||||
db,
|
||||
match def.into() {
|
||||
TyDefId::AdtId(it) => GenericDefId::AdtId(it),
|
||||
TyDefId::TypeAliasId(it) => GenericDefId::TypeAliasId(it),
|
||||
TyDefId::BuiltinType(_) => return Type::new(db, def, ty.skip_binders().clone()),
|
||||
TyDefId::BuiltinType(_) => {
|
||||
return Type::new(db, def, ty.skip_binder().to_chalk(interner));
|
||||
}
|
||||
},
|
||||
);
|
||||
Type::new(db, def, ty.substitute(Interner, &substs))
|
||||
let args: hir_ty::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
Type::new(db, def, ty.instantiate(interner, args).to_chalk(interner))
|
||||
}
|
||||
|
||||
fn from_def_placeholders(
|
||||
db: &'db dyn HirDatabase,
|
||||
def: impl Into<TyDefId> + HasResolver,
|
||||
) -> Self {
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let ty = db.ty(def.into());
|
||||
let substs = TyBuilder::placeholder_subst(
|
||||
db,
|
||||
match def.into() {
|
||||
TyDefId::AdtId(it) => GenericDefId::AdtId(it),
|
||||
TyDefId::TypeAliasId(it) => GenericDefId::TypeAliasId(it),
|
||||
TyDefId::BuiltinType(_) => return Type::new(db, def, ty.skip_binders().clone()),
|
||||
TyDefId::BuiltinType(_) => {
|
||||
return Type::new(db, def, ty.skip_binder().to_chalk(interner));
|
||||
}
|
||||
},
|
||||
);
|
||||
Type::new(db, def, ty.substitute(Interner, &substs))
|
||||
let args: hir_ty::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
Type::new(db, def, ty.instantiate(interner, args).to_chalk(interner))
|
||||
}
|
||||
|
||||
fn from_value_def(
|
||||
@ -4863,6 +4924,7 @@ impl<'db> Type<'db> {
|
||||
let Some(ty) = db.value_ty(def.into()) else {
|
||||
return Type::new(db, def, TyKind::Error.intern(Interner));
|
||||
};
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let substs = TyBuilder::unknown_subst(
|
||||
db,
|
||||
match def.into() {
|
||||
@ -4873,10 +4935,13 @@ impl<'db> Type<'db> {
|
||||
ValueTyDefId::EnumVariantId(it) => {
|
||||
GenericDefId::AdtId(AdtId::EnumId(it.lookup(db).parent))
|
||||
}
|
||||
ValueTyDefId::StaticId(_) => return Type::new(db, def, ty.skip_binders().clone()),
|
||||
ValueTyDefId::StaticId(_) => {
|
||||
return Type::new(db, def, ty.skip_binder().to_chalk(interner));
|
||||
}
|
||||
},
|
||||
);
|
||||
Type::new(db, def, ty.substitute(Interner, &substs))
|
||||
let args: crate::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
Type::new(db, def, ty.instantiate(interner, args).to_chalk(interner))
|
||||
}
|
||||
|
||||
pub fn new_slice(ty: Self) -> Self {
|
||||
|
@ -46,6 +46,10 @@ use hir_ty::{
|
||||
from_assoc_type_id,
|
||||
lang_items::lang_items_for_bin_op,
|
||||
method_resolution,
|
||||
next_solver::{
|
||||
DbInterner,
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk},
|
||||
},
|
||||
};
|
||||
use intern::sym;
|
||||
use itertools::Itertools;
|
||||
@ -372,8 +376,10 @@ impl<'db> SourceAnalyzer<'db> {
|
||||
) -> Option<Callable<'db>> {
|
||||
let expr_id = self.expr_id(call.clone().into())?.as_expr()?;
|
||||
let (func, substs) = self.infer()?.method_resolution(expr_id)?;
|
||||
let ty = db.value_ty(func.into())?.substitute(Interner, &substs);
|
||||
let ty = Type::new_with_resolver(db, &self.resolver, ty);
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let args: hir_ty::next_solver::GenericArgs<'_> = substs.to_nextsolver(interner);
|
||||
let ty = db.value_ty(func.into())?.instantiate(interner, args);
|
||||
let ty = Type::new_with_resolver(db, &self.resolver, ty.to_chalk(interner));
|
||||
let mut res = ty.as_callable(db)?;
|
||||
res.is_bound_method = true;
|
||||
Some(res)
|
||||
|
@ -1,6 +1,7 @@
|
||||
//! Module responsible for analyzing the code surrounding the cursor for completion.
|
||||
use std::iter;
|
||||
|
||||
use base_db::salsa;
|
||||
use hir::{ExpandResult, InFile, Semantics, Type, TypeInfo, Variant};
|
||||
use ide_db::{RootDatabase, active_parameter::ActiveParameter};
|
||||
use itertools::Either;
|
||||
@ -85,9 +86,15 @@ pub(super) fn expand_and_analyze<'db>(
|
||||
let original_offset = expansion.original_offset + relative_offset;
|
||||
let token = expansion.original_file.token_at_offset(original_offset).left_biased()?;
|
||||
|
||||
analyze(sema, expansion, original_token, &token).map(|(analysis, expected, qualifier_ctx)| {
|
||||
AnalysisResult { analysis, expected, qualifier_ctx, token, original_offset }
|
||||
})
|
||||
salsa::attach(sema.db, || analyze(sema, expansion, original_token, &token)).map(
|
||||
|(analysis, expected, qualifier_ctx)| AnalysisResult {
|
||||
analysis,
|
||||
expected,
|
||||
qualifier_ctx,
|
||||
token,
|
||||
original_offset,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn token_at_offset_ignore_whitespace(file: &SyntaxNode, offset: TextSize) -> Option<SyntaxToken> {
|
||||
|
@ -473,7 +473,7 @@ mod tests {
|
||||
frange.range,
|
||||
"selection is not an expression(yet contained in one)"
|
||||
);
|
||||
let name = NameGenerator::default().for_variable(&expr, &sema);
|
||||
let name = salsa::attach(sema.db, || NameGenerator::default().for_variable(&expr, &sema));
|
||||
assert_eq!(&name, expected);
|
||||
}
|
||||
|
||||
|
@ -380,7 +380,7 @@ fn main() {
|
||||
let foo = foo4();
|
||||
// ^^^ &dyn Fn(f64, f64) -> u32
|
||||
let foo = foo5();
|
||||
// ^^^ &dyn Fn(&dyn Fn(f64, f64) -> u32, f64) -> u32
|
||||
// ^^^ &dyn Fn(&(dyn Fn(f64, f64) -> u32 + 'static), f64) -> u32
|
||||
let foo = foo6();
|
||||
// ^^^ impl Fn(f64, f64) -> u32
|
||||
let foo = foo7();
|
||||
|
@ -94,8 +94,8 @@ pub(crate) fn view_memory_layout(
|
||||
let def = get_definition(&sema, token)?;
|
||||
|
||||
let ty = match def {
|
||||
Definition::Adt(it) => it.ty(db),
|
||||
Definition::TypeAlias(it) => it.ty(db),
|
||||
Definition::Adt(it) => salsa::attach(db, || it.ty(db)),
|
||||
Definition::TypeAlias(it) => salsa::attach(db, || it.ty(db)),
|
||||
Definition::BuiltinType(it) => it.ty(db),
|
||||
Definition::SelfType(it) => it.self_ty(db),
|
||||
Definition::Local(it) => it.ty(db),
|
||||
|
Loading…
x
Reference in New Issue
Block a user