Migrate hir types to next solver
This commit is contained in:
parent
bfb0892525
commit
9170a7dffc
28 changed files with 1284 additions and 1933 deletions
|
|
@ -5,23 +5,21 @@
|
|||
|
||||
use std::fmt;
|
||||
|
||||
use hir_def::TraitId;
|
||||
use hir_def::{TypeAliasId, lang_item::LangItem};
|
||||
use hir_def::{TraitId, TypeAliasId, lang_item::LangItem};
|
||||
use rustc_type_ir::inherent::{IntoKind, Ty as _};
|
||||
use tracing::debug;
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::next_solver::TraitRef;
|
||||
use crate::next_solver::infer::InferOk;
|
||||
use crate::next_solver::infer::traits::Obligation;
|
||||
use crate::{
|
||||
TraitEnvironment,
|
||||
db::HirDatabase,
|
||||
infer::unify::InferenceTable,
|
||||
next_solver::{
|
||||
Ty, TyKind,
|
||||
infer::traits::{ObligationCause, PredicateObligations},
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk},
|
||||
Canonical, TraitRef, Ty, TyKind,
|
||||
infer::{
|
||||
InferOk,
|
||||
traits::{Obligation, ObligationCause, PredicateObligations},
|
||||
},
|
||||
obligation_ctxt::ObligationCtxt,
|
||||
},
|
||||
};
|
||||
|
|
@ -38,17 +36,16 @@ const AUTODEREF_RECURSION_LIMIT: usize = 20;
|
|||
pub fn autoderef<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'db>>,
|
||||
ty: crate::Canonical<crate::Ty>,
|
||||
) -> impl Iterator<Item = crate::Ty> + use<> {
|
||||
ty: Canonical<'db, Ty<'db>>,
|
||||
) -> impl Iterator<Item = Ty<'db>> + use<'db> {
|
||||
let mut table = InferenceTable::new(db, env);
|
||||
let interner = table.interner();
|
||||
let ty = table.instantiate_canonical(ty.to_nextsolver(interner));
|
||||
let ty = table.instantiate_canonical(ty);
|
||||
let mut autoderef = Autoderef::new_no_tracking(&mut table, ty);
|
||||
let mut v = Vec::new();
|
||||
while let Some((ty, _steps)) = autoderef.next() {
|
||||
// `ty` may contain unresolved inference variables. Since there's no chance they would be
|
||||
// resolved, just replace with fallback type.
|
||||
let resolved = autoderef.table.resolve_completely(ty).to_chalk(interner);
|
||||
let resolved = autoderef.table.resolve_completely(ty);
|
||||
|
||||
// If the deref chain contains a cycle (e.g. `A` derefs to `B` and `B` derefs to `A`), we
|
||||
// would revisit some already visited types. Stop here to avoid duplication.
|
||||
|
|
|
|||
|
|
@ -1,66 +1,32 @@
|
|||
//! Various extensions traits for Chalk types.
|
||||
|
||||
use chalk_ir::{
|
||||
FloatTy, IntTy, Mutability, Scalar, TyVariableKind, TypeOutlives, UintTy, cast::Cast,
|
||||
};
|
||||
use hir_def::{
|
||||
DefWithBodyId, FunctionId, GenericDefId, HasModule, ItemContainerId, Lookup, TraitId,
|
||||
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType, BuiltinUint},
|
||||
hir::generics::{TypeOrConstParamData, TypeParamProvenance},
|
||||
lang_item::LangItem,
|
||||
type_ref::Rawness,
|
||||
};
|
||||
use chalk_ir::Mutability;
|
||||
use hir_def::{FunctionId, ItemContainerId, Lookup, TraitId};
|
||||
|
||||
use crate::{
|
||||
AdtId, AliasEq, AliasTy, Binders, CallableDefId, CallableSig, Canonical, CanonicalVarKinds,
|
||||
ClosureId, DynTy, FnPointer, ImplTraitId, InEnvironment, Interner, Lifetime, ProjectionTy,
|
||||
QuantifiedWhereClause, Substitution, ToChalk, TraitRef, Ty, TyBuilder, TyKind, TypeFlags,
|
||||
WhereClause,
|
||||
db::HirDatabase,
|
||||
from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, from_placeholder_idx,
|
||||
generics::generics,
|
||||
next_solver::{DbInterner, mapping::NextSolverToChalk},
|
||||
to_chalk_trait_id,
|
||||
AdtId, Binders, CallableDefId, CallableSig, DynTy, Interner, Lifetime, ProjectionTy,
|
||||
Substitution, ToChalk, TraitRef, Ty, TyKind, TypeFlags, WhereClause, db::HirDatabase,
|
||||
from_assoc_type_id, from_chalk_trait_id, generics::generics, to_chalk_trait_id,
|
||||
utils::ClosureSubst,
|
||||
};
|
||||
|
||||
pub trait TyExt {
|
||||
pub(crate) trait TyExt {
|
||||
fn is_unit(&self) -> bool;
|
||||
fn is_integral(&self) -> bool;
|
||||
fn is_scalar(&self) -> bool;
|
||||
fn is_floating_point(&self) -> bool;
|
||||
fn is_never(&self) -> bool;
|
||||
fn is_str(&self) -> bool;
|
||||
fn is_unknown(&self) -> bool;
|
||||
fn contains_unknown(&self) -> bool;
|
||||
fn is_ty_var(&self) -> bool;
|
||||
fn is_union(&self) -> bool;
|
||||
|
||||
fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)>;
|
||||
fn as_builtin(&self) -> Option<BuiltinType>;
|
||||
fn as_tuple(&self) -> Option<&Substitution>;
|
||||
fn as_closure(&self) -> Option<ClosureId>;
|
||||
fn as_fn_def(&self, db: &dyn HirDatabase) -> Option<FunctionId>;
|
||||
fn as_reference(&self) -> Option<(&Ty, Lifetime, Mutability)>;
|
||||
fn as_raw_ptr(&self) -> Option<(&Ty, Mutability)>;
|
||||
fn as_reference_or_ptr(&self) -> Option<(&Ty, Rawness, Mutability)>;
|
||||
fn as_generic_def(&self, db: &dyn HirDatabase) -> Option<GenericDefId>;
|
||||
|
||||
fn callable_def(&self, db: &dyn HirDatabase) -> Option<CallableDefId>;
|
||||
fn callable_sig(&self, db: &dyn HirDatabase) -> Option<CallableSig>;
|
||||
|
||||
fn strip_references(&self) -> &Ty;
|
||||
fn strip_reference(&self) -> &Ty;
|
||||
|
||||
/// If this is a `dyn Trait`, returns that trait.
|
||||
fn dyn_trait(&self) -> Option<TraitId>;
|
||||
|
||||
fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>>;
|
||||
fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId>;
|
||||
fn is_copy(self, db: &dyn HirDatabase, owner: DefWithBodyId) -> bool;
|
||||
|
||||
/// FIXME: Get rid of this, it's not a good abstraction
|
||||
fn equals_ctor(&self, other: &Ty) -> bool;
|
||||
}
|
||||
|
||||
impl TyExt for Ty {
|
||||
|
|
@ -68,33 +34,6 @@ impl TyExt for Ty {
|
|||
matches!(self.kind(Interner), TyKind::Tuple(0, _))
|
||||
}
|
||||
|
||||
fn is_integral(&self) -> bool {
|
||||
matches!(
|
||||
self.kind(Interner),
|
||||
TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_))
|
||||
| TyKind::InferenceVar(_, TyVariableKind::Integer)
|
||||
)
|
||||
}
|
||||
|
||||
fn is_scalar(&self) -> bool {
|
||||
matches!(self.kind(Interner), TyKind::Scalar(_))
|
||||
}
|
||||
|
||||
fn is_floating_point(&self) -> bool {
|
||||
matches!(
|
||||
self.kind(Interner),
|
||||
TyKind::Scalar(Scalar::Float(_)) | TyKind::InferenceVar(_, TyVariableKind::Float)
|
||||
)
|
||||
}
|
||||
|
||||
fn is_never(&self) -> bool {
|
||||
matches!(self.kind(Interner), TyKind::Never)
|
||||
}
|
||||
|
||||
fn is_str(&self) -> bool {
|
||||
matches!(self.kind(Interner), TyKind::Str)
|
||||
}
|
||||
|
||||
fn is_unknown(&self) -> bool {
|
||||
matches!(self.kind(Interner), TyKind::Error)
|
||||
}
|
||||
|
|
@ -103,14 +42,6 @@ impl TyExt for Ty {
|
|||
self.data(Interner).flags.contains(TypeFlags::HAS_ERROR)
|
||||
}
|
||||
|
||||
fn is_ty_var(&self) -> bool {
|
||||
matches!(self.kind(Interner), TyKind::InferenceVar(_, _))
|
||||
}
|
||||
|
||||
fn is_union(&self) -> bool {
|
||||
matches!(self.adt_id(Interner), Some(AdtId(hir_def::AdtId::UnionId(_))))
|
||||
}
|
||||
|
||||
fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)> {
|
||||
match self.kind(Interner) {
|
||||
TyKind::Adt(AdtId(adt), parameters) => Some((*adt, parameters)),
|
||||
|
|
@ -118,37 +49,6 @@ impl TyExt for Ty {
|
|||
}
|
||||
}
|
||||
|
||||
fn as_builtin(&self) -> Option<BuiltinType> {
|
||||
match self.kind(Interner) {
|
||||
TyKind::Str => Some(BuiltinType::Str),
|
||||
TyKind::Scalar(Scalar::Bool) => Some(BuiltinType::Bool),
|
||||
TyKind::Scalar(Scalar::Char) => Some(BuiltinType::Char),
|
||||
TyKind::Scalar(Scalar::Float(fty)) => Some(BuiltinType::Float(match fty {
|
||||
FloatTy::F128 => BuiltinFloat::F128,
|
||||
FloatTy::F64 => BuiltinFloat::F64,
|
||||
FloatTy::F32 => BuiltinFloat::F32,
|
||||
FloatTy::F16 => BuiltinFloat::F16,
|
||||
})),
|
||||
TyKind::Scalar(Scalar::Int(ity)) => Some(BuiltinType::Int(match ity {
|
||||
IntTy::Isize => BuiltinInt::Isize,
|
||||
IntTy::I8 => BuiltinInt::I8,
|
||||
IntTy::I16 => BuiltinInt::I16,
|
||||
IntTy::I32 => BuiltinInt::I32,
|
||||
IntTy::I64 => BuiltinInt::I64,
|
||||
IntTy::I128 => BuiltinInt::I128,
|
||||
})),
|
||||
TyKind::Scalar(Scalar::Uint(ity)) => Some(BuiltinType::Uint(match ity {
|
||||
UintTy::Usize => BuiltinUint::Usize,
|
||||
UintTy::U8 => BuiltinUint::U8,
|
||||
UintTy::U16 => BuiltinUint::U16,
|
||||
UintTy::U32 => BuiltinUint::U32,
|
||||
UintTy::U64 => BuiltinUint::U64,
|
||||
UintTy::U128 => BuiltinUint::U128,
|
||||
})),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn as_tuple(&self) -> Option<&Substitution> {
|
||||
match self.kind(Interner) {
|
||||
TyKind::Tuple(_, substs) => Some(substs),
|
||||
|
|
@ -156,13 +56,6 @@ impl TyExt for Ty {
|
|||
}
|
||||
}
|
||||
|
||||
fn as_closure(&self) -> Option<ClosureId> {
|
||||
match self.kind(Interner) {
|
||||
TyKind::Closure(id, _) => Some(*id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn as_fn_def(&self, db: &dyn HirDatabase) -> Option<FunctionId> {
|
||||
match self.callable_def(db) {
|
||||
Some(CallableDefId::FunctionId(func)) => Some(func),
|
||||
|
|
@ -177,33 +70,6 @@ impl TyExt for Ty {
|
|||
}
|
||||
}
|
||||
|
||||
fn as_raw_ptr(&self) -> Option<(&Ty, Mutability)> {
|
||||
match self.kind(Interner) {
|
||||
TyKind::Raw(mutability, ty) => Some((ty, *mutability)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn as_reference_or_ptr(&self) -> Option<(&Ty, Rawness, Mutability)> {
|
||||
match self.kind(Interner) {
|
||||
TyKind::Ref(mutability, _, ty) => Some((ty, Rawness::Ref, *mutability)),
|
||||
TyKind::Raw(mutability, ty) => Some((ty, Rawness::RawPtr, *mutability)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn as_generic_def(&self, db: &dyn HirDatabase) -> Option<GenericDefId> {
|
||||
match *self.kind(Interner) {
|
||||
TyKind::Adt(AdtId(adt), ..) => Some(adt.into()),
|
||||
TyKind::FnDef(callable, ..) => {
|
||||
Some(GenericDefId::from_callable(db, ToChalk::from_chalk(db, callable)))
|
||||
}
|
||||
TyKind::AssociatedType(type_alias, ..) => Some(from_assoc_type_id(type_alias).into()),
|
||||
TyKind::Foreign(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn callable_def(&self, db: &dyn HirDatabase) -> Option<CallableDefId> {
|
||||
match self.kind(Interner) {
|
||||
&TyKind::FnDef(def, ..) => Some(ToChalk::from_chalk(db, def)),
|
||||
|
|
@ -244,177 +110,6 @@ impl TyExt for Ty {
|
|||
}
|
||||
t
|
||||
}
|
||||
|
||||
fn strip_reference(&self) -> &Ty {
|
||||
self.as_reference().map_or(self, |(ty, _, _)| ty)
|
||||
}
|
||||
|
||||
fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>> {
|
||||
let handle_async_block_type_impl_trait = |def: DefWithBodyId| {
|
||||
let krate = def.module(db).krate();
|
||||
if let Some(future_trait) = LangItem::Future.resolve_trait(db, krate) {
|
||||
// This is only used by type walking.
|
||||
// Parameters will be walked outside, and projection predicate is not used.
|
||||
// So just provide the Future trait.
|
||||
let impl_bound = Binders::empty(
|
||||
Interner,
|
||||
WhereClause::Implemented(TraitRef {
|
||||
trait_id: to_chalk_trait_id(future_trait),
|
||||
substitution: Substitution::empty(Interner),
|
||||
}),
|
||||
);
|
||||
Some(vec![impl_bound])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
match self.kind(Interner) {
|
||||
TyKind::OpaqueType(opaque_ty_id, subst) => {
|
||||
match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) {
|
||||
ImplTraitId::AsyncBlockTypeImplTrait(def, _expr) => {
|
||||
handle_async_block_type_impl_trait(def)
|
||||
}
|
||||
ImplTraitId::ReturnTypeImplTrait(func, idx) => {
|
||||
db.return_type_impl_traits(func).map(|it| {
|
||||
let data =
|
||||
(*it).as_ref().map(|rpit| rpit.impl_traits[idx].bounds.clone());
|
||||
data.substitute(Interner, &subst).into_value_and_skipped_binders().0
|
||||
})
|
||||
}
|
||||
ImplTraitId::TypeAliasImplTrait(alias, idx) => {
|
||||
db.type_alias_impl_traits(alias).map(|it| {
|
||||
let data =
|
||||
(*it).as_ref().map(|rpit| rpit.impl_traits[idx].bounds.clone());
|
||||
data.substitute(Interner, &subst).into_value_and_skipped_binders().0
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
TyKind::Alias(AliasTy::Opaque(opaque_ty)) => {
|
||||
let predicates = match db.lookup_intern_impl_trait_id(opaque_ty.opaque_ty_id.into())
|
||||
{
|
||||
ImplTraitId::ReturnTypeImplTrait(func, idx) => {
|
||||
db.return_type_impl_traits(func).map(|it| {
|
||||
let data =
|
||||
(*it).as_ref().map(|rpit| rpit.impl_traits[idx].bounds.clone());
|
||||
data.substitute(Interner, &opaque_ty.substitution)
|
||||
})
|
||||
}
|
||||
ImplTraitId::TypeAliasImplTrait(alias, idx) => {
|
||||
db.type_alias_impl_traits(alias).map(|it| {
|
||||
let data =
|
||||
(*it).as_ref().map(|rpit| rpit.impl_traits[idx].bounds.clone());
|
||||
data.substitute(Interner, &opaque_ty.substitution)
|
||||
})
|
||||
}
|
||||
ImplTraitId::AsyncBlockTypeImplTrait(def, _) => {
|
||||
return handle_async_block_type_impl_trait(def);
|
||||
}
|
||||
};
|
||||
|
||||
predicates.map(|it| it.into_value_and_skipped_binders().0)
|
||||
}
|
||||
TyKind::Placeholder(idx) => {
|
||||
let id = from_placeholder_idx(db, *idx).0;
|
||||
let generic_params = db.generic_params(id.parent);
|
||||
let param_data = &generic_params[id.local_id];
|
||||
match param_data {
|
||||
TypeOrConstParamData::TypeParamData(p) => match p.provenance {
|
||||
TypeParamProvenance::ArgumentImplTrait => {
|
||||
let substs = TyBuilder::placeholder_subst(db, id.parent);
|
||||
let predicates = db
|
||||
.generic_predicates(id.parent)
|
||||
.iter()
|
||||
.map(|pred| pred.clone().substitute(Interner, &substs))
|
||||
.filter(|wc| match wc.skip_binders() {
|
||||
WhereClause::Implemented(tr) => {
|
||||
&tr.self_type_parameter(Interner) == self
|
||||
}
|
||||
WhereClause::AliasEq(AliasEq {
|
||||
alias: AliasTy::Projection(proj),
|
||||
ty: _,
|
||||
}) => &proj.self_type_parameter(db) == self,
|
||||
WhereClause::TypeOutlives(TypeOutlives { ty, lifetime: _ }) => {
|
||||
ty == self
|
||||
}
|
||||
_ => false,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Some(predicates)
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId> {
|
||||
match self.kind(Interner) {
|
||||
TyKind::AssociatedType(id, ..) => match from_assoc_type_id(*id).lookup(db).container {
|
||||
ItemContainerId::TraitId(trait_id) => Some(trait_id),
|
||||
_ => None,
|
||||
},
|
||||
TyKind::Alias(AliasTy::Projection(projection_ty)) => {
|
||||
match from_assoc_type_id(projection_ty.associated_ty_id).lookup(db).container {
|
||||
ItemContainerId::TraitId(trait_id) => Some(trait_id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_copy(self, db: &dyn HirDatabase, owner: DefWithBodyId) -> bool {
|
||||
let crate_id = owner.module(db).krate();
|
||||
let Some(copy_trait) = LangItem::Copy.resolve_trait(db, crate_id) else {
|
||||
return false;
|
||||
};
|
||||
let trait_ref = TyBuilder::trait_ref(db, copy_trait).push(self).build();
|
||||
let env = db.trait_environment_for_body(owner);
|
||||
let goal = Canonical {
|
||||
value: InEnvironment::new(
|
||||
&env.env.to_chalk(DbInterner::new_with(db, Some(env.krate), env.block)),
|
||||
trait_ref.cast(Interner),
|
||||
),
|
||||
binders: CanonicalVarKinds::empty(Interner),
|
||||
};
|
||||
!db.trait_solve(crate_id, None, goal).no_solution()
|
||||
}
|
||||
|
||||
fn equals_ctor(&self, other: &Ty) -> bool {
|
||||
match (self.kind(Interner), other.kind(Interner)) {
|
||||
(TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2,
|
||||
(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, ..)) => {
|
||||
ty_id == ty_id2
|
||||
}
|
||||
(TyKind::Foreign(ty_id, ..), TyKind::Foreign(ty_id2, ..)) => ty_id == ty_id2,
|
||||
(TyKind::Closure(id1, _), TyKind::Closure(id2, _)) => id1 == id2,
|
||||
(TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..))
|
||||
| (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => {
|
||||
mutability == mutability2
|
||||
}
|
||||
(
|
||||
TyKind::Function(FnPointer { num_binders, sig, .. }),
|
||||
TyKind::Function(FnPointer { num_binders: num_binders2, sig: sig2, .. }),
|
||||
) => num_binders == num_binders2 && sig == sig2,
|
||||
(TyKind::Tuple(cardinality, _), TyKind::Tuple(cardinality2, _)) => {
|
||||
cardinality == cardinality2
|
||||
}
|
||||
(TyKind::Str, TyKind::Str) | (TyKind::Never, TyKind::Never) => true,
|
||||
(TyKind::Scalar(scalar), TyKind::Scalar(scalar2)) => scalar == scalar2,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ProjectionTyExt {
|
||||
|
|
@ -445,9 +140,8 @@ impl ProjectionTyExt for ProjectionTy {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait DynTyExt {
|
||||
pub(crate) trait DynTyExt {
|
||||
fn principal(&self) -> Option<Binders<Binders<&TraitRef>>>;
|
||||
fn principal_id(&self) -> Option<chalk_ir::TraitId<Interner>>;
|
||||
}
|
||||
|
||||
impl DynTyExt for DynTy {
|
||||
|
|
@ -461,13 +155,6 @@ impl DynTyExt for DynTy {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn principal_id(&self) -> Option<chalk_ir::TraitId<Interner>> {
|
||||
self.bounds.skip_binders().interned().first().and_then(|b| match b.skip_binders() {
|
||||
crate::WhereClause::Implemented(trait_ref) => Some(trait_ref.trait_id),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TraitRefExt {
|
||||
|
|
|
|||
|
|
@ -11,48 +11,15 @@ use stdx::never;
|
|||
|
||||
use crate::{
|
||||
Const, ConstData, ConstScalar, ConstValue, GenericArg, Interner, MemoryMap, Substitution,
|
||||
TraitEnvironment, Ty, TyBuilder,
|
||||
TraitEnvironment, Ty,
|
||||
db::HirDatabase,
|
||||
generics::Generics,
|
||||
lower::ParamLoweringMode,
|
||||
next_solver::{
|
||||
DbInterner,
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk},
|
||||
},
|
||||
next_solver::{DbInterner, mapping::ChalkToNextSolver},
|
||||
to_placeholder_idx,
|
||||
};
|
||||
|
||||
use super::mir::pad16;
|
||||
|
||||
/// Extension trait for [`Const`]
|
||||
pub trait ConstExt {
|
||||
/// Is a [`Const`] unknown?
|
||||
fn is_unknown(&self) -> bool;
|
||||
}
|
||||
|
||||
impl ConstExt for Const {
|
||||
fn is_unknown(&self) -> bool {
|
||||
match self.data(Interner).value {
|
||||
// interned Unknown
|
||||
chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst {
|
||||
interned: ConstScalar::Unknown,
|
||||
}) => true,
|
||||
|
||||
// interned concrete anything else
|
||||
chalk_ir::ConstValue::Concrete(..) => false,
|
||||
|
||||
_ => {
|
||||
tracing::error!(
|
||||
"is_unknown was called on a non-concrete constant value! {:?}",
|
||||
self
|
||||
);
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn path_to_const<'g>(
|
||||
pub(crate) fn path_to_const<'g>(
|
||||
db: &dyn HirDatabase,
|
||||
resolver: &Resolver<'_>,
|
||||
path: &Path,
|
||||
|
|
@ -94,7 +61,7 @@ pub fn path_to_const<'g>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn unknown_const(ty: Ty) -> Const {
|
||||
pub(crate) fn unknown_const(ty: Ty) -> Const {
|
||||
ConstData {
|
||||
ty,
|
||||
value: ConstValue::Concrete(chalk_ir::ConcreteConst { interned: ConstScalar::Unknown }),
|
||||
|
|
@ -102,18 +69,18 @@ pub fn unknown_const(ty: Ty) -> Const {
|
|||
.intern(Interner)
|
||||
}
|
||||
|
||||
pub fn unknown_const_as_generic(ty: Ty) -> GenericArg {
|
||||
pub(crate) fn unknown_const_as_generic(ty: Ty) -> GenericArg {
|
||||
unknown_const(ty).cast(Interner)
|
||||
}
|
||||
|
||||
/// Interns a constant scalar with the given type
|
||||
pub fn intern_const_scalar(value: ConstScalar, ty: Ty) -> Const {
|
||||
pub(crate) fn intern_const_scalar(value: ConstScalar, ty: Ty) -> Const {
|
||||
ConstData { ty, value: ConstValue::Concrete(chalk_ir::ConcreteConst { interned: value }) }
|
||||
.intern(Interner)
|
||||
}
|
||||
|
||||
/// Interns a constant scalar with the given type
|
||||
pub fn intern_const_ref(
|
||||
pub(crate) fn intern_const_ref(
|
||||
db: &dyn HirDatabase,
|
||||
value: &LiteralConstRef,
|
||||
ty: Ty,
|
||||
|
|
@ -139,47 +106,3 @@ pub fn intern_const_ref(
|
|||
};
|
||||
intern_const_scalar(bytes, ty)
|
||||
}
|
||||
|
||||
/// Interns a possibly-unknown target usize
|
||||
pub fn usize_const(db: &dyn HirDatabase, value: Option<u128>, krate: Crate) -> Const {
|
||||
intern_const_ref(
|
||||
db,
|
||||
&value.map_or(LiteralConstRef::Unknown, LiteralConstRef::UInt),
|
||||
TyBuilder::usize(),
|
||||
krate,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn try_const_usize(db: &dyn HirDatabase, c: &Const) -> Option<u128> {
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
match &c.data(Interner).value {
|
||||
chalk_ir::ConstValue::BoundVar(_) => None,
|
||||
chalk_ir::ConstValue::InferenceVar(_) => None,
|
||||
chalk_ir::ConstValue::Placeholder(_) => None,
|
||||
chalk_ir::ConstValue::Concrete(c) => match &c.interned {
|
||||
ConstScalar::Bytes(it, _) => Some(u128::from_le_bytes(pad16(it, false))),
|
||||
ConstScalar::UnevaluatedConst(c, subst) => {
|
||||
let ec = db.const_eval(*c, subst.to_nextsolver(interner), None).ok()?;
|
||||
try_const_usize(db, &ec.to_chalk(interner))
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_const_isize(db: &dyn HirDatabase, c: &Const) -> Option<i128> {
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
match &c.data(Interner).value {
|
||||
chalk_ir::ConstValue::BoundVar(_) => None,
|
||||
chalk_ir::ConstValue::InferenceVar(_) => None,
|
||||
chalk_ir::ConstValue::Placeholder(_) => None,
|
||||
chalk_ir::ConstValue::Concrete(c) => match &c.interned {
|
||||
ConstScalar::Bytes(it, _) => Some(i128::from_le_bytes(pad16(it, true))),
|
||||
ConstScalar::UnevaluatedConst(c, subst) => {
|
||||
let ec = db.const_eval(*c, subst.to_nextsolver(interner), None).ok()?;
|
||||
try_const_isize(db, &ec.to_chalk(interner))
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ use rustc_ast_ir::Mutability;
|
|||
use rustc_type_ir::{
|
||||
BoundVar, TypeAndMut,
|
||||
error::TypeError,
|
||||
inherent::{Const as _, GenericArg as _, IntoKind, Region as _, Safety, SliceLike, Ty as _},
|
||||
inherent::{Const as _, GenericArg as _, IntoKind, Safety, SliceLike, Ty as _},
|
||||
};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{debug, instrument};
|
||||
|
|
@ -59,15 +59,15 @@ use crate::{
|
|||
infer::{AllowTwoPhase, InferenceContext, TypeMismatch, unify::InferenceTable},
|
||||
next_solver::{
|
||||
Binder, BoundConst, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, CallableIdWrapper,
|
||||
ClauseKind, CoercePredicate, Const, ConstKind, DbInterner, ErrorGuaranteed, GenericArgs,
|
||||
PolyFnSig, PredicateKind, Region, RegionKind, SolverDefId, TraitRef, Ty, TyKind,
|
||||
Canonical, ClauseKind, CoercePredicate, Const, ConstKind, DbInterner, ErrorGuaranteed,
|
||||
GenericArgs, PolyFnSig, PredicateKind, Region, RegionKind, SolverDefId, TraitRef, Ty,
|
||||
TyKind,
|
||||
infer::{
|
||||
DefineOpaqueTypes, InferCtxt, InferOk, InferResult,
|
||||
relate::RelateResult,
|
||||
select::{ImplSource, SelectionError},
|
||||
traits::{Obligation, ObligationCause, PredicateObligation, PredicateObligations},
|
||||
},
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk},
|
||||
obligation_ctxt::ObligationCtxt,
|
||||
},
|
||||
utils::TargetFeatureIsSafeInTarget,
|
||||
|
|
@ -1525,7 +1525,7 @@ impl<'db, 'exprs> CoerceMany<'db, 'exprs> {
|
|||
pub fn could_coerce<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'db>>,
|
||||
tys: &crate::Canonical<(crate::Ty, crate::Ty)>,
|
||||
tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>,
|
||||
) -> bool {
|
||||
coerce(db, env, tys).is_ok()
|
||||
}
|
||||
|
|
@ -1533,12 +1533,11 @@ pub fn could_coerce<'db>(
|
|||
fn coerce<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'db>>,
|
||||
tys: &crate::Canonical<(crate::Ty, crate::Ty)>,
|
||||
) -> Result<(Vec<Adjustment<'db>>, crate::Ty), TypeError<DbInterner<'db>>> {
|
||||
tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>,
|
||||
) -> Result<(Vec<Adjustment<'db>>, Ty<'db>), TypeError<DbInterner<'db>>> {
|
||||
let mut table = InferenceTable::new(db, env);
|
||||
let interner = table.interner();
|
||||
let tys = tys.to_nextsolver(interner);
|
||||
let ((ty1_with_vars, ty2_with_vars), vars) = table.infer_ctxt.instantiate_canonical(&tys);
|
||||
let ((ty1_with_vars, ty2_with_vars), vars) = table.infer_ctxt.instantiate_canonical(tys);
|
||||
|
||||
let cause = ObligationCause::new();
|
||||
// FIXME: Target features.
|
||||
|
|
@ -1614,5 +1613,5 @@ fn coerce<'db>(
|
|||
&mut fallback_const,
|
||||
&mut fallback_region,
|
||||
);
|
||||
Ok((adjustments, ty.to_chalk(interner)))
|
||||
Ok((adjustments, ty))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! Path expression resolution.
|
||||
|
||||
use hir_def::{
|
||||
AdtId, AssocItemId, GenericDefId, GenericParamId, ItemContainerId, Lookup,
|
||||
AdtId, AssocItemId, GenericDefId, ItemContainerId, Lookup,
|
||||
expr_store::path::{Path, PathSegment},
|
||||
resolver::{ResolveValueResult, TypeNs, ValueNs},
|
||||
};
|
||||
|
|
@ -10,7 +10,7 @@ use rustc_type_ir::inherent::{SliceLike, Ty as _};
|
|||
use stdx::never;
|
||||
|
||||
use crate::{
|
||||
InferenceDiagnostic, ValueTyDefId, consteval,
|
||||
InferenceDiagnostic, ValueTyDefId,
|
||||
generics::generics,
|
||||
infer::diagnostics::InferenceTyLoweringContext as TyLoweringContext,
|
||||
lower_nextsolver::LifetimeElisionKind,
|
||||
|
|
@ -118,22 +118,12 @@ impl<'db> InferenceContext<'_, 'db> {
|
|||
self.interner(),
|
||||
generic_def.into(),
|
||||
self_subst.iter().flat_map(|it| it.iter()).chain(substs.iter().skip(parent_substs_len)),
|
||||
|_, _, id, _| self.error_param(id),
|
||||
|_, _, id, _| GenericArg::error_from_id(self.interner(), id),
|
||||
);
|
||||
|
||||
Some(ValuePathResolution::GenericDef(value_def, generic_def, substs))
|
||||
}
|
||||
|
||||
fn error_param(&mut self, id: GenericParamId) -> GenericArg<'db> {
|
||||
match id {
|
||||
GenericParamId::TypeParamId(_) => self.types.error.into(),
|
||||
GenericParamId::ConstParamId(id) => {
|
||||
consteval::unknown_const_as_generic(self.db.const_param_ty_ns(id))
|
||||
}
|
||||
GenericParamId::LifetimeParamId(_) => self.types.re_error.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn resolve_value_path_inner(
|
||||
&mut self,
|
||||
path: &Path,
|
||||
|
|
|
|||
|
|
@ -2,29 +2,27 @@
|
|||
|
||||
use std::fmt;
|
||||
|
||||
use chalk_ir::cast::Cast;
|
||||
use hir_def::GenericParamId;
|
||||
use hir_def::{AdtId, lang_item::LangItem};
|
||||
use hir_def::{AdtId, GenericParamId, lang_item::LangItem};
|
||||
use hir_expand::name::Name;
|
||||
use intern::sym;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use rustc_type_ir::{DebruijnIndex, InferConst, InferTy, RegionVid};
|
||||
use rustc_type_ir::{
|
||||
TyVid, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, UpcastFrom,
|
||||
DebruijnIndex, InferConst, InferTy, RegionVid, TyVid, TypeFoldable, TypeFolder,
|
||||
TypeSuperFoldable, TypeVisitableExt, UpcastFrom,
|
||||
inherent::{Const as _, IntoKind, Ty as _},
|
||||
solve::{Certainty, GoalSource},
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::next_solver::{Binder, ConstKind, GenericArgs, RegionKind, SolverDefId};
|
||||
use crate::{
|
||||
Interner, TraitEnvironment,
|
||||
TraitEnvironment,
|
||||
db::{HirDatabase, InternedOpaqueTyId},
|
||||
infer::InferenceContext,
|
||||
next_solver::{
|
||||
self, AliasTy, ClauseKind, Const, DbInterner, ErrorGuaranteed, GenericArg, Predicate,
|
||||
PredicateKind, Region, SolverDefIds, TraitRef, Ty, TyKind, TypingMode,
|
||||
self, AliasTy, Binder, Canonical, ClauseKind, Const, ConstKind, DbInterner,
|
||||
ErrorGuaranteed, GenericArg, GenericArgs, Predicate, PredicateKind, Region, RegionKind,
|
||||
SolverDefId, SolverDefIds, TraitRef, Ty, TyKind, TypingMode,
|
||||
fulfill::{FulfillmentCtxt, NextSolverError},
|
||||
infer::{
|
||||
DbInternerInferExt, DefineOpaqueTypes, InferCtxt, InferOk, InferResult,
|
||||
|
|
@ -33,7 +31,6 @@ use crate::{
|
|||
traits::{Obligation, ObligationCause, PredicateObligation},
|
||||
},
|
||||
inspect::{InspectConfig, InspectGoal, ProofTreeVisitor},
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk},
|
||||
obligation_ctxt::ObligationCtxt,
|
||||
},
|
||||
traits::{
|
||||
|
|
@ -115,10 +112,10 @@ impl<'a, 'db> ProofTreeVisitor<'db> for NestedObligationsForSelfTy<'a, 'db> {
|
|||
/// This means that there may be some unresolved goals that actually set bounds for the placeholder
|
||||
/// type for the types to unify. For example `Option<T>` and `Option<U>` unify although there is
|
||||
/// unresolved goal `T = U`.
|
||||
pub fn could_unify(
|
||||
db: &dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'_>>,
|
||||
tys: &crate::Canonical<(crate::Ty, crate::Ty)>,
|
||||
pub fn could_unify<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'db>>,
|
||||
tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>,
|
||||
) -> bool {
|
||||
could_unify_impl(db, env, tys, |ctxt| ctxt.select_where_possible())
|
||||
}
|
||||
|
|
@ -127,32 +124,28 @@ pub fn could_unify(
|
|||
///
|
||||
/// This means that placeholder types are not considered to unify if there are any bounds set on
|
||||
/// them. For example `Option<T>` and `Option<U>` do not unify as we cannot show that `T = U`
|
||||
pub fn could_unify_deeply(
|
||||
db: &dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'_>>,
|
||||
tys: &crate::Canonical<(crate::Ty, crate::Ty)>,
|
||||
pub fn could_unify_deeply<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'db>>,
|
||||
tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>,
|
||||
) -> bool {
|
||||
could_unify_impl(db, env, tys, |ctxt| ctxt.select_all_or_error())
|
||||
}
|
||||
|
||||
fn could_unify_impl(
|
||||
db: &dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'_>>,
|
||||
tys: &crate::Canonical<(crate::Ty, crate::Ty)>,
|
||||
select: for<'a, 'db> fn(&mut ObligationCtxt<'a, 'db>) -> Vec<NextSolverError<'db>>,
|
||||
fn could_unify_impl<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'db>>,
|
||||
tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>,
|
||||
select: for<'a> fn(&mut ObligationCtxt<'a, 'db>) -> Vec<NextSolverError<'db>>,
|
||||
) -> bool {
|
||||
let interner = DbInterner::new_with(db, Some(env.krate), env.block);
|
||||
// FIXME(next-solver): I believe this should use `PostAnalysis` (this is only used for IDE things),
|
||||
// but this causes some bug because of our incorrect impl of `type_of_opaque_hir_typeck()` for TAIT
|
||||
// and async blocks.
|
||||
let infcx = interner.infer_ctxt().build(TypingMode::Analysis {
|
||||
defining_opaque_types_and_generators: SolverDefIds::new_from_iter(interner, []),
|
||||
});
|
||||
let infcx = interner.infer_ctxt().build(TypingMode::non_body_analysis());
|
||||
let cause = ObligationCause::dummy();
|
||||
let at = infcx.at(&cause, env.env);
|
||||
let vars = make_substitutions(tys, &infcx);
|
||||
let ty1_with_vars = vars.apply(tys.value.0.clone(), Interner).to_nextsolver(interner);
|
||||
let ty2_with_vars = vars.apply(tys.value.1.clone(), Interner).to_nextsolver(interner);
|
||||
let ((ty1_with_vars, ty2_with_vars), _) = infcx.instantiate_canonical(tys);
|
||||
let mut ctxt = ObligationCtxt::new(&infcx);
|
||||
let can_unify = at
|
||||
.eq(DefineOpaqueTypes::No, ty1_with_vars, ty2_with_vars)
|
||||
|
|
@ -161,26 +154,6 @@ fn could_unify_impl(
|
|||
can_unify && select(&mut ctxt).is_empty()
|
||||
}
|
||||
|
||||
fn make_substitutions(
|
||||
tys: &crate::Canonical<(crate::Ty, crate::Ty)>,
|
||||
infcx: &InferCtxt<'_>,
|
||||
) -> crate::Substitution {
|
||||
let interner = infcx.interner;
|
||||
crate::Substitution::from_iter(
|
||||
Interner,
|
||||
tys.binders.iter(Interner).map(|it| match &it.kind {
|
||||
chalk_ir::VariableKind::Ty(_) => infcx.next_ty_var().to_chalk(interner).cast(Interner),
|
||||
// FIXME: maybe wrong?
|
||||
chalk_ir::VariableKind::Lifetime => {
|
||||
infcx.next_ty_var().to_chalk(interner).cast(Interner)
|
||||
}
|
||||
chalk_ir::VariableKind::Const(_ty) => {
|
||||
infcx.next_const_var().to_chalk(interner).cast(Interner)
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct InferenceTable<'db> {
|
||||
pub(crate) db: &'db dyn HirDatabase,
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ mod utils;
|
|||
|
||||
pub mod autoderef;
|
||||
pub mod consteval;
|
||||
pub mod consteval_chalk;
|
||||
mod consteval_chalk;
|
||||
pub mod db;
|
||||
pub mod diagnostics;
|
||||
pub mod display;
|
||||
|
|
@ -62,7 +62,7 @@ mod variance;
|
|||
use std::hash::Hash;
|
||||
|
||||
use chalk_ir::{
|
||||
NoSolution, VariableKinds,
|
||||
VariableKinds,
|
||||
fold::{Shift, TypeFoldable},
|
||||
interner::HasInterner,
|
||||
};
|
||||
|
|
@ -74,15 +74,16 @@ use la_arena::{Arena, Idx};
|
|||
use mir::{MirEvalError, VTableMap};
|
||||
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
|
||||
use rustc_type_ir::{
|
||||
UpcastFrom,
|
||||
inherent::{SliceLike, Ty as _},
|
||||
TypeSuperVisitable, TypeVisitableExt, UpcastFrom,
|
||||
inherent::{IntoKind, SliceLike, Ty as _},
|
||||
};
|
||||
use syntax::ast::{ConstArg, make};
|
||||
use traits::FnTrait;
|
||||
use triomphe::Arc;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
use crate::next_solver::ErrorGuaranteed;
|
||||
use crate::{
|
||||
consteval::unknown_const,
|
||||
db::HirDatabase,
|
||||
display::{DisplayTarget, HirDisplay},
|
||||
generics::Generics,
|
||||
|
|
@ -104,11 +105,10 @@ pub use infer::{
|
|||
could_coerce, could_unify, could_unify_deeply,
|
||||
};
|
||||
pub use interner::Interner;
|
||||
pub use lower::{
|
||||
ImplTraitLoweringMode, LifetimeElisionKind, ParamLoweringMode, TyDefId, TyLoweringContext,
|
||||
ValueTyDefId, diagnostics::*,
|
||||
pub use lower::{ImplTraitLoweringMode, ParamLoweringMode, TyDefId, ValueTyDefId, diagnostics::*};
|
||||
pub use lower_nextsolver::{
|
||||
LifetimeElisionKind, TyLoweringContext, associated_type_shorthand_candidates,
|
||||
};
|
||||
pub use lower_nextsolver::associated_type_shorthand_candidates;
|
||||
pub use mapping::{
|
||||
ToChalk, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, from_placeholder_idx,
|
||||
lt_from_placeholder_idx, lt_to_placeholder_idx, to_assoc_type_id, to_chalk_trait_id,
|
||||
|
|
@ -124,20 +124,16 @@ pub use utils::{
|
|||
};
|
||||
pub use variance::Variance;
|
||||
|
||||
pub use chalk_ir::{
|
||||
AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind,
|
||||
cast::Cast,
|
||||
visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor},
|
||||
};
|
||||
use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Safety, Scalar};
|
||||
|
||||
pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
|
||||
pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
|
||||
pub type FnDefId = chalk_ir::FnDefId<Interner>;
|
||||
pub type ClosureId = chalk_ir::ClosureId<Interner>;
|
||||
pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
|
||||
pub type PlaceholderIndex = chalk_ir::PlaceholderIndex;
|
||||
pub(crate) type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
|
||||
pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
|
||||
pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>;
|
||||
pub(crate) type ClosureId = chalk_ir::ClosureId<Interner>;
|
||||
pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
|
||||
pub(crate) type PlaceholderIndex = chalk_ir::PlaceholderIndex;
|
||||
|
||||
pub type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>;
|
||||
pub(crate) type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>;
|
||||
|
||||
pub(crate) type VariableKind = chalk_ir::VariableKind<Interner>;
|
||||
/// Represents generic parameters and an item bound by them. When the item has parent, the binders
|
||||
|
|
@ -148,49 +144,48 @@ pub(crate) type VariableKind = chalk_ir::VariableKind<Interner>;
|
|||
/// parameters/arguments for an item MUST come before those for its parent. This is to facilitate
|
||||
/// the integration with chalk-solve, which mildly puts constraints as such. See #13335 for its
|
||||
/// motivation in detail.
|
||||
pub type Binders<T> = chalk_ir::Binders<T>;
|
||||
pub(crate) type Binders<T> = chalk_ir::Binders<T>;
|
||||
/// Interned list of generic arguments for an item. When an item has parent, the `Substitution` for
|
||||
/// it contains generic arguments for both its parent and itself. See chalk's documentation for
|
||||
/// details.
|
||||
///
|
||||
/// See `Binders` for the constraint on the ordering.
|
||||
pub type Substitution = chalk_ir::Substitution<Interner>;
|
||||
pub type GenericArg = chalk_ir::GenericArg<Interner>;
|
||||
pub type GenericArgData = chalk_ir::GenericArgData<Interner>;
|
||||
pub(crate) type Substitution = chalk_ir::Substitution<Interner>;
|
||||
pub(crate) type GenericArg = chalk_ir::GenericArg<Interner>;
|
||||
pub(crate) type GenericArgData = chalk_ir::GenericArgData<Interner>;
|
||||
|
||||
pub type Ty = chalk_ir::Ty<Interner>;
|
||||
pub(crate) type Ty = chalk_ir::Ty<Interner>;
|
||||
pub type TyKind = chalk_ir::TyKind<Interner>;
|
||||
pub type TypeFlags = chalk_ir::TypeFlags;
|
||||
pub(crate) type TypeFlags = chalk_ir::TypeFlags;
|
||||
pub(crate) type DynTy = chalk_ir::DynTy<Interner>;
|
||||
pub type FnPointer = chalk_ir::FnPointer<Interner>;
|
||||
pub(crate) type FnPointer = chalk_ir::FnPointer<Interner>;
|
||||
pub(crate) use chalk_ir::FnSubst; // a re-export so we don't lose the tuple constructor
|
||||
|
||||
pub type AliasTy = chalk_ir::AliasTy<Interner>;
|
||||
|
||||
pub type ProjectionTy = chalk_ir::ProjectionTy<Interner>;
|
||||
pub(crate) type ProjectionTy = chalk_ir::ProjectionTy<Interner>;
|
||||
pub(crate) type OpaqueTy = chalk_ir::OpaqueTy<Interner>;
|
||||
pub(crate) type InferenceVar = chalk_ir::InferenceVar;
|
||||
|
||||
pub(crate) type Lifetime = chalk_ir::Lifetime<Interner>;
|
||||
pub(crate) type LifetimeData = chalk_ir::LifetimeData<Interner>;
|
||||
pub(crate) type LifetimeOutlives = chalk_ir::LifetimeOutlives<Interner>;
|
||||
|
||||
pub type ConstValue = chalk_ir::ConstValue<Interner>;
|
||||
pub(crate) type ConstValue = chalk_ir::ConstValue<Interner>;
|
||||
|
||||
pub type Const = chalk_ir::Const<Interner>;
|
||||
pub(crate) type Const = chalk_ir::Const<Interner>;
|
||||
pub(crate) type ConstData = chalk_ir::ConstData<Interner>;
|
||||
pub(crate) type ConcreteConst = chalk_ir::ConcreteConst<Interner>;
|
||||
|
||||
pub type TraitRef = chalk_ir::TraitRef<Interner>;
|
||||
pub type QuantifiedWhereClause = Binders<WhereClause>;
|
||||
pub type Canonical<T> = chalk_ir::Canonical<T>;
|
||||
pub(crate) type TraitRef = chalk_ir::TraitRef<Interner>;
|
||||
pub(crate) type QuantifiedWhereClause = Binders<WhereClause>;
|
||||
pub(crate) type Canonical<T> = chalk_ir::Canonical<T>;
|
||||
|
||||
pub(crate) type ChalkTraitId = chalk_ir::TraitId<Interner>;
|
||||
pub(crate) type QuantifiedWhereClauses = chalk_ir::QuantifiedWhereClauses<Interner>;
|
||||
|
||||
pub(crate) type FnSig = chalk_ir::FnSig<Interner>;
|
||||
|
||||
pub type InEnvironment<T> = chalk_ir::InEnvironment<T>;
|
||||
pub(crate) type InEnvironment<T> = chalk_ir::InEnvironment<T>;
|
||||
pub type AliasEq = chalk_ir::AliasEq<Interner>;
|
||||
pub type WhereClause = chalk_ir::WhereClause<Interner>;
|
||||
|
||||
|
|
@ -717,130 +712,167 @@ pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<
|
|||
/// 'Canonicalizes' the `t` by replacing any errors with new variables. Also
|
||||
/// ensures there are no unbound variables or inference variables anywhere in
|
||||
/// the `t`.
|
||||
pub fn replace_errors_with_variables<T>(t: &T) -> Canonical<T>
|
||||
pub fn replace_errors_with_variables<'db, T>(
|
||||
interner: DbInterner<'db>,
|
||||
t: &T,
|
||||
) -> crate::next_solver::Canonical<'db, T>
|
||||
where
|
||||
T: HasInterner<Interner = Interner> + TypeFoldable<Interner> + Clone,
|
||||
T: rustc_type_ir::TypeFoldable<DbInterner<'db>> + Clone,
|
||||
{
|
||||
use chalk_ir::{
|
||||
Fallible,
|
||||
fold::{FallibleTypeFolder, TypeSuperFoldable},
|
||||
};
|
||||
struct ErrorReplacer {
|
||||
vars: usize,
|
||||
use rustc_type_ir::{FallibleTypeFolder, TypeSuperFoldable};
|
||||
struct ErrorReplacer<'db> {
|
||||
interner: DbInterner<'db>,
|
||||
vars: Vec<crate::next_solver::CanonicalVarKind<'db>>,
|
||||
binder: rustc_type_ir::DebruijnIndex,
|
||||
}
|
||||
impl FallibleTypeFolder<Interner> for ErrorReplacer {
|
||||
type Error = NoSolution;
|
||||
impl<'db> FallibleTypeFolder<DbInterner<'db>> for ErrorReplacer<'db> {
|
||||
#[cfg(debug_assertions)]
|
||||
type Error = ();
|
||||
#[cfg(not(debug_assertions))]
|
||||
type Error = std::convert::Infallible;
|
||||
|
||||
fn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<Interner, Error = Self::Error> {
|
||||
self
|
||||
fn cx(&self) -> DbInterner<'db> {
|
||||
self.interner
|
||||
}
|
||||
|
||||
fn interner(&self) -> Interner {
|
||||
Interner
|
||||
fn try_fold_binder<T>(
|
||||
&mut self,
|
||||
t: crate::next_solver::Binder<'db, T>,
|
||||
) -> Result<crate::next_solver::Binder<'db, T>, Self::Error>
|
||||
where
|
||||
T: rustc_type_ir::TypeFoldable<DbInterner<'db>>,
|
||||
{
|
||||
self.binder.shift_in(1);
|
||||
let result = t.try_super_fold_with(self);
|
||||
self.binder.shift_out(1);
|
||||
result
|
||||
}
|
||||
|
||||
fn try_fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
|
||||
if let TyKind::Error = ty.kind(Interner) {
|
||||
let index = self.vars;
|
||||
self.vars += 1;
|
||||
Ok(TyKind::BoundVar(BoundVar::new(outer_binder, index)).intern(Interner))
|
||||
} else {
|
||||
ty.try_super_fold_with(self.as_dyn(), outer_binder)
|
||||
fn try_fold_ty(
|
||||
&mut self,
|
||||
t: crate::next_solver::Ty<'db>,
|
||||
) -> Result<crate::next_solver::Ty<'db>, Self::Error> {
|
||||
if !t.has_type_flags(
|
||||
rustc_type_ir::TypeFlags::HAS_ERROR
|
||||
| rustc_type_ir::TypeFlags::HAS_TY_INFER
|
||||
| rustc_type_ir::TypeFlags::HAS_CT_INFER
|
||||
| rustc_type_ir::TypeFlags::HAS_RE_INFER,
|
||||
) {
|
||||
return Ok(t);
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
let error = || Err(());
|
||||
#[cfg(not(debug_assertions))]
|
||||
let error = || Ok(crate::next_solver::Ty::new_error(self.interner, ErrorGuaranteed));
|
||||
|
||||
match t.kind() {
|
||||
crate::next_solver::TyKind::Error(_) => {
|
||||
let var = rustc_type_ir::BoundVar::from_usize(self.vars.len());
|
||||
self.vars.push(crate::next_solver::CanonicalVarKind::Ty {
|
||||
ui: rustc_type_ir::UniverseIndex::ZERO,
|
||||
sub_root: var,
|
||||
});
|
||||
Ok(crate::next_solver::Ty::new_bound(
|
||||
self.interner,
|
||||
self.binder,
|
||||
crate::next_solver::BoundTy {
|
||||
var,
|
||||
kind: crate::next_solver::BoundTyKind::Anon,
|
||||
},
|
||||
))
|
||||
}
|
||||
crate::next_solver::TyKind::Infer(_) => error(),
|
||||
crate::next_solver::TyKind::Bound(index, _) if index > self.binder => error(),
|
||||
_ => t.try_super_fold_with(self),
|
||||
}
|
||||
}
|
||||
|
||||
fn try_fold_inference_ty(
|
||||
fn try_fold_const(
|
||||
&mut self,
|
||||
_var: InferenceVar,
|
||||
_kind: TyVariableKind,
|
||||
_outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Ty> {
|
||||
if cfg!(debug_assertions) {
|
||||
// we don't want to just panic here, because then the error message
|
||||
// won't contain the whole thing, which would not be very helpful
|
||||
Err(NoSolution)
|
||||
} else {
|
||||
Ok(TyKind::Error.intern(Interner))
|
||||
ct: crate::next_solver::Const<'db>,
|
||||
) -> Result<crate::next_solver::Const<'db>, Self::Error> {
|
||||
if !ct.has_type_flags(
|
||||
rustc_type_ir::TypeFlags::HAS_ERROR
|
||||
| rustc_type_ir::TypeFlags::HAS_TY_INFER
|
||||
| rustc_type_ir::TypeFlags::HAS_CT_INFER
|
||||
| rustc_type_ir::TypeFlags::HAS_RE_INFER,
|
||||
) {
|
||||
return Ok(ct);
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
let error = || Err(());
|
||||
#[cfg(not(debug_assertions))]
|
||||
let error = || Ok(crate::next_solver::Const::error(self.interner));
|
||||
|
||||
match ct.kind() {
|
||||
crate::next_solver::ConstKind::Error(_) => {
|
||||
let var = rustc_type_ir::BoundVar::from_usize(self.vars.len());
|
||||
self.vars.push(crate::next_solver::CanonicalVarKind::Const(
|
||||
rustc_type_ir::UniverseIndex::ZERO,
|
||||
));
|
||||
Ok(crate::next_solver::Const::new_bound(
|
||||
self.interner,
|
||||
self.binder,
|
||||
crate::next_solver::BoundConst { var },
|
||||
))
|
||||
}
|
||||
crate::next_solver::ConstKind::Infer(_) => error(),
|
||||
crate::next_solver::ConstKind::Bound(index, _) if index > self.binder => error(),
|
||||
_ => ct.try_super_fold_with(self),
|
||||
}
|
||||
}
|
||||
|
||||
fn try_fold_free_var_ty(
|
||||
fn try_fold_region(
|
||||
&mut self,
|
||||
_bound_var: BoundVar,
|
||||
_outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Ty> {
|
||||
if cfg!(debug_assertions) {
|
||||
// we don't want to just panic here, because then the error message
|
||||
// won't contain the whole thing, which would not be very helpful
|
||||
Err(NoSolution)
|
||||
} else {
|
||||
Ok(TyKind::Error.intern(Interner))
|
||||
region: crate::next_solver::Region<'db>,
|
||||
) -> Result<crate::next_solver::Region<'db>, Self::Error> {
|
||||
#[cfg(debug_assertions)]
|
||||
let error = || Err(());
|
||||
#[cfg(not(debug_assertions))]
|
||||
let error = || Ok(crate::next_solver::Region::error(self.interner));
|
||||
|
||||
match region.kind() {
|
||||
crate::next_solver::RegionKind::ReError(_) => {
|
||||
let var = rustc_type_ir::BoundVar::from_usize(self.vars.len());
|
||||
self.vars.push(crate::next_solver::CanonicalVarKind::Region(
|
||||
rustc_type_ir::UniverseIndex::ZERO,
|
||||
));
|
||||
Ok(crate::next_solver::Region::new_bound(
|
||||
self.interner,
|
||||
self.binder,
|
||||
crate::next_solver::BoundRegion {
|
||||
var,
|
||||
kind: crate::next_solver::BoundRegionKind::Anon,
|
||||
},
|
||||
))
|
||||
}
|
||||
crate::next_solver::RegionKind::ReVar(_) => error(),
|
||||
crate::next_solver::RegionKind::ReBound(index, _) if index > self.binder => error(),
|
||||
_ => Ok(region),
|
||||
}
|
||||
}
|
||||
|
||||
fn try_fold_inference_const(
|
||||
&mut self,
|
||||
ty: Ty,
|
||||
_var: InferenceVar,
|
||||
_outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Const> {
|
||||
if cfg!(debug_assertions) {
|
||||
Err(NoSolution)
|
||||
} else {
|
||||
let interner = DbInterner::conjure();
|
||||
Ok(unknown_const(ty.to_nextsolver(interner)).to_chalk(interner))
|
||||
}
|
||||
}
|
||||
|
||||
fn try_fold_free_var_const(
|
||||
&mut self,
|
||||
ty: Ty,
|
||||
_bound_var: BoundVar,
|
||||
_outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Const> {
|
||||
if cfg!(debug_assertions) {
|
||||
Err(NoSolution)
|
||||
} else {
|
||||
let interner = DbInterner::conjure();
|
||||
Ok(unknown_const(ty.to_nextsolver(interner)).to_chalk(interner))
|
||||
}
|
||||
}
|
||||
|
||||
fn try_fold_inference_lifetime(
|
||||
&mut self,
|
||||
_var: InferenceVar,
|
||||
_outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Lifetime> {
|
||||
if cfg!(debug_assertions) { Err(NoSolution) } else { Ok(error_lifetime()) }
|
||||
}
|
||||
|
||||
fn try_fold_free_var_lifetime(
|
||||
&mut self,
|
||||
_bound_var: BoundVar,
|
||||
_outer_binder: DebruijnIndex,
|
||||
) -> Fallible<Lifetime> {
|
||||
if cfg!(debug_assertions) { Err(NoSolution) } else { Ok(error_lifetime()) }
|
||||
}
|
||||
}
|
||||
let mut error_replacer = ErrorReplacer { vars: 0 };
|
||||
let value = match t.clone().try_fold_with(&mut error_replacer, DebruijnIndex::INNERMOST) {
|
||||
|
||||
let mut error_replacer =
|
||||
ErrorReplacer { vars: Vec::new(), binder: rustc_type_ir::DebruijnIndex::ZERO, interner };
|
||||
let value = match t.clone().try_fold_with(&mut error_replacer) {
|
||||
Ok(t) => t,
|
||||
Err(_) => panic!("Encountered unbound or inference vars in {t:?}"),
|
||||
};
|
||||
let kinds = (0..error_replacer.vars).map(|_| {
|
||||
chalk_ir::CanonicalVarKind::new(
|
||||
chalk_ir::VariableKind::Ty(TyVariableKind::General),
|
||||
chalk_ir::UniverseIndex::ROOT,
|
||||
)
|
||||
});
|
||||
Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(Interner, kinds) }
|
||||
crate::next_solver::Canonical {
|
||||
value,
|
||||
max_universe: rustc_type_ir::UniverseIndex::ZERO,
|
||||
variables: crate::next_solver::CanonicalVars::new_from_iter(interner, error_replacer.vars),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn callable_sig_from_fn_trait<'db>(
|
||||
self_ty: &Ty,
|
||||
self_ty: crate::next_solver::Ty<'db>,
|
||||
trait_env: Arc<TraitEnvironment<'db>>,
|
||||
db: &'db dyn HirDatabase,
|
||||
) -> Option<(FnTrait, CallableSig)> {
|
||||
) -> Option<(FnTrait, crate::next_solver::PolyFnSig<'db>)> {
|
||||
let krate = trait_env.krate;
|
||||
let fn_once_trait = FnTrait::FnOnce.get_id(db, krate)?;
|
||||
let output_assoc_type = fn_once_trait
|
||||
|
|
@ -857,7 +889,7 @@ pub fn callable_sig_from_fn_trait<'db>(
|
|||
// - Self: FnOnce<?args_ty>
|
||||
// - <Self as FnOnce<?args_ty>>::Output == ?ret_ty
|
||||
let args_ty = table.next_ty_var();
|
||||
let args = [self_ty.to_nextsolver(table.interner()), args_ty];
|
||||
let args = [self_ty, args_ty];
|
||||
let trait_ref = crate::next_solver::TraitRef::new(table.interner(), fn_once_trait.into(), args);
|
||||
let projection = crate::next_solver::Ty::new_alias(
|
||||
table.interner(),
|
||||
|
|
@ -880,23 +912,24 @@ pub fn callable_sig_from_fn_trait<'db>(
|
|||
))
|
||||
.no_solution()
|
||||
{
|
||||
let ret_ty = table.resolve_completely(return_ty).to_chalk(table.interner());
|
||||
let args_ty = table.resolve_completely(args_ty).to_chalk(table.interner());
|
||||
let params = args_ty
|
||||
.as_tuple()?
|
||||
.iter(Interner)
|
||||
.map(|it| it.assert_ty_ref(Interner))
|
||||
.cloned();
|
||||
let ret_ty = table.resolve_completely(return_ty);
|
||||
let args_ty = table.resolve_completely(args_ty);
|
||||
let crate::next_solver::TyKind::Tuple(params) = args_ty.kind() else {
|
||||
return None;
|
||||
};
|
||||
let inputs_and_output = crate::next_solver::Tys::new_from_iter(
|
||||
table.interner(),
|
||||
params.iter().chain(std::iter::once(ret_ty)),
|
||||
);
|
||||
|
||||
return Some((
|
||||
fn_x,
|
||||
CallableSig::from_params_and_return(
|
||||
params,
|
||||
ret_ty,
|
||||
false,
|
||||
Safety::Safe,
|
||||
FnAbi::RustCall,
|
||||
),
|
||||
crate::next_solver::Binder::dummy(crate::next_solver::FnSig {
|
||||
inputs_and_output,
|
||||
c_variadic: false,
|
||||
safety: crate::next_solver::abi::Safety::Safe,
|
||||
abi: FnAbi::RustCall,
|
||||
}),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -906,74 +939,43 @@ pub fn callable_sig_from_fn_trait<'db>(
|
|||
}
|
||||
}
|
||||
|
||||
struct PlaceholderCollector<'db> {
|
||||
db: &'db dyn HirDatabase,
|
||||
placeholders: FxHashSet<TypeOrConstParamId>,
|
||||
struct ParamCollector {
|
||||
params: FxHashSet<TypeOrConstParamId>,
|
||||
}
|
||||
|
||||
impl PlaceholderCollector<'_> {
|
||||
fn collect(&mut self, idx: PlaceholderIndex) {
|
||||
let id = from_placeholder_idx(self.db, idx).0;
|
||||
self.placeholders.insert(id);
|
||||
}
|
||||
}
|
||||
impl<'db> rustc_type_ir::TypeVisitor<DbInterner<'db>> for ParamCollector {
|
||||
type Result = ();
|
||||
|
||||
impl TypeVisitor<Interner> for PlaceholderCollector<'_> {
|
||||
type BreakTy = ();
|
||||
|
||||
fn as_dyn(&mut self) -> &mut dyn TypeVisitor<Interner, BreakTy = Self::BreakTy> {
|
||||
self
|
||||
}
|
||||
|
||||
fn interner(&self) -> Interner {
|
||||
Interner
|
||||
}
|
||||
|
||||
fn visit_ty(
|
||||
&mut self,
|
||||
ty: &Ty,
|
||||
outer_binder: DebruijnIndex,
|
||||
) -> std::ops::ControlFlow<Self::BreakTy> {
|
||||
let has_placeholder_bits = TypeFlags::HAS_TY_PLACEHOLDER | TypeFlags::HAS_CT_PLACEHOLDER;
|
||||
let chalk_ir::TyData { kind, flags } = ty.data(Interner);
|
||||
|
||||
if let TyKind::Placeholder(idx) = kind {
|
||||
self.collect(*idx);
|
||||
} else if flags.intersects(has_placeholder_bits) {
|
||||
return ty.super_visit_with(self, outer_binder);
|
||||
} else {
|
||||
// Fast path: don't visit inner types (e.g. generic arguments) when `flags` indicate
|
||||
// that there are no placeholders.
|
||||
fn visit_ty(&mut self, ty: crate::next_solver::Ty<'db>) -> Self::Result {
|
||||
if let crate::next_solver::TyKind::Param(param) = ty.kind() {
|
||||
self.params.insert(param.id.into());
|
||||
}
|
||||
|
||||
std::ops::ControlFlow::Continue(())
|
||||
ty.super_visit_with(self);
|
||||
}
|
||||
|
||||
fn visit_const(
|
||||
&mut self,
|
||||
constant: &chalk_ir::Const<Interner>,
|
||||
_outer_binder: DebruijnIndex,
|
||||
) -> std::ops::ControlFlow<Self::BreakTy> {
|
||||
if let chalk_ir::ConstValue::Placeholder(idx) = constant.data(Interner).value {
|
||||
self.collect(idx);
|
||||
fn visit_const(&mut self, konst: crate::next_solver::Const<'db>) -> Self::Result {
|
||||
if let crate::next_solver::ConstKind::Param(param) = konst.kind() {
|
||||
self.params.insert(param.id.into());
|
||||
}
|
||||
std::ops::ControlFlow::Continue(())
|
||||
|
||||
konst.super_visit_with(self);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns unique placeholders for types and consts contained in `value`.
|
||||
pub fn collect_placeholders<T>(value: &T, db: &dyn HirDatabase) -> Vec<TypeOrConstParamId>
|
||||
/// Returns unique params for types and consts contained in `value`.
|
||||
pub fn collect_params<'db, T>(value: &T) -> Vec<TypeOrConstParamId>
|
||||
where
|
||||
T: ?Sized + TypeVisitable<Interner>,
|
||||
T: ?Sized + rustc_type_ir::TypeVisitable<DbInterner<'db>>,
|
||||
{
|
||||
let mut collector = PlaceholderCollector { db, placeholders: FxHashSet::default() };
|
||||
_ = value.visit_with(&mut collector, DebruijnIndex::INNERMOST);
|
||||
collector.placeholders.into_iter().collect()
|
||||
let mut collector = ParamCollector { params: FxHashSet::default() };
|
||||
value.visit_with(&mut collector);
|
||||
Vec::from_iter(collector.params)
|
||||
}
|
||||
|
||||
pub fn known_const_to_ast(
|
||||
konst: &Const,
|
||||
db: &dyn HirDatabase,
|
||||
pub fn known_const_to_ast<'db>(
|
||||
konst: crate::next_solver::Const<'db>,
|
||||
db: &'db dyn HirDatabase,
|
||||
display_target: DisplayTarget,
|
||||
) -> Option<ConstArg> {
|
||||
Some(make::expr_const_value(konst.display(db, display_target).to_string().as_str()))
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ impl ImplTraitLoweringState {
|
|||
pub(crate) struct PathDiagnosticCallbackData(pub(crate) TypeRefId);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum LifetimeElisionKind {
|
||||
pub(crate) enum LifetimeElisionKind {
|
||||
/// Create a new anonymous lifetime parameter and reference it.
|
||||
///
|
||||
/// If `report_in_path`, report an error when encountering lifetime elision in a path:
|
||||
|
|
@ -111,14 +111,6 @@ pub enum LifetimeElisionKind {
|
|||
/// error on default object bounds (e.g., `Box<dyn Foo>`).
|
||||
AnonymousReportError,
|
||||
|
||||
/// Resolves elided lifetimes to `'static` if there are no other lifetimes in scope,
|
||||
/// otherwise give a warning that the previous behavior of introducing a new early-bound
|
||||
/// lifetime is a bug and will be removed (if `only_lint` is enabled).
|
||||
StaticIfNoLifetimeInScope { only_lint: bool },
|
||||
|
||||
/// Signal we cannot find which should be the anonymous lifetime.
|
||||
ElisionFailure,
|
||||
|
||||
/// Infer all elided lifetimes.
|
||||
Infer,
|
||||
}
|
||||
|
|
@ -132,7 +124,7 @@ impl LifetimeElisionKind {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TyLoweringContext<'db> {
|
||||
pub(crate) struct TyLoweringContext<'db> {
|
||||
pub db: &'db dyn HirDatabase,
|
||||
resolver: &'db Resolver<'db>,
|
||||
store: &'db ExpressionStore,
|
||||
|
|
@ -152,7 +144,7 @@ pub struct TyLoweringContext<'db> {
|
|||
}
|
||||
|
||||
impl<'db> TyLoweringContext<'db> {
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
db: &'db dyn HirDatabase,
|
||||
resolver: &'db Resolver<'db>,
|
||||
store: &'db ExpressionStore,
|
||||
|
|
@ -177,7 +169,7 @@ impl<'db> TyLoweringContext<'db> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn with_debruijn<T>(
|
||||
pub(crate) fn with_debruijn<T>(
|
||||
&mut self,
|
||||
debruijn: DebruijnIndex,
|
||||
f: impl FnOnce(&mut TyLoweringContext<'_>) -> T,
|
||||
|
|
@ -188,7 +180,7 @@ impl<'db> TyLoweringContext<'db> {
|
|||
result
|
||||
}
|
||||
|
||||
pub fn with_shifted_in<T>(
|
||||
pub(crate) fn with_shifted_in<T>(
|
||||
&mut self,
|
||||
debruijn: DebruijnIndex,
|
||||
f: impl FnOnce(&mut TyLoweringContext<'_>) -> T,
|
||||
|
|
@ -207,25 +199,15 @@ impl<'db> TyLoweringContext<'db> {
|
|||
result
|
||||
}
|
||||
|
||||
pub fn with_impl_trait_mode(self, impl_trait_mode: ImplTraitLoweringMode) -> Self {
|
||||
pub(crate) fn with_impl_trait_mode(self, impl_trait_mode: ImplTraitLoweringMode) -> Self {
|
||||
Self { impl_trait_mode: ImplTraitLoweringState::new(impl_trait_mode), ..self }
|
||||
}
|
||||
|
||||
pub fn with_type_param_mode(self, type_param_mode: ParamLoweringMode) -> Self {
|
||||
pub(crate) fn with_type_param_mode(self, type_param_mode: ParamLoweringMode) -> Self {
|
||||
Self { type_param_mode, ..self }
|
||||
}
|
||||
|
||||
pub fn impl_trait_mode(&mut self, impl_trait_mode: ImplTraitLoweringMode) -> &mut Self {
|
||||
self.impl_trait_mode = ImplTraitLoweringState::new(impl_trait_mode);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn type_param_mode(&mut self, type_param_mode: ParamLoweringMode) -> &mut Self {
|
||||
self.type_param_mode = type_param_mode;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn push_diagnostic(&mut self, type_ref: TypeRefId, kind: TyLoweringDiagnosticKind) {
|
||||
pub(crate) fn push_diagnostic(&mut self, type_ref: TypeRefId, kind: TyLoweringDiagnosticKind) {
|
||||
self.diagnostics.push(TyLoweringDiagnostic { source: type_ref, kind });
|
||||
}
|
||||
}
|
||||
|
|
@ -249,11 +231,11 @@ pub enum ParamLoweringMode {
|
|||
}
|
||||
|
||||
impl<'db> TyLoweringContext<'db> {
|
||||
pub fn lower_ty(&mut self, type_ref: TypeRefId) -> Ty {
|
||||
pub(crate) fn lower_ty(&mut self, type_ref: TypeRefId) -> Ty {
|
||||
self.lower_ty_ext(type_ref).0
|
||||
}
|
||||
|
||||
pub fn lower_const(&mut self, const_ref: &ConstRef, const_type: Ty) -> Const {
|
||||
pub(crate) fn lower_const(&mut self, const_ref: &ConstRef, const_type: Ty) -> Const {
|
||||
let const_ref = &self.store[const_ref.expr];
|
||||
match const_ref {
|
||||
hir_def::hir::Expr::Path(path) => path_to_const(
|
||||
|
|
@ -308,7 +290,7 @@ impl<'db> TyLoweringContext<'db> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn lower_path_as_const(&mut self, path: &Path, const_type: Ty) -> Const {
|
||||
pub(crate) fn lower_path_as_const(&mut self, path: &Path, const_type: Ty) -> Const {
|
||||
path_to_const(
|
||||
self.db,
|
||||
self.resolver,
|
||||
|
|
@ -325,7 +307,7 @@ impl<'db> TyLoweringContext<'db> {
|
|||
self.generics.get_or_init(|| generics(self.db, self.def))
|
||||
}
|
||||
|
||||
pub fn lower_ty_ext(&mut self, type_ref_id: TypeRefId) -> (Ty, Option<TypeNs>) {
|
||||
pub(crate) fn lower_ty_ext(&mut self, type_ref_id: TypeRefId) -> (Ty, Option<TypeNs>) {
|
||||
let mut res = None;
|
||||
let type_ref = &self.store[type_ref_id];
|
||||
let ty = match type_ref {
|
||||
|
|
@ -774,7 +756,7 @@ impl<'db> TyLoweringContext<'db> {
|
|||
ImplTrait { bounds: crate::make_single_type_binders(predicates) }
|
||||
}
|
||||
|
||||
pub fn lower_lifetime(&self, lifetime: LifetimeRefId) -> Lifetime {
|
||||
pub(crate) fn lower_lifetime(&self, lifetime: LifetimeRefId) -> Lifetime {
|
||||
match self.resolver.resolve_lifetime(&self.store[lifetime]) {
|
||||
Some(resolution) => match resolution {
|
||||
LifetimeNs::Static => static_lifetime(),
|
||||
|
|
|
|||
|
|
@ -21,18 +21,17 @@ use stdx::never;
|
|||
use crate::{
|
||||
AliasEq, AliasTy, GenericArgsProhibitedReason, ImplTraitLoweringMode, IncorrectGenericsLenKind,
|
||||
Interner, ParamLoweringMode, PathGenericsSource, PathLoweringDiagnostic, ProjectionTy,
|
||||
QuantifiedWhereClause, Substitution, TraitRef, Ty, TyBuilder, TyDefId, TyKind,
|
||||
TyLoweringContext, WhereClause,
|
||||
QuantifiedWhereClause, Substitution, TraitRef, Ty, TyBuilder, TyDefId, TyKind, WhereClause,
|
||||
consteval_chalk::{unknown_const, unknown_const_as_generic},
|
||||
db::HirDatabase,
|
||||
error_lifetime,
|
||||
generics::{Generics, generics},
|
||||
lower::{LifetimeElisionKind, named_associated_type_shorthand_candidates},
|
||||
lower::{LifetimeElisionKind, TyLoweringContext, named_associated_type_shorthand_candidates},
|
||||
next_solver::{
|
||||
DbInterner,
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk},
|
||||
},
|
||||
static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
|
||||
to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
|
||||
utils::associated_type_by_name_including_super_traits,
|
||||
};
|
||||
|
||||
|
|
@ -650,14 +649,6 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
});
|
||||
}
|
||||
|
||||
fn report_elision_failure(&mut self, def: GenericDefId, expected_count: u32) {
|
||||
self.ctx.on_diagnostic(PathLoweringDiagnostic::ElisionFailure {
|
||||
generics_source: self.generics_source,
|
||||
def,
|
||||
expected_count,
|
||||
});
|
||||
}
|
||||
|
||||
fn report_missing_lifetime(&mut self, def: GenericDefId, expected_count: u32) {
|
||||
self.ctx.on_diagnostic(PathLoweringDiagnostic::MissingLifetime {
|
||||
generics_source: self.generics_source,
|
||||
|
|
@ -810,8 +801,6 @@ pub(crate) trait GenericArgsLowerer {
|
|||
hard_error: bool,
|
||||
);
|
||||
|
||||
fn report_elision_failure(&mut self, def: GenericDefId, expected_count: u32);
|
||||
|
||||
fn report_missing_lifetime(&mut self, def: GenericDefId, expected_count: u32);
|
||||
|
||||
fn report_len_mismatch(
|
||||
|
|
@ -884,13 +873,6 @@ fn check_generic_args_len(
|
|||
ctx.report_missing_lifetime(def, lifetime_args_len as u32);
|
||||
had_error = true
|
||||
}
|
||||
LifetimeElisionKind::ElisionFailure => {
|
||||
ctx.report_elision_failure(def, lifetime_args_len as u32);
|
||||
had_error = true;
|
||||
}
|
||||
LifetimeElisionKind::StaticIfNoLifetimeInScope { only_lint: _ } => {
|
||||
// FIXME: Check there are other lifetimes in scope, and error/lint.
|
||||
}
|
||||
LifetimeElisionKind::Elided(_) => {
|
||||
ctx.report_elided_lifetimes_in_path(def, lifetime_args_len as u32, false);
|
||||
}
|
||||
|
|
@ -1099,15 +1081,11 @@ pub(crate) fn substs_from_args_and_bindings(
|
|||
// If there are fewer arguments than parameters, it means we're inferring the remaining arguments.
|
||||
let param = if let GenericParamId::LifetimeParamId(_) = param_id {
|
||||
match &lifetime_elision {
|
||||
LifetimeElisionKind::ElisionFailure
|
||||
| LifetimeElisionKind::AnonymousCreateParameter { report_in_path: true }
|
||||
LifetimeElisionKind::AnonymousCreateParameter { report_in_path: true }
|
||||
| LifetimeElisionKind::AnonymousReportError => {
|
||||
assert!(had_count_error);
|
||||
ctx.inferred_kind(def, param_id, param, infer_args, &substs)
|
||||
}
|
||||
LifetimeElisionKind::StaticIfNoLifetimeInScope { only_lint: _ } => {
|
||||
static_lifetime().cast(Interner)
|
||||
}
|
||||
LifetimeElisionKind::Elided(lifetime) => lifetime.clone().cast(Interner),
|
||||
LifetimeElisionKind::AnonymousCreateParameter { report_in_path: false }
|
||||
| LifetimeElisionKind::Infer => {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ use hir_def::{ConstId, LifetimeParamId, StaticId, TypeParamId};
|
|||
use hir_expand::name::Name;
|
||||
use intern::{Symbol, sym};
|
||||
use la_arena::{Arena, ArenaMap, Idx};
|
||||
use path::{PathDiagnosticCallback, PathLoweringContext, builtin};
|
||||
use path::{PathDiagnosticCallback, PathLoweringContext};
|
||||
use rustc_ast_ir::Mutability;
|
||||
use rustc_hash::FxHashSet;
|
||||
use rustc_pattern_analysis::Captures;
|
||||
|
|
@ -105,7 +105,7 @@ impl<'db> ImplTraitLoweringState<'db> {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) enum LifetimeElisionKind<'db> {
|
||||
pub enum LifetimeElisionKind<'db> {
|
||||
/// Create a new anonymous lifetime parameter and reference it.
|
||||
///
|
||||
/// If `report_in_path`, report an error when encountering lifetime elision in a path:
|
||||
|
|
@ -174,7 +174,7 @@ impl<'db> LifetimeElisionKind<'db> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct TyLoweringContext<'db, 'a> {
|
||||
pub struct TyLoweringContext<'db, 'a> {
|
||||
pub db: &'db dyn HirDatabase,
|
||||
interner: DbInterner<'db>,
|
||||
resolver: &'a Resolver<'db>,
|
||||
|
|
@ -192,7 +192,7 @@ pub(crate) struct TyLoweringContext<'db, 'a> {
|
|||
}
|
||||
|
||||
impl<'db, 'a> TyLoweringContext<'db, 'a> {
|
||||
pub(crate) fn new(
|
||||
pub fn new(
|
||||
db: &'db dyn HirDatabase,
|
||||
resolver: &'a Resolver<'db>,
|
||||
store: &'a ExpressionStore,
|
||||
|
|
@ -271,7 +271,7 @@ pub(crate) enum ImplTraitLoweringMode {
|
|||
}
|
||||
|
||||
impl<'db, 'a> TyLoweringContext<'db, 'a> {
|
||||
pub(crate) fn lower_ty(&mut self, type_ref: TypeRefId) -> Ty<'db> {
|
||||
pub fn lower_ty(&mut self, type_ref: TypeRefId) -> Ty<'db> {
|
||||
self.lower_ty_ext(type_ref).0
|
||||
}
|
||||
|
||||
|
|
@ -361,7 +361,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(self), ret)]
|
||||
pub(crate) fn lower_ty_ext(&mut self, type_ref_id: TypeRefId) -> (Ty<'db>, Option<TypeNs>) {
|
||||
pub fn lower_ty_ext(&mut self, type_ref_id: TypeRefId) -> (Ty<'db>, Option<TypeNs>) {
|
||||
let interner = self.interner;
|
||||
let mut res = None;
|
||||
let type_ref = &self.store[type_ref_id];
|
||||
|
|
@ -1013,7 +1013,7 @@ pub(crate) fn type_alias_impl_traits<'db>(
|
|||
pub(crate) fn ty_query<'db>(db: &'db dyn HirDatabase, def: TyDefId) -> EarlyBinder<'db, Ty<'db>> {
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
match def {
|
||||
TyDefId::BuiltinType(it) => EarlyBinder::bind(builtin(interner, it)),
|
||||
TyDefId::BuiltinType(it) => EarlyBinder::bind(Ty::from_builtin_type(interner, it)),
|
||||
TyDefId::AdtId(it) => EarlyBinder::bind(Ty::new_adt(
|
||||
interner,
|
||||
it,
|
||||
|
|
@ -1401,6 +1401,7 @@ pub(crate) fn generic_predicates_for_param_cycle_result(
|
|||
pub struct GenericPredicates<'db>(Option<Arc<[Clause<'db>]>>);
|
||||
|
||||
impl<'db> GenericPredicates<'db> {
|
||||
#[inline]
|
||||
pub fn instantiate(
|
||||
&self,
|
||||
interner: DbInterner<'db>,
|
||||
|
|
@ -1410,6 +1411,11 @@ impl<'db> GenericPredicates<'db> {
|
|||
.as_ref()
|
||||
.map(|it| EarlyBinder::bind(it.iter().copied()).iter_instantiated(interner, args))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn instantiate_identity(&self) -> Option<impl Iterator<Item = Clause<'db>>> {
|
||||
self.0.as_ref().map(|it| it.iter().copied())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> ops::Deref for GenericPredicates<'db> {
|
||||
|
|
@ -1458,8 +1464,7 @@ pub(crate) fn trait_environment_query<'db>(
|
|||
for pred in maybe_parent_generics.where_predicates() {
|
||||
for pred in ctx.lower_where_predicate(pred, false, &generics, PredicateFilter::All) {
|
||||
if let rustc_type_ir::ClauseKind::Trait(tr) = pred.kind().skip_binder() {
|
||||
traits_in_scope
|
||||
.push((convert_ty_for_result(interner, tr.self_ty()), tr.def_id().0));
|
||||
traits_in_scope.push((tr.self_ty(), tr.def_id().0));
|
||||
}
|
||||
clauses.push(pred);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -550,7 +550,9 @@ impl<'a, 'b, 'db> PathLoweringContext<'a, 'b, 'db> {
|
|||
|
||||
fn lower_path_inner(&mut self, typeable: TyDefId, infer_args: bool) -> Ty<'db> {
|
||||
let generic_def = match typeable {
|
||||
TyDefId::BuiltinType(builtinty) => return builtin(self.ctx.interner, builtinty),
|
||||
TyDefId::BuiltinType(builtinty) => {
|
||||
return Ty::from_builtin_type(self.ctx.interner, builtinty);
|
||||
}
|
||||
TyDefId::AdtId(it) => it.into(),
|
||||
TyDefId::TypeAliasId(it) => it.into(),
|
||||
};
|
||||
|
|
@ -1350,42 +1352,3 @@ fn unknown_subst<'db>(
|
|||
}),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn builtin<'db>(interner: DbInterner<'db>, builtin: BuiltinType) -> Ty<'db> {
|
||||
match builtin {
|
||||
BuiltinType::Char => Ty::new(interner, rustc_type_ir::TyKind::Char),
|
||||
BuiltinType::Bool => Ty::new_bool(interner),
|
||||
BuiltinType::Str => Ty::new(interner, rustc_type_ir::TyKind::Str),
|
||||
BuiltinType::Int(t) => {
|
||||
let int_ty = match primitive::int_ty_from_builtin(t) {
|
||||
chalk_ir::IntTy::Isize => rustc_type_ir::IntTy::Isize,
|
||||
chalk_ir::IntTy::I8 => rustc_type_ir::IntTy::I8,
|
||||
chalk_ir::IntTy::I16 => rustc_type_ir::IntTy::I16,
|
||||
chalk_ir::IntTy::I32 => rustc_type_ir::IntTy::I32,
|
||||
chalk_ir::IntTy::I64 => rustc_type_ir::IntTy::I64,
|
||||
chalk_ir::IntTy::I128 => rustc_type_ir::IntTy::I128,
|
||||
};
|
||||
Ty::new_int(interner, int_ty)
|
||||
}
|
||||
BuiltinType::Uint(t) => {
|
||||
let uint_ty = match primitive::uint_ty_from_builtin(t) {
|
||||
chalk_ir::UintTy::Usize => rustc_type_ir::UintTy::Usize,
|
||||
chalk_ir::UintTy::U8 => rustc_type_ir::UintTy::U8,
|
||||
chalk_ir::UintTy::U16 => rustc_type_ir::UintTy::U16,
|
||||
chalk_ir::UintTy::U32 => rustc_type_ir::UintTy::U32,
|
||||
chalk_ir::UintTy::U64 => rustc_type_ir::UintTy::U64,
|
||||
chalk_ir::UintTy::U128 => rustc_type_ir::UintTy::U128,
|
||||
};
|
||||
Ty::new_uint(interner, uint_ty)
|
||||
}
|
||||
BuiltinType::Float(t) => {
|
||||
let float_ty = match primitive::float_ty_from_builtin(t) {
|
||||
chalk_ir::FloatTy::F16 => rustc_type_ir::FloatTy::F16,
|
||||
chalk_ir::FloatTy::F32 => rustc_type_ir::FloatTy::F32,
|
||||
chalk_ir::FloatTy::F64 => rustc_type_ir::FloatTy::F64,
|
||||
chalk_ir::FloatTy::F128 => rustc_type_ir::FloatTy::F128,
|
||||
};
|
||||
Ty::new_float(interner, float_ty)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
use std::ops::ControlFlow;
|
||||
|
||||
use base_db::Crate;
|
||||
use chalk_ir::{UniverseIndex, WithKind, cast::Cast};
|
||||
use hir_def::{
|
||||
AdtId, AssocItemId, BlockId, ConstId, FunctionId, HasModule, ImplId, ItemContainerId, Lookup,
|
||||
ModuleId, TraitId, TypeAliasId,
|
||||
|
|
@ -29,8 +28,7 @@ use triomphe::Arc;
|
|||
use crate::next_solver::infer::InferCtxt;
|
||||
use crate::next_solver::infer::select::ImplSource;
|
||||
use crate::{
|
||||
CanonicalVarKinds, DebruijnIndex, GenericArgData, InEnvironment, Interner, TraitEnvironment,
|
||||
TyBuilder, VariableKind,
|
||||
TraitEnvironment, TyBuilder,
|
||||
autoderef::{self, AutoderefKind},
|
||||
db::HirDatabase,
|
||||
infer::{Adjust, Adjustment, OverloadedDeref, PointerCast, unify::InferenceTable},
|
||||
|
|
@ -42,7 +40,6 @@ use crate::{
|
|||
DbInternerInferExt, DefineOpaqueTypes,
|
||||
traits::{Obligation, ObligationCause, PredicateObligation},
|
||||
},
|
||||
mapping::NextSolverToChalk,
|
||||
obligation_ctxt::ObligationCtxt,
|
||||
},
|
||||
traits::next_trait_solve_canonical_in_ctxt,
|
||||
|
|
@ -1390,9 +1387,8 @@ fn iterate_inherent_methods<'db>(
|
|||
match self_ty.kind() {
|
||||
TyKind::Param(_) => {
|
||||
let env = table.trait_env.clone();
|
||||
let traits = env
|
||||
.traits_in_scope_from_clauses(self_ty.to_chalk(table.interner()))
|
||||
.flat_map(|t| all_super_traits(db, t));
|
||||
let traits =
|
||||
env.traits_in_scope_from_clauses(self_ty).flat_map(|t| all_super_traits(db, t));
|
||||
iterate_inherent_trait_methods(
|
||||
self_ty,
|
||||
table,
|
||||
|
|
@ -1755,50 +1751,6 @@ fn is_valid_impl_fn_candidate<'db>(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn implements_trait_unique<'db>(
|
||||
ty: &crate::Canonical<crate::Ty>,
|
||||
db: &'db dyn HirDatabase,
|
||||
env: &TraitEnvironment<'db>,
|
||||
trait_: TraitId,
|
||||
) -> bool {
|
||||
let goal = generic_implements_goal(db, env, trait_, ty);
|
||||
db.trait_solve(env.krate, env.block, goal.cast(Interner)).certain()
|
||||
}
|
||||
|
||||
/// This creates Substs for a trait with the given Self type and type variables
|
||||
/// for all other parameters, to query next solver with it.
|
||||
#[tracing::instrument(skip_all)]
|
||||
fn generic_implements_goal<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
env: &TraitEnvironment<'db>,
|
||||
trait_: TraitId,
|
||||
self_ty: &crate::Canonical<crate::Ty>,
|
||||
) -> crate::Canonical<crate::InEnvironment<crate::DomainGoal>> {
|
||||
let binders = self_ty.binders.interned();
|
||||
let trait_ref = TyBuilder::trait_ref(db, trait_)
|
||||
.push(self_ty.value.clone())
|
||||
.fill_with_bound_vars(DebruijnIndex::INNERMOST, binders.len())
|
||||
.build();
|
||||
|
||||
let kinds =
|
||||
binders.iter().cloned().chain(trait_ref.substitution.iter(Interner).skip(1).map(|it| {
|
||||
let vk = match it.data(Interner) {
|
||||
GenericArgData::Ty(_) => VariableKind::Ty(chalk_ir::TyVariableKind::General),
|
||||
GenericArgData::Lifetime(_) => VariableKind::Lifetime,
|
||||
GenericArgData::Const(c) => VariableKind::Const(c.data(Interner).ty.clone()),
|
||||
};
|
||||
WithKind::new(vk, UniverseIndex::ROOT)
|
||||
}));
|
||||
let binders = CanonicalVarKinds::from_iter(Interner, kinds);
|
||||
|
||||
let obligation = trait_ref.cast(Interner);
|
||||
let value = InEnvironment::new(
|
||||
&env.env.to_chalk(DbInterner::new_with(db, Some(env.krate), env.block)),
|
||||
obligation,
|
||||
);
|
||||
crate::Canonical { binders, value }
|
||||
}
|
||||
|
||||
/// This creates Substs for a trait with the given Self type and type variables
|
||||
/// for all other parameters, to query the trait solver with it.
|
||||
#[tracing::instrument(skip_all)]
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ use intern::{Interned, Symbol};
|
|||
use macros::{TypeFoldable, TypeVisitable};
|
||||
use rustc_ast_ir::{try_visit, visit::VisitorResult};
|
||||
use rustc_type_ir::{
|
||||
BoundVar, FlagComputation, Flags, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable,
|
||||
TypeVisitable, TypeVisitableExt, WithCachedTypeInfo,
|
||||
BoundVar, DebruijnIndex, FlagComputation, Flags, TypeFoldable, TypeSuperFoldable,
|
||||
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, WithCachedTypeInfo,
|
||||
inherent::{IntoKind, ParamEnv as _, PlaceholderLike, SliceLike},
|
||||
relate::Relate,
|
||||
};
|
||||
|
|
@ -62,6 +62,10 @@ impl<'db> Const<'db> {
|
|||
Const::new(interner, ConstKind::Placeholder(placeholder))
|
||||
}
|
||||
|
||||
pub fn new_bound(interner: DbInterner<'db>, index: DebruijnIndex, bound: BoundConst) -> Self {
|
||||
Const::new(interner, ConstKind::Bound(index, bound))
|
||||
}
|
||||
|
||||
pub fn new_valtree(
|
||||
interner: DbInterner<'db>,
|
||||
ty: Ty<'db>,
|
||||
|
|
@ -159,11 +163,11 @@ impl ParamConst {
|
|||
/// Represents a typed, fully evaluated constant.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, TypeFoldable, TypeVisitable)]
|
||||
pub struct ValueConst<'db> {
|
||||
pub(crate) ty: Ty<'db>,
|
||||
pub ty: Ty<'db>,
|
||||
// FIXME: Should we ignore this for TypeVisitable, TypeFoldable?
|
||||
#[type_visitable(ignore)]
|
||||
#[type_foldable(identity)]
|
||||
pub(crate) value: Valtree<'db>,
|
||||
pub value: Valtree<'db>,
|
||||
}
|
||||
|
||||
impl<'db> ValueConst<'db> {
|
||||
|
|
|
|||
|
|
@ -158,6 +158,15 @@ impl SolverDefId {
|
|||
_ => panic!("expected opaque type, found {self:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
pub fn expect_type_alias(self) -> TypeAliasId {
|
||||
match self {
|
||||
SolverDefId::TypeAliasId(it) => it,
|
||||
_ => panic!("expected type alias, found {self:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> inherent::DefId<DbInterner<'db>> for SolverDefId {
|
||||
|
|
|
|||
|
|
@ -69,6 +69,14 @@ impl<'db> GenericArg<'db> {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error_from_id(interner: DbInterner<'db>, id: GenericParamId) -> GenericArg<'db> {
|
||||
match id {
|
||||
GenericParamId::TypeParamId(_) => Ty::new_error(interner, ErrorGuaranteed).into(),
|
||||
GenericParamId::ConstParamId(_) => Const::error(interner).into(),
|
||||
GenericParamId::LifetimeParamId(_) => Region::error(interner).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db> From<Term<'db>> for GenericArg<'db> {
|
||||
|
|
@ -192,6 +200,13 @@ impl<'db> GenericArgs<'db> {
|
|||
interner.mk_args(&args)
|
||||
}
|
||||
|
||||
/// Creates an all-error `GenericArgs`.
|
||||
pub fn error_for_item(interner: DbInterner<'db>, def_id: SolverDefId) -> GenericArgs<'db> {
|
||||
GenericArgs::for_item(interner, def_id, |_, _, id, _| {
|
||||
GenericArg::error_from_id(interner, id)
|
||||
})
|
||||
}
|
||||
|
||||
/// Like `for_item`, but prefers the default of a parameter if it has any.
|
||||
pub fn for_item_with_defaults<F>(
|
||||
interner: DbInterner<'db>,
|
||||
|
|
|
|||
|
|
@ -304,6 +304,7 @@ impl<'db> DbInterner<'db> {
|
|||
DbInterner { db, krate, block }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn db(&self) -> &'db dyn HirDatabase {
|
||||
self.db
|
||||
}
|
||||
|
|
@ -1952,7 +1953,6 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
|
|||
false
|
||||
}
|
||||
|
||||
// FIXME(next-solver): Make this a query? Can this make cycles?
|
||||
fn impl_specializes(
|
||||
self,
|
||||
specializing_impl_def_id: Self::ImplId,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
use hir_def::LifetimeParamId;
|
||||
use intern::{Interned, Symbol};
|
||||
use rustc_type_ir::{
|
||||
BoundVar, Flags, INNERMOST, RegionVid, TypeFlags, TypeFoldable, TypeVisitable, VisitorResult,
|
||||
BoundVar, DebruijnIndex, Flags, INNERMOST, RegionVid, TypeFlags, TypeFoldable, TypeVisitable,
|
||||
VisitorResult,
|
||||
inherent::{IntoKind, PlaceholderLike, SliceLike},
|
||||
relate::Relate,
|
||||
};
|
||||
|
|
@ -62,6 +63,14 @@ impl<'db> Region<'db> {
|
|||
Region::new(interner, RegionKind::ReErased)
|
||||
}
|
||||
|
||||
pub fn new_bound(
|
||||
interner: DbInterner<'db>,
|
||||
index: DebruijnIndex,
|
||||
bound: BoundRegion,
|
||||
) -> Region<'db> {
|
||||
Region::new(interner, RegionKind::ReBound(index, bound))
|
||||
}
|
||||
|
||||
pub fn is_placeholder(&self) -> bool {
|
||||
matches!(self.inner(), RegionKind::RePlaceholder(..))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,18 +3,22 @@
|
|||
use std::iter;
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
use hir_def::type_ref::Rawness;
|
||||
use hir_def::{AdtId, GenericDefId, TypeOrConstParamId, TypeParamId};
|
||||
use hir_def::{
|
||||
AdtId, DefWithBodyId, GenericDefId, HasModule, TypeOrConstParamId, TypeParamId,
|
||||
hir::generics::{TypeOrConstParamData, TypeParamProvenance},
|
||||
lang_item::LangItem,
|
||||
};
|
||||
use hir_def::{TraitId, type_ref::Rawness};
|
||||
use intern::{Interned, Symbol, sym};
|
||||
use rustc_abi::{Float, Integer, Size};
|
||||
use rustc_ast_ir::{Mutability, try_visit, visit::VisitorResult};
|
||||
use rustc_type_ir::{
|
||||
BoundVar, ClosureKind, CollectAndApply, FlagComputation, Flags, FloatTy, FloatVid, InferTy,
|
||||
IntTy, IntVid, Interner, TyVid, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable,
|
||||
TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, WithCachedTypeInfo,
|
||||
AliasTyKind, BoundVar, ClosureKind, CollectAndApply, FlagComputation, Flags, FloatTy, FloatVid,
|
||||
InferTy, IntTy, IntVid, Interner, TyVid, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable,
|
||||
TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, Upcast, WithCachedTypeInfo,
|
||||
inherent::{
|
||||
Abi, AdtDef as _, BoundVarLike, Const as _, GenericArgs as _, IntoKind, ParamLike,
|
||||
PlaceholderLike, Safety as _, SliceLike, Ty as _,
|
||||
Abi, AdtDef as _, BoundExistentialPredicates, BoundVarLike, Const as _, GenericArgs as _,
|
||||
IntoKind, ParamLike, PlaceholderLike, Safety as _, SliceLike, Ty as _,
|
||||
},
|
||||
relate::Relate,
|
||||
solve::SizedTraitKind,
|
||||
|
|
@ -24,13 +28,14 @@ use salsa::plumbing::{AsId, FromId};
|
|||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{
|
||||
FnAbi,
|
||||
FnAbi, ImplTraitId,
|
||||
db::HirDatabase,
|
||||
interner::InternedWrapperNoDebug,
|
||||
next_solver::{
|
||||
AdtDef, Binder, CallableIdWrapper, ClosureIdWrapper, Const, CoroutineIdWrapper, FnSig,
|
||||
GenericArg, PolyFnSig, Region, TypeAliasIdWrapper,
|
||||
AdtDef, Binder, CallableIdWrapper, Clause, ClauseKind, ClosureIdWrapper, Const,
|
||||
CoroutineIdWrapper, FnSig, GenericArg, PolyFnSig, Region, TraitRef, TypeAliasIdWrapper,
|
||||
abi::Safety,
|
||||
mapping::ChalkToNextSolver,
|
||||
util::{CoroutineArgsExt, IntegerTypeExt},
|
||||
},
|
||||
};
|
||||
|
|
@ -409,7 +414,7 @@ impl<'db> Ty<'db> {
|
|||
|
||||
pub fn as_reference(self) -> Option<(Ty<'db>, Region<'db>, Mutability)> {
|
||||
match self.kind() {
|
||||
TyKind::Ref(lifetime, ty, mutability) => Some((ty, lifetime, mutability)),
|
||||
TyKind::Ref(region, ty, mutability) => Some((ty, region, mutability)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -422,6 +427,18 @@ impl<'db> Ty<'db> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn as_tuple(self) -> Option<Tys<'db>> {
|
||||
match self.kind() {
|
||||
TyKind::Tuple(tys) => Some(tys),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dyn_trait(self) -> Option<TraitId> {
|
||||
let TyKind::Dynamic(bounds, _) = self.kind() else { return None };
|
||||
Some(bounds.principal_def_id()?.0)
|
||||
}
|
||||
|
||||
pub fn strip_references(self) -> Ty<'db> {
|
||||
let mut t = self;
|
||||
while let TyKind::Ref(_lifetime, ty, _mutability) = t.kind() {
|
||||
|
|
@ -443,6 +460,176 @@ impl<'db> Ty<'db> {
|
|||
interner,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn from_builtin_type(
|
||||
interner: DbInterner<'db>,
|
||||
ty: hir_def::builtin_type::BuiltinType,
|
||||
) -> Ty<'db> {
|
||||
let kind = match ty {
|
||||
hir_def::builtin_type::BuiltinType::Char => TyKind::Char,
|
||||
hir_def::builtin_type::BuiltinType::Bool => TyKind::Bool,
|
||||
hir_def::builtin_type::BuiltinType::Str => TyKind::Str,
|
||||
hir_def::builtin_type::BuiltinType::Int(int) => TyKind::Int(match int {
|
||||
hir_def::builtin_type::BuiltinInt::Isize => rustc_type_ir::IntTy::Isize,
|
||||
hir_def::builtin_type::BuiltinInt::I8 => rustc_type_ir::IntTy::I8,
|
||||
hir_def::builtin_type::BuiltinInt::I16 => rustc_type_ir::IntTy::I16,
|
||||
hir_def::builtin_type::BuiltinInt::I32 => rustc_type_ir::IntTy::I32,
|
||||
hir_def::builtin_type::BuiltinInt::I64 => rustc_type_ir::IntTy::I64,
|
||||
hir_def::builtin_type::BuiltinInt::I128 => rustc_type_ir::IntTy::I128,
|
||||
}),
|
||||
hir_def::builtin_type::BuiltinType::Uint(uint) => TyKind::Uint(match uint {
|
||||
hir_def::builtin_type::BuiltinUint::Usize => rustc_type_ir::UintTy::Usize,
|
||||
hir_def::builtin_type::BuiltinUint::U8 => rustc_type_ir::UintTy::U8,
|
||||
hir_def::builtin_type::BuiltinUint::U16 => rustc_type_ir::UintTy::U16,
|
||||
hir_def::builtin_type::BuiltinUint::U32 => rustc_type_ir::UintTy::U32,
|
||||
hir_def::builtin_type::BuiltinUint::U64 => rustc_type_ir::UintTy::U64,
|
||||
hir_def::builtin_type::BuiltinUint::U128 => rustc_type_ir::UintTy::U128,
|
||||
}),
|
||||
hir_def::builtin_type::BuiltinType::Float(float) => TyKind::Float(match float {
|
||||
hir_def::builtin_type::BuiltinFloat::F16 => rustc_type_ir::FloatTy::F16,
|
||||
hir_def::builtin_type::BuiltinFloat::F32 => rustc_type_ir::FloatTy::F32,
|
||||
hir_def::builtin_type::BuiltinFloat::F64 => rustc_type_ir::FloatTy::F64,
|
||||
hir_def::builtin_type::BuiltinFloat::F128 => rustc_type_ir::FloatTy::F128,
|
||||
}),
|
||||
};
|
||||
Ty::new(interner, kind)
|
||||
}
|
||||
|
||||
pub fn as_builtin(self) -> Option<hir_def::builtin_type::BuiltinType> {
|
||||
let builtin = match self.kind() {
|
||||
TyKind::Char => hir_def::builtin_type::BuiltinType::Char,
|
||||
TyKind::Bool => hir_def::builtin_type::BuiltinType::Bool,
|
||||
TyKind::Str => hir_def::builtin_type::BuiltinType::Str,
|
||||
TyKind::Int(int) => hir_def::builtin_type::BuiltinType::Int(match int {
|
||||
rustc_type_ir::IntTy::Isize => hir_def::builtin_type::BuiltinInt::Isize,
|
||||
rustc_type_ir::IntTy::I8 => hir_def::builtin_type::BuiltinInt::I8,
|
||||
rustc_type_ir::IntTy::I16 => hir_def::builtin_type::BuiltinInt::I16,
|
||||
rustc_type_ir::IntTy::I32 => hir_def::builtin_type::BuiltinInt::I32,
|
||||
rustc_type_ir::IntTy::I64 => hir_def::builtin_type::BuiltinInt::I64,
|
||||
rustc_type_ir::IntTy::I128 => hir_def::builtin_type::BuiltinInt::I128,
|
||||
}),
|
||||
TyKind::Uint(uint) => hir_def::builtin_type::BuiltinType::Uint(match uint {
|
||||
rustc_type_ir::UintTy::Usize => hir_def::builtin_type::BuiltinUint::Usize,
|
||||
rustc_type_ir::UintTy::U8 => hir_def::builtin_type::BuiltinUint::U8,
|
||||
rustc_type_ir::UintTy::U16 => hir_def::builtin_type::BuiltinUint::U16,
|
||||
rustc_type_ir::UintTy::U32 => hir_def::builtin_type::BuiltinUint::U32,
|
||||
rustc_type_ir::UintTy::U64 => hir_def::builtin_type::BuiltinUint::U64,
|
||||
rustc_type_ir::UintTy::U128 => hir_def::builtin_type::BuiltinUint::U128,
|
||||
}),
|
||||
TyKind::Float(float) => hir_def::builtin_type::BuiltinType::Float(match float {
|
||||
rustc_type_ir::FloatTy::F16 => hir_def::builtin_type::BuiltinFloat::F16,
|
||||
rustc_type_ir::FloatTy::F32 => hir_def::builtin_type::BuiltinFloat::F32,
|
||||
rustc_type_ir::FloatTy::F64 => hir_def::builtin_type::BuiltinFloat::F64,
|
||||
rustc_type_ir::FloatTy::F128 => hir_def::builtin_type::BuiltinFloat::F128,
|
||||
}),
|
||||
_ => return None,
|
||||
};
|
||||
Some(builtin)
|
||||
}
|
||||
|
||||
// FIXME: Should this be here?
|
||||
pub fn impl_trait_bounds(self, db: &'db dyn HirDatabase) -> Option<Vec<Clause<'db>>> {
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
|
||||
match self.kind() {
|
||||
TyKind::Alias(AliasTyKind::Opaque, opaque_ty) => {
|
||||
match db.lookup_intern_impl_trait_id(opaque_ty.def_id.expect_opaque_ty()) {
|
||||
ImplTraitId::ReturnTypeImplTrait(func, idx) => {
|
||||
db.return_type_impl_traits_ns(func).map(|it| {
|
||||
let data = (*it).as_ref().map_bound(|rpit| {
|
||||
&rpit.impl_traits[idx.to_nextsolver(interner)].predicates
|
||||
});
|
||||
data.iter_instantiated_copied(interner, opaque_ty.args.as_slice())
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
ImplTraitId::TypeAliasImplTrait(alias, idx) => {
|
||||
db.type_alias_impl_traits_ns(alias).map(|it| {
|
||||
let data = (*it).as_ref().map_bound(|rpit| {
|
||||
&rpit.impl_traits[idx.to_nextsolver(interner)].predicates
|
||||
});
|
||||
data.iter_instantiated_copied(interner, opaque_ty.args.as_slice())
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
ImplTraitId::AsyncBlockTypeImplTrait(def, _) => {
|
||||
let krate = def.module(db).krate();
|
||||
if let Some(future_trait) = LangItem::Future.resolve_trait(db, krate) {
|
||||
// This is only used by type walking.
|
||||
// Parameters will be walked outside, and projection predicate is not used.
|
||||
// So just provide the Future trait.
|
||||
let impl_bound = TraitRef::new(
|
||||
interner,
|
||||
future_trait.into(),
|
||||
GenericArgs::new_from_iter(interner, []),
|
||||
)
|
||||
.upcast(interner);
|
||||
Some(vec![impl_bound])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TyKind::Param(param) => {
|
||||
// FIXME: We shouldn't use `param.id` here.
|
||||
let generic_params = db.generic_params(param.id.parent());
|
||||
let param_data = &generic_params[param.id.local_id()];
|
||||
match param_data {
|
||||
TypeOrConstParamData::TypeParamData(p) => match p.provenance {
|
||||
TypeParamProvenance::ArgumentImplTrait => {
|
||||
let predicates = db
|
||||
.generic_predicates_ns(param.id.parent())
|
||||
.instantiate_identity()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|wc| match wc.kind().skip_binder() {
|
||||
ClauseKind::Trait(tr) => tr.self_ty() == self,
|
||||
ClauseKind::Projection(pred) => pred.self_ty() == self,
|
||||
ClauseKind::TypeOutlives(pred) => pred.0 == self,
|
||||
_ => false,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Some(predicates)
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// FIXME: Get rid of this, it's not a good abstraction
|
||||
pub fn equals_ctor(self, other: Ty<'db>) -> bool {
|
||||
match (self.kind(), other.kind()) {
|
||||
(TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt.def_id() == adt2.def_id(),
|
||||
(TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_, _), TyKind::Array(_, _)) => {
|
||||
true
|
||||
}
|
||||
(TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2,
|
||||
(TyKind::Alias(_, alias, ..), TyKind::Alias(_, alias2)) => {
|
||||
alias.def_id == alias2.def_id
|
||||
}
|
||||
(TyKind::Foreign(ty_id, ..), TyKind::Foreign(ty_id2, ..)) => ty_id == ty_id2,
|
||||
(TyKind::Closure(id1, _), TyKind::Closure(id2, _)) => id1 == id2,
|
||||
(TyKind::Ref(.., mutability), TyKind::Ref(.., mutability2))
|
||||
| (TyKind::RawPtr(.., mutability), TyKind::RawPtr(.., mutability2)) => {
|
||||
mutability == mutability2
|
||||
}
|
||||
(TyKind::FnPtr(sig, hdr), TyKind::FnPtr(sig2, hdr2)) => sig == sig2 && hdr == hdr2,
|
||||
(TyKind::Tuple(tys), TyKind::Tuple(tys2)) => tys.len() == tys2.len(),
|
||||
(TyKind::Str, TyKind::Str)
|
||||
| (TyKind::Never, TyKind::Never)
|
||||
| (TyKind::Char, TyKind::Char)
|
||||
| (TyKind::Bool, TyKind::Bool) => true,
|
||||
(TyKind::Int(int), TyKind::Int(int2)) => int == int2,
|
||||
(TyKind::Float(float), TyKind::Float(float2)) => float == float2,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn references_non_lt_error<'db, T: TypeVisitableExt<DbInterner<'db>>>(t: &T) -> bool {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use intern::sym;
|
|||
use rustc_next_trait_solver::solve::{HasChanged, SolverDelegateEvalExt};
|
||||
use rustc_type_ir::{
|
||||
InferCtxtLike, TypingMode,
|
||||
inherent::{SliceLike, Span as _, Ty as _},
|
||||
inherent::{IntoKind, SliceLike, Span as _, Ty as _},
|
||||
solve::Certainty,
|
||||
};
|
||||
use span::Edition;
|
||||
|
|
@ -28,6 +28,7 @@ use crate::{
|
|||
DbInterner, GenericArg, ParamEnv, Predicate, SolverContext, Span,
|
||||
infer::{DbInternerInferExt, InferCtxt, traits::ObligationCause},
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk, convert_canonical_args_for_result},
|
||||
obligation_ctxt::ObligationCtxt,
|
||||
util::mini_canonicalize,
|
||||
},
|
||||
utils::UnevaluatedConstEvaluatorFolder,
|
||||
|
|
@ -43,7 +44,7 @@ pub struct TraitEnvironment<'db> {
|
|||
pub krate: Crate,
|
||||
pub block: Option<BlockId>,
|
||||
// FIXME make this a BTreeMap
|
||||
traits_from_clauses: Box<[(Ty, TraitId)]>,
|
||||
traits_from_clauses: Box<[(crate::next_solver::Ty<'db>, TraitId)]>,
|
||||
pub env: ParamEnv<'db>,
|
||||
}
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ impl<'db> TraitEnvironment<'db> {
|
|||
pub fn new(
|
||||
krate: Crate,
|
||||
block: Option<BlockId>,
|
||||
traits_from_clauses: Box<[(Ty, TraitId)]>,
|
||||
traits_from_clauses: Box<[(crate::next_solver::Ty<'db>, TraitId)]>,
|
||||
env: ParamEnv<'db>,
|
||||
) -> Arc<Self> {
|
||||
Arc::new(TraitEnvironment { krate, block, traits_from_clauses, env })
|
||||
|
|
@ -71,13 +72,28 @@ impl<'db> TraitEnvironment<'db> {
|
|||
Arc::make_mut(this).block = Some(block);
|
||||
}
|
||||
|
||||
pub fn traits_in_scope_from_clauses(&self, ty: Ty) -> impl Iterator<Item = TraitId> + '_ {
|
||||
pub fn traits_in_scope_from_clauses(
|
||||
&self,
|
||||
ty: crate::next_solver::Ty<'db>,
|
||||
) -> impl Iterator<Item = TraitId> + '_ {
|
||||
self.traits_from_clauses
|
||||
.iter()
|
||||
.filter_map(move |(self_ty, trait_id)| (*self_ty == ty).then_some(*trait_id))
|
||||
}
|
||||
}
|
||||
|
||||
/// This should be used in `hir` only.
|
||||
pub fn structurally_normalize_ty<'db>(
|
||||
infcx: &InferCtxt<'db>,
|
||||
ty: crate::next_solver::Ty<'db>,
|
||||
env: Arc<TraitEnvironment<'db>>,
|
||||
) -> crate::next_solver::Ty<'db> {
|
||||
let crate::next_solver::TyKind::Alias(..) = ty.kind() else { return ty };
|
||||
let mut ocx = ObligationCtxt::new(infcx);
|
||||
let ty = ocx.structurally_normalize_ty(&ObligationCause::dummy(), env.env, ty).unwrap_or(ty);
|
||||
ty.replace_infer_with_error(infcx.interner)
|
||||
}
|
||||
|
||||
pub(crate) fn normalize_projection_query<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
projection: ProjectionTy,
|
||||
|
|
@ -440,3 +456,43 @@ impl FnTrait {
|
|||
self.lang_item().resolve_trait(db, krate)
|
||||
}
|
||||
}
|
||||
|
||||
/// This should not be used in `hir-ty`, only in `hir`.
|
||||
pub fn implements_trait_unique<'db>(
|
||||
ty: crate::next_solver::Ty<'db>,
|
||||
db: &'db dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'db>>,
|
||||
trait_: TraitId,
|
||||
) -> bool {
|
||||
implements_trait_unique_impl(db, env, trait_, &mut |infcx| {
|
||||
infcx.fill_rest_fresh_args(trait_.into(), [ty.into()])
|
||||
})
|
||||
}
|
||||
|
||||
/// This should not be used in `hir-ty`, only in `hir`.
|
||||
pub fn implements_trait_unique_with_args<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'db>>,
|
||||
trait_: TraitId,
|
||||
args: crate::next_solver::GenericArgs<'db>,
|
||||
) -> bool {
|
||||
implements_trait_unique_impl(db, env, trait_, &mut |_| args)
|
||||
}
|
||||
|
||||
fn implements_trait_unique_impl<'db>(
|
||||
db: &'db dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment<'db>>,
|
||||
trait_: TraitId,
|
||||
create_args: &mut dyn FnMut(&InferCtxt<'db>) -> crate::next_solver::GenericArgs<'db>,
|
||||
) -> bool {
|
||||
let interner = DbInterner::new_with(db, Some(env.krate), env.block);
|
||||
// FIXME(next-solver): I believe this should be `PostAnalysis`.
|
||||
let infcx = interner.infer_ctxt().build(TypingMode::non_body_analysis());
|
||||
|
||||
let args = create_args(&infcx);
|
||||
let trait_ref = rustc_type_ir::TraitRef::new_from_args(interner, trait_.into(), args);
|
||||
let goal = crate::next_solver::Goal::new(interner, env.env, trait_ref);
|
||||
|
||||
let result = crate::traits::next_trait_solve_in_ctxt(&infcx, goal);
|
||||
matches!(result, Ok((_, Certainty::Yes)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,7 @@ use hir_expand::{
|
|||
mod_path::{ModPath, PathKind},
|
||||
name::Name,
|
||||
};
|
||||
use hir_ty::{
|
||||
db::HirDatabase,
|
||||
method_resolution,
|
||||
next_solver::{DbInterner, mapping::ChalkToNextSolver},
|
||||
};
|
||||
use hir_ty::{db::HirDatabase, method_resolution};
|
||||
|
||||
use crate::{
|
||||
Adt, AsAssocItem, AssocItem, BuiltinType, Const, ConstParam, DocLinkDef, Enum, ExternCrateDecl,
|
||||
|
|
@ -261,7 +257,7 @@ fn resolve_impl_trait_item<'db>(
|
|||
name: &Name,
|
||||
ns: Option<Namespace>,
|
||||
) -> Option<DocLinkDef> {
|
||||
let canonical = ty.canonical();
|
||||
let canonical = ty.canonical(db);
|
||||
let krate = ty.krate(db);
|
||||
let environment = resolver
|
||||
.generic_def()
|
||||
|
|
@ -275,11 +271,7 @@ fn resolve_impl_trait_item<'db>(
|
|||
//
|
||||
// FIXME: resolve type aliases (which are not yielded by iterate_path_candidates)
|
||||
_ = method_resolution::iterate_path_candidates(
|
||||
&canonical.to_nextsolver(DbInterner::new_with(
|
||||
db,
|
||||
Some(environment.krate),
|
||||
environment.block,
|
||||
)),
|
||||
&canonical,
|
||||
db,
|
||||
environment,
|
||||
&traits_in_scope,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ use hir_ty::{
|
|||
PathLoweringDiagnostic, TyLoweringDiagnostic, TyLoweringDiagnosticKind,
|
||||
db::HirDatabase,
|
||||
diagnostics::{BodyValidationDiagnostic, UnsafetyReason},
|
||||
next_solver::{DbInterner, mapping::NextSolverToChalk},
|
||||
};
|
||||
use syntax::{
|
||||
AstNode, AstPtr, SyntaxError, SyntaxNodePtr, TextRange,
|
||||
|
|
@ -641,7 +640,6 @@ impl<'db> AnyDiagnostic<'db> {
|
|||
ExprOrPatId::ExprId(expr) => expr_syntax(expr),
|
||||
ExprOrPatId::PatId(pat) => pat_syntax(pat),
|
||||
};
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
Some(match d {
|
||||
&InferenceDiagnostic::NoSuchField { field: expr, private, variant } => {
|
||||
let expr_or_pat = match expr {
|
||||
|
|
@ -668,11 +666,7 @@ impl<'db> AnyDiagnostic<'db> {
|
|||
}
|
||||
InferenceDiagnostic::ExpectedFunction { call_expr, found } => {
|
||||
let call_expr = expr_syntax(*call_expr)?;
|
||||
ExpectedFunction {
|
||||
call: call_expr,
|
||||
found: Type::new(db, def, found.to_chalk(interner)),
|
||||
}
|
||||
.into()
|
||||
ExpectedFunction { call: call_expr, found: Type::new(db, def, *found) }.into()
|
||||
}
|
||||
InferenceDiagnostic::UnresolvedField {
|
||||
expr,
|
||||
|
|
@ -684,7 +678,7 @@ impl<'db> AnyDiagnostic<'db> {
|
|||
UnresolvedField {
|
||||
expr,
|
||||
name: name.clone(),
|
||||
receiver: Type::new(db, def, receiver.to_chalk(interner)),
|
||||
receiver: Type::new(db, def, *receiver),
|
||||
method_with_same_name_exists: *method_with_same_name_exists,
|
||||
}
|
||||
.into()
|
||||
|
|
@ -700,9 +694,8 @@ impl<'db> AnyDiagnostic<'db> {
|
|||
UnresolvedMethodCall {
|
||||
expr,
|
||||
name: name.clone(),
|
||||
receiver: Type::new(db, def, receiver.to_chalk(interner)),
|
||||
field_with_same_name: (*field_with_same_name)
|
||||
.map(|ty| Type::new(db, def, ty.to_chalk(interner))),
|
||||
receiver: Type::new(db, def, *receiver),
|
||||
field_with_same_name: (*field_with_same_name).map(|ty| Type::new(db, def, ty)),
|
||||
assoc_func_with_same_name: assoc_func_with_same_name.map(Into::into),
|
||||
}
|
||||
.into()
|
||||
|
|
@ -729,7 +722,7 @@ impl<'db> AnyDiagnostic<'db> {
|
|||
}
|
||||
InferenceDiagnostic::TypedHole { expr, expected } => {
|
||||
let expr = expr_syntax(*expr)?;
|
||||
TypedHole { expr, expected: Type::new(db, def, expected.to_chalk(interner)) }.into()
|
||||
TypedHole { expr, expected: Type::new(db, def, *expected) }.into()
|
||||
}
|
||||
&InferenceDiagnostic::MismatchedTupleStructPatArgCount { pat, expected, found } => {
|
||||
let expr_or_pat = match pat {
|
||||
|
|
@ -746,13 +739,12 @@ impl<'db> AnyDiagnostic<'db> {
|
|||
}
|
||||
InferenceDiagnostic::CastToUnsized { expr, cast_ty } => {
|
||||
let expr = expr_syntax(*expr)?;
|
||||
CastToUnsized { expr, cast_ty: Type::new(db, def, cast_ty.to_chalk(interner)) }
|
||||
.into()
|
||||
CastToUnsized { expr, cast_ty: Type::new(db, def, *cast_ty) }.into()
|
||||
}
|
||||
InferenceDiagnostic::InvalidCast { expr, error, expr_ty, cast_ty } => {
|
||||
let expr = expr_syntax(*expr)?;
|
||||
let expr_ty = Type::new(db, def, expr_ty.to_chalk(interner));
|
||||
let cast_ty = Type::new(db, def, cast_ty.to_chalk(interner));
|
||||
let expr_ty = Type::new(db, def, *expr_ty);
|
||||
let cast_ty = Type::new(db, def, *cast_ty);
|
||||
InvalidCast { expr, error: *error, expr_ty, cast_ty }.into()
|
||||
}
|
||||
InferenceDiagnostic::TyDiagnostic { source, diag } => {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use hir_def::{
|
|||
type_ref::{TypeBound, TypeRef, TypeRefId},
|
||||
};
|
||||
use hir_ty::{
|
||||
AliasEq, AliasTy, Interner, ProjectionTyExt, TraitRefExt, TyKind, WhereClause,
|
||||
AliasEq, AliasTy, Interner, ProjectionTyExt, TraitRefExt, TyBuilder, TyKind, WhereClause,
|
||||
db::HirDatabase,
|
||||
display::{
|
||||
HirDisplay, HirDisplayError, HirDisplayWithExpressionStore, HirFormatter, SizedByDefault,
|
||||
|
|
@ -23,8 +23,8 @@ use itertools::Itertools;
|
|||
use crate::{
|
||||
Adt, AsAssocItem, AssocItem, AssocItemContainer, Const, ConstParam, Crate, Enum,
|
||||
ExternCrateDecl, Field, Function, GenericParam, HasCrate, HasVisibility, Impl, LifetimeParam,
|
||||
Macro, Module, SelfParam, Static, Struct, StructKind, Trait, TraitRef, TupleField, TyBuilder,
|
||||
Type, TypeAlias, TypeNs, TypeOrConstParam, TypeParam, Union, Variant,
|
||||
Macro, Module, SelfParam, Static, Struct, StructKind, Trait, TraitRef, TupleField, Type,
|
||||
TypeAlias, TypeNs, TypeOrConstParam, TypeParam, Union, Variant,
|
||||
};
|
||||
|
||||
impl HirDisplay for Function {
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ impl HasSource for Param<'_> {
|
|||
.map(|value| InFile { file_id, value })
|
||||
}
|
||||
Callee::Closure(closure, _) => {
|
||||
let InternedClosure(owner, expr_id) = db.lookup_intern_closure(closure.into());
|
||||
let InternedClosure(owner, expr_id) = db.lookup_intern_closure(closure);
|
||||
let (_, source_map) = db.body_with_source_map(owner);
|
||||
let ast @ InFile { file_id, value } = source_map.expr_syntax(expr_id).ok()?;
|
||||
let root = db.parse_or_expand(file_id);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -28,9 +28,10 @@ use hir_expand::{
|
|||
mod_path::{ModPath, PathKind},
|
||||
name::AsName,
|
||||
};
|
||||
use hir_ty::diagnostics::{unsafe_operations, unsafe_operations_for_body};
|
||||
use hir_ty::next_solver::DbInterner;
|
||||
use hir_ty::next_solver::mapping::{ChalkToNextSolver, NextSolverToChalk};
|
||||
use hir_ty::{
|
||||
diagnostics::{unsafe_operations, unsafe_operations_for_body},
|
||||
next_solver::DbInterner,
|
||||
};
|
||||
use intern::{Interned, Symbol, sym};
|
||||
use itertools::Itertools;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
|
@ -1563,16 +1564,11 @@ impl<'db> SemanticsImpl<'db> {
|
|||
|
||||
let (mut source_ty, _) = analyzer.type_of_expr(self.db, expr)?;
|
||||
|
||||
let interner = DbInterner::new_with(self.db, None, None);
|
||||
|
||||
analyzer.expr_adjustments(expr).map(|it| {
|
||||
it.iter()
|
||||
.map(|adjust| {
|
||||
let target = Type::new_with_resolver(
|
||||
self.db,
|
||||
&analyzer.resolver,
|
||||
adjust.target.to_chalk(interner),
|
||||
);
|
||||
let target =
|
||||
Type::new_with_resolver(self.db, &analyzer.resolver, adjust.target);
|
||||
let kind = match adjust.kind {
|
||||
hir_ty::Adjust::NeverToAny => Adjust::NeverToAny,
|
||||
hir_ty::Adjust::Deref(Some(hir_ty::OverloadedDeref(m))) => {
|
||||
|
|
@ -1666,7 +1662,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||
trait_.id.into(),
|
||||
|_, _, id, _| {
|
||||
assert!(matches!(id, hir_def::GenericParamId::TypeParamId(_)), "expected a type");
|
||||
subst.next().expect("too few subst").ty.to_nextsolver(interner).into()
|
||||
subst.next().expect("too few subst").ty.into()
|
||||
},
|
||||
);
|
||||
assert!(subst.next().is_none(), "too many subst");
|
||||
|
|
|
|||
|
|
@ -7,13 +7,6 @@
|
|||
//! purely for "IDE needs".
|
||||
use std::iter::{self, once};
|
||||
|
||||
use crate::{
|
||||
Adt, AssocItem, BindingMode, BuiltinAttr, BuiltinType, Callable, Const, DeriveHelper, Field,
|
||||
Function, GenericSubstitution, Local, Macro, ModuleDef, Static, Struct, ToolModule, Trait,
|
||||
TupleField, Type, TypeAlias, Variant,
|
||||
db::HirDatabase,
|
||||
semantics::{PathResolution, PathResolutionPerNs},
|
||||
};
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
AdtId, AssocItemId, CallableDefId, ConstId, DefWithBodyId, FieldId, FunctionId, GenericDefId,
|
||||
|
|
@ -36,23 +29,24 @@ use hir_expand::{
|
|||
name::{AsName, Name},
|
||||
};
|
||||
use hir_ty::{
|
||||
Adjustment, AliasTy, InferenceResult, Interner, LifetimeElisionKind, ProjectionTy,
|
||||
Substitution, ToChalk, TraitEnvironment, Ty, TyKind, TyLoweringContext,
|
||||
Adjustment, InferenceResult, LifetimeElisionKind, TraitEnvironment, TyLoweringContext,
|
||||
diagnostics::{
|
||||
InsideUnsafeBlock, record_literal_missing_fields, record_pattern_missing_fields,
|
||||
unsafe_operations,
|
||||
},
|
||||
from_assoc_type_id,
|
||||
lang_items::lang_items_for_bin_op,
|
||||
method_resolution,
|
||||
next_solver::{
|
||||
DbInterner, GenericArgs, TypingMode,
|
||||
infer::DbInternerInferExt,
|
||||
mapping::{ChalkToNextSolver, NextSolverToChalk},
|
||||
DbInterner, ErrorGuaranteed, GenericArgs, Ty, TyKind, TypingMode, infer::DbInternerInferExt,
|
||||
},
|
||||
traits::structurally_normalize_ty,
|
||||
};
|
||||
use intern::sym;
|
||||
use itertools::Itertools;
|
||||
use rustc_type_ir::{
|
||||
AliasTyKind,
|
||||
inherent::{AdtDef, IntoKind, Ty as _},
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use stdx::never;
|
||||
use syntax::{
|
||||
|
|
@ -61,6 +55,14 @@ use syntax::{
|
|||
};
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::{
|
||||
Adt, AssocItem, BindingMode, BuiltinAttr, BuiltinType, Callable, Const, DeriveHelper, Field,
|
||||
Function, GenericSubstitution, Local, Macro, ModuleDef, Static, Struct, ToolModule, Trait,
|
||||
TupleField, Type, TypeAlias, Variant,
|
||||
db::HirDatabase,
|
||||
semantics::{PathResolution, PathResolutionPerNs},
|
||||
};
|
||||
|
||||
/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
|
||||
/// original source files. It should not be used inside the HIR itself.
|
||||
#[derive(Debug)]
|
||||
|
|
@ -292,9 +294,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
.and_then(|expr_id| infer.expr_adjustment(expr_id))
|
||||
.and_then(|adjusts| adjusts.last().map(|adjust| adjust.target));
|
||||
let ty = infer[expr_id];
|
||||
let mk_ty = |ty: hir_ty::next_solver::Ty<'_>| {
|
||||
Type::new_with_resolver(db, &self.resolver, ty.to_chalk(DbInterner::conjure()))
|
||||
};
|
||||
let mk_ty = |ty: Ty<'db>| Type::new_with_resolver(db, &self.resolver, ty);
|
||||
Some((mk_ty(ty), coerced.map(mk_ty)))
|
||||
}
|
||||
|
||||
|
|
@ -316,9 +316,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
};
|
||||
|
||||
let ty = infer[expr_or_pat_id];
|
||||
let mk_ty = |ty: hir_ty::next_solver::Ty<'db>| {
|
||||
Type::new_with_resolver(db, &self.resolver, ty.to_chalk(DbInterner::conjure()))
|
||||
};
|
||||
let mk_ty = |ty: Ty<'db>| Type::new_with_resolver(db, &self.resolver, ty);
|
||||
Some((mk_ty(ty), coerced.map(mk_ty)))
|
||||
}
|
||||
|
||||
|
|
@ -330,9 +328,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
let binding_id = self.binding_id_of_pat(pat)?;
|
||||
let infer = self.infer()?;
|
||||
let ty = infer[binding_id];
|
||||
let mk_ty = |ty: hir_ty::next_solver::Ty<'db>| {
|
||||
Type::new_with_resolver(db, &self.resolver, ty.to_chalk(DbInterner::conjure()))
|
||||
};
|
||||
let mk_ty = |ty: Ty<'db>| Type::new_with_resolver(db, &self.resolver, ty);
|
||||
Some(mk_ty(ty))
|
||||
}
|
||||
|
||||
|
|
@ -343,7 +339,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
) -> Option<Type<'db>> {
|
||||
let binding = self.body()?.self_param?;
|
||||
let ty = self.infer()?[binding];
|
||||
Some(Type::new_with_resolver(db, &self.resolver, ty.to_chalk(DbInterner::conjure())))
|
||||
Some(Type::new_with_resolver(db, &self.resolver, ty))
|
||||
}
|
||||
|
||||
pub(crate) fn binding_mode_of_pat(
|
||||
|
|
@ -374,9 +370,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
infer
|
||||
.pat_adjustment(pat_id.as_pat()?)?
|
||||
.iter()
|
||||
.map(|ty| {
|
||||
Type::new_with_resolver(db, &self.resolver, ty.to_chalk(DbInterner::conjure()))
|
||||
})
|
||||
.map(|ty| Type::new_with_resolver(db, &self.resolver, *ty))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
|
@ -390,7 +384,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
let (func, args) = self.infer()?.method_resolution(expr_id)?;
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let ty = db.value_ty(func.into())?.instantiate(interner, args);
|
||||
let ty = Type::new_with_resolver(db, &self.resolver, ty.to_chalk(interner));
|
||||
let ty = Type::new_with_resolver(db, &self.resolver, ty);
|
||||
let mut res = ty.as_callable(db)?;
|
||||
res.is_bound_method = true;
|
||||
Some(res)
|
||||
|
|
@ -414,18 +408,13 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
) -> Option<(Either<Function, Field>, Option<GenericSubstitution<'db>>)> {
|
||||
let expr_id = self.expr_id(call.clone().into())?.as_expr()?;
|
||||
let inference_result = self.infer()?;
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
match inference_result.method_resolution(expr_id) {
|
||||
Some((f_in_trait, substs)) => {
|
||||
let (fn_, subst) =
|
||||
self.resolve_impl_method_or_trait_def_with_subst(db, f_in_trait, substs);
|
||||
Some((
|
||||
Either::Left(fn_.into()),
|
||||
Some(GenericSubstitution::new(
|
||||
fn_.into(),
|
||||
subst.to_chalk(interner),
|
||||
self.trait_environment(db),
|
||||
)),
|
||||
Some(GenericSubstitution::new(fn_.into(), subst, self.trait_environment(db))),
|
||||
))
|
||||
}
|
||||
None => {
|
||||
|
|
@ -465,11 +454,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
let body = self.store()?;
|
||||
if let Expr::Field { expr: object_expr, name: _ } = body[field_expr] {
|
||||
let (adt, subst) = infer.type_of_expr_with_adjust(object_expr)?.as_adt()?;
|
||||
return Some(GenericSubstitution::new(
|
||||
adt.into(),
|
||||
subst.to_chalk(DbInterner::conjure()),
|
||||
self.trait_environment(db),
|
||||
));
|
||||
return Some(GenericSubstitution::new(adt.into(), subst, self.trait_environment(db)));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
@ -483,7 +468,6 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
let (def, ..) = self.body_()?;
|
||||
let expr_id = self.expr_id(field.clone().into())?.as_expr()?;
|
||||
let inference_result = self.infer()?;
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
match inference_result.field_resolution(expr_id) {
|
||||
Some(field) => match field {
|
||||
Either::Left(field) => Some((
|
||||
|
|
@ -503,11 +487,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
let (f, subst) = self.resolve_impl_method_or_trait_def_with_subst(db, f, substs);
|
||||
(
|
||||
Either::Right(f.into()),
|
||||
Some(GenericSubstitution::new(
|
||||
f.into(),
|
||||
subst.to_chalk(interner),
|
||||
self.trait_environment(db),
|
||||
)),
|
||||
Some(GenericSubstitution::new(f.into(), subst, self.trait_environment(db))),
|
||||
)
|
||||
}),
|
||||
}
|
||||
|
|
@ -557,7 +537,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
db: &'db dyn HirDatabase,
|
||||
await_expr: &ast::AwaitExpr,
|
||||
) -> Option<FunctionId> {
|
||||
let mut ty = self.ty_of_expr(await_expr.expr()?)?.clone();
|
||||
let mut ty = self.ty_of_expr(await_expr.expr()?)?;
|
||||
|
||||
let into_future_trait = self
|
||||
.resolver
|
||||
|
|
@ -565,7 +545,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
.map(Trait::from);
|
||||
|
||||
if let Some(into_future_trait) = into_future_trait {
|
||||
let type_ = Type::new_with_resolver(db, &self.resolver, ty.clone());
|
||||
let type_ = Type::new_with_resolver(db, &self.resolver, ty);
|
||||
if type_.impls_trait(db, into_future_trait, &[]) {
|
||||
let items = into_future_trait.items(db);
|
||||
let into_future_type = items.into_iter().find_map(|item| match item {
|
||||
|
|
@ -585,7 +565,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
// HACK: subst for `poll()` coincides with that for `Future` because `poll()` itself
|
||||
// doesn't have any generic parameters, so we skip building another subst for `poll()`.
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let substs = GenericArgs::new_from_iter(interner, [ty.to_nextsolver(interner).into()]);
|
||||
let substs = GenericArgs::new_from_iter(interner, [ty.into()]);
|
||||
Some(self.resolve_impl_method_or_trait_def(db, poll_fn, substs))
|
||||
}
|
||||
|
||||
|
|
@ -627,7 +607,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
let interner = DbInterner::new_with(db, None, None);
|
||||
// HACK: subst for all methods coincides with that for their trait because the methods
|
||||
// don't have any generic parameters, so we skip building another subst for the methods.
|
||||
let substs = GenericArgs::new_from_iter(interner, [ty.to_nextsolver(interner).into()]);
|
||||
let substs = GenericArgs::new_from_iter(interner, [ty.into()]);
|
||||
|
||||
Some(self.resolve_impl_method_or_trait_def(db, op_fn, substs))
|
||||
}
|
||||
|
|
@ -658,10 +638,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
// HACK: subst for all methods coincides with that for their trait because the methods
|
||||
// don't have any generic parameters, so we skip building another subst for the methods.
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let substs = GenericArgs::new_from_iter(
|
||||
interner,
|
||||
[base_ty.to_nextsolver(interner).into(), index_ty.to_nextsolver(interner).into()],
|
||||
);
|
||||
let substs = GenericArgs::new_from_iter(interner, [base_ty.into(), index_ty.into()]);
|
||||
Some(self.resolve_impl_method_or_trait_def(db, op_fn, substs))
|
||||
}
|
||||
|
||||
|
|
@ -679,10 +656,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
// HACK: subst for `index()` coincides with that for `Index` because `index()` itself
|
||||
// doesn't have any generic parameters, so we skip building another subst for `index()`.
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let substs = GenericArgs::new_from_iter(
|
||||
interner,
|
||||
[lhs.to_nextsolver(interner).into(), rhs.to_nextsolver(interner).into()],
|
||||
);
|
||||
let substs = GenericArgs::new_from_iter(interner, [lhs.into(), rhs.into()]);
|
||||
|
||||
Some(self.resolve_impl_method_or_trait_def(db, op_fn, substs))
|
||||
}
|
||||
|
|
@ -698,7 +672,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
// HACK: subst for `branch()` coincides with that for `Try` because `branch()` itself
|
||||
// doesn't have any generic parameters, so we skip building another subst for `branch()`.
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let substs = GenericArgs::new_from_iter(interner, [ty.to_nextsolver(interner).into()]);
|
||||
let substs = GenericArgs::new_from_iter(interner, [ty.into()]);
|
||||
|
||||
Some(self.resolve_impl_method_or_trait_def(db, op_fn, substs))
|
||||
}
|
||||
|
|
@ -735,12 +709,11 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
}
|
||||
};
|
||||
let (adt, subst) = self.infer()?.type_of_expr_or_pat(expr_id)?.as_adt()?;
|
||||
let subst = subst.to_chalk(interner);
|
||||
let variant = self.infer()?.variant_resolution_for_expr_or_pat(expr_id)?;
|
||||
let variant_data = variant.fields(db);
|
||||
let field = FieldId { parent: variant, local_id: variant_data.field(&local_name)? };
|
||||
let field_ty =
|
||||
db.field_types(variant).get(field.local_id)?.clone().substitute(Interner, &subst);
|
||||
(*db.field_types_ns(variant).get(field.local_id)?).instantiate(interner, subst);
|
||||
Some((
|
||||
field.into(),
|
||||
local,
|
||||
|
|
@ -762,9 +735,8 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
let variant_data = variant.fields(db);
|
||||
let field = FieldId { parent: variant, local_id: variant_data.field(&field_name)? };
|
||||
let (adt, subst) = self.infer()?[pat_id.as_pat()?].as_adt()?;
|
||||
let subst = subst.to_chalk(interner);
|
||||
let field_ty =
|
||||
db.field_types(variant).get(field.local_id)?.clone().substitute(Interner, &subst);
|
||||
(*db.field_types_ns(variant).get(field.local_id)?).instantiate(interner, subst);
|
||||
Some((
|
||||
field.into(),
|
||||
Type::new_with_resolver(db, &self.resolver, field_ty),
|
||||
|
|
@ -817,43 +789,40 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
let container = self.type_of_type(db, &container)?;
|
||||
|
||||
let trait_env = container.env;
|
||||
|
||||
let interner = DbInterner::new_with(db, Some(trait_env.krate), trait_env.block);
|
||||
let infcx = interner.infer_ctxt().build(TypingMode::PostAnalysis);
|
||||
|
||||
let mut container = Either::Right(container.ty);
|
||||
for field_name in offset_of_expr.fields() {
|
||||
if let Some(
|
||||
TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty_id, substitution }))
|
||||
| TyKind::AssociatedType(associated_ty_id, substitution),
|
||||
) = container.as_ref().right().map(|it| it.kind(Interner))
|
||||
{
|
||||
let projection = ProjectionTy {
|
||||
associated_ty_id: *associated_ty_id,
|
||||
substitution: substitution.clone(),
|
||||
};
|
||||
container = Either::Right(db.normalize_projection(projection, trait_env.clone()));
|
||||
if let Either::Right(container) = &mut container {
|
||||
*container = structurally_normalize_ty(&infcx, *container, trait_env.clone());
|
||||
}
|
||||
let handle_variants = |variant: VariantId, subst: &Substitution, container: &mut _| {
|
||||
let fields = variant.fields(db);
|
||||
let field = fields.field(&field_name.as_name())?;
|
||||
let field_types = db.field_types(variant);
|
||||
*container = Either::Right(field_types[field].clone().substitute(Interner, subst));
|
||||
let generic_def = match variant {
|
||||
VariantId::EnumVariantId(it) => it.loc(db).parent.into(),
|
||||
VariantId::StructId(it) => it.into(),
|
||||
VariantId::UnionId(it) => it.into(),
|
||||
let handle_variants =
|
||||
|variant: VariantId, subst: GenericArgs<'db>, container: &mut _| {
|
||||
let fields = variant.fields(db);
|
||||
let field = fields.field(&field_name.as_name())?;
|
||||
let field_types = db.field_types_ns(variant);
|
||||
*container = Either::Right(field_types[field].instantiate(interner, subst));
|
||||
let generic_def = match variant {
|
||||
VariantId::EnumVariantId(it) => it.loc(db).parent.into(),
|
||||
VariantId::StructId(it) => it.into(),
|
||||
VariantId::UnionId(it) => it.into(),
|
||||
};
|
||||
Some((
|
||||
Either::Right(Field { parent: variant.into(), id: field }),
|
||||
generic_def,
|
||||
subst,
|
||||
))
|
||||
};
|
||||
Some((
|
||||
Either::Right(Field { parent: variant.into(), id: field }),
|
||||
generic_def,
|
||||
subst.clone(),
|
||||
))
|
||||
};
|
||||
let temp_ty = TyKind::Error.intern(Interner);
|
||||
let temp_ty = Ty::new_error(interner, ErrorGuaranteed);
|
||||
let (field_def, generic_def, subst) =
|
||||
match std::mem::replace(&mut container, Either::Right(temp_ty.clone())) {
|
||||
match std::mem::replace(&mut container, Either::Right(temp_ty)) {
|
||||
Either::Left((variant_id, subst)) => {
|
||||
handle_variants(VariantId::from(variant_id), &subst, &mut container)?
|
||||
handle_variants(VariantId::from(variant_id), subst, &mut container)?
|
||||
}
|
||||
Either::Right(container_ty) => match container_ty.kind(Interner) {
|
||||
TyKind::Adt(adt_id, subst) => match adt_id.0 {
|
||||
Either::Right(container_ty) => match container_ty.kind() {
|
||||
TyKind::Adt(adt_def, subst) => match adt_def.def_id().0 {
|
||||
AdtId::StructId(id) => {
|
||||
handle_variants(id.into(), subst, &mut container)?
|
||||
}
|
||||
|
|
@ -863,8 +832,8 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
AdtId::EnumId(id) => {
|
||||
let variants = id.enum_variants(db);
|
||||
let variant = variants.variant(&field_name.as_name())?;
|
||||
container = Either::Left((variant, subst.clone()));
|
||||
(Either::Left(Variant { id: variant }), id.into(), subst.clone())
|
||||
container = Either::Left((variant, subst));
|
||||
(Either::Left(Variant { id: variant }), id.into(), subst)
|
||||
}
|
||||
},
|
||||
_ => return None,
|
||||
|
|
@ -884,7 +853,6 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
db: &'db dyn HirDatabase,
|
||||
path: &ast::Path,
|
||||
) -> Option<(PathResolution, Option<GenericSubstitution<'db>>)> {
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let parent = path.syntax().parent();
|
||||
let parent = || parent.clone();
|
||||
|
||||
|
|
@ -900,31 +868,27 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
None => {
|
||||
let subst = GenericSubstitution::new(
|
||||
f_in_trait.into(),
|
||||
subs.to_chalk(interner),
|
||||
subs,
|
||||
self.trait_environment(db),
|
||||
);
|
||||
(assoc, subst)
|
||||
}
|
||||
Some(func_ty) => {
|
||||
if let TyKind::FnDef(_fn_def, subs) =
|
||||
func_ty.to_chalk(interner).kind(Interner)
|
||||
{
|
||||
if let TyKind::FnDef(_fn_def, subs) = func_ty.kind() {
|
||||
let (fn_, subst) = self
|
||||
.resolve_impl_method_or_trait_def_with_subst(
|
||||
db,
|
||||
f_in_trait,
|
||||
subs.to_nextsolver(interner),
|
||||
db, f_in_trait, subs,
|
||||
);
|
||||
let subst = GenericSubstitution::new(
|
||||
fn_.into(),
|
||||
subst.to_chalk(interner),
|
||||
subst,
|
||||
self.trait_environment(db),
|
||||
);
|
||||
(fn_.into(), subst)
|
||||
} else {
|
||||
let subst = GenericSubstitution::new(
|
||||
f_in_trait.into(),
|
||||
subs.to_chalk(interner),
|
||||
subs,
|
||||
self.trait_environment(db),
|
||||
);
|
||||
(assoc, subst)
|
||||
|
|
@ -937,7 +901,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
self.resolve_impl_const_or_trait_def_with_subst(db, const_id, subs);
|
||||
let subst = GenericSubstitution::new(
|
||||
konst.into(),
|
||||
subst.to_chalk(interner),
|
||||
subst,
|
||||
self.trait_environment(db),
|
||||
);
|
||||
(konst.into(), subst)
|
||||
|
|
@ -946,7 +910,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
assoc,
|
||||
GenericSubstitution::new(
|
||||
type_alias.into(),
|
||||
subs.to_chalk(interner),
|
||||
subs,
|
||||
self.trait_environment(db),
|
||||
),
|
||||
),
|
||||
|
|
@ -970,7 +934,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
self.resolve_impl_const_or_trait_def_with_subst(db, const_id, subs);
|
||||
let subst = GenericSubstitution::new(
|
||||
konst.into(),
|
||||
subst.to_chalk(interner),
|
||||
subst,
|
||||
self.trait_environment(db),
|
||||
);
|
||||
(konst.into(), subst)
|
||||
|
|
@ -979,7 +943,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
assoc,
|
||||
GenericSubstitution::new(
|
||||
assoc.into(),
|
||||
subs.to_chalk(interner),
|
||||
subs,
|
||||
self.trait_environment(db),
|
||||
),
|
||||
),
|
||||
|
|
@ -1177,36 +1141,38 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
let parent = parent()?;
|
||||
let ty = if let Some(expr) = ast::Expr::cast(parent.clone()) {
|
||||
let expr_id = self.expr_id(expr)?;
|
||||
self.infer()?.type_of_expr_or_pat(expr_id)?.to_chalk(interner)
|
||||
self.infer()?.type_of_expr_or_pat(expr_id)?
|
||||
} else if let Some(pat) = ast::Pat::cast(parent) {
|
||||
let pat_id = self.pat_id(&pat)?;
|
||||
self.infer()?[pat_id].to_chalk(interner)
|
||||
self.infer()?[pat_id]
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let env = self.trait_environment(db);
|
||||
let (subst, expected_resolution) = match ty.kind(Interner) {
|
||||
TyKind::Adt(adt_id, subst) => (
|
||||
GenericSubstitution::new(adt_id.0.into(), subst.clone(), env),
|
||||
PathResolution::Def(ModuleDef::Adt(adt_id.0.into())),
|
||||
),
|
||||
TyKind::AssociatedType(assoc_id, subst) => {
|
||||
let assoc_id = from_assoc_type_id(*assoc_id);
|
||||
let (subst, expected_resolution) = match ty.kind() {
|
||||
TyKind::Adt(adt_def, subst) => {
|
||||
let adt_id = adt_def.def_id().0;
|
||||
(
|
||||
GenericSubstitution::new(assoc_id.into(), subst.clone(), env),
|
||||
GenericSubstitution::new(adt_id.into(), subst, env),
|
||||
PathResolution::Def(ModuleDef::Adt(adt_id.into())),
|
||||
)
|
||||
}
|
||||
TyKind::Alias(AliasTyKind::Projection, alias) => {
|
||||
let assoc_id = alias.def_id.expect_type_alias();
|
||||
(
|
||||
GenericSubstitution::new(assoc_id.into(), alias.args, env),
|
||||
PathResolution::Def(ModuleDef::TypeAlias(assoc_id.into())),
|
||||
)
|
||||
}
|
||||
TyKind::FnDef(fn_id, subst) => {
|
||||
let fn_id = ToChalk::from_chalk(db, *fn_id);
|
||||
let generic_def_id = match fn_id {
|
||||
let generic_def_id = match fn_id.0 {
|
||||
CallableDefId::StructId(id) => id.into(),
|
||||
CallableDefId::FunctionId(id) => id.into(),
|
||||
CallableDefId::EnumVariantId(_) => return None,
|
||||
};
|
||||
(
|
||||
GenericSubstitution::new(generic_def_id, subst.clone(), env),
|
||||
PathResolution::Def(ModuleDefId::from(fn_id).into()),
|
||||
GenericSubstitution::new(generic_def_id, subst, env),
|
||||
PathResolution::Def(ModuleDefId::from(fn_id.0).into()),
|
||||
)
|
||||
}
|
||||
_ => return None,
|
||||
|
|
@ -1260,8 +1226,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
record_pattern_missing_fields(db, infer, pat_id, &body[pat_id])?
|
||||
}
|
||||
};
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let res = self.missing_fields(db, &substs.to_chalk(interner), variant, missing_fields);
|
||||
let res = self.missing_fields(db, substs, variant, missing_fields);
|
||||
Some(res)
|
||||
}
|
||||
|
||||
|
|
@ -1278,25 +1243,25 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
|
||||
let (variant, missing_fields, _exhaustive) =
|
||||
record_pattern_missing_fields(db, infer, pat_id, &body[pat_id])?;
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let res = self.missing_fields(db, &substs.to_chalk(interner), variant, missing_fields);
|
||||
let res = self.missing_fields(db, substs, variant, missing_fields);
|
||||
Some(res)
|
||||
}
|
||||
|
||||
fn missing_fields(
|
||||
&self,
|
||||
db: &'db dyn HirDatabase,
|
||||
substs: &Substitution,
|
||||
substs: GenericArgs<'db>,
|
||||
variant: VariantId,
|
||||
missing_fields: Vec<LocalFieldId>,
|
||||
) -> Vec<(Field, Type<'db>)> {
|
||||
let field_types = db.field_types(variant);
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let field_types = db.field_types_ns(variant);
|
||||
|
||||
missing_fields
|
||||
.into_iter()
|
||||
.map(|local_id| {
|
||||
let field = FieldId { parent: variant, local_id };
|
||||
let ty = field_types[local_id].clone().substitute(Interner, substs);
|
||||
let ty = field_types[local_id].instantiate(interner, substs);
|
||||
(field.into(), Type::new_with_resolver_inner(db, &self.resolver, ty))
|
||||
})
|
||||
.collect()
|
||||
|
|
@ -1455,10 +1420,8 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
Some((trait_id, fn_id))
|
||||
}
|
||||
|
||||
fn ty_of_expr(&self, expr: ast::Expr) -> Option<Ty> {
|
||||
self.infer()?
|
||||
.type_of_expr_or_pat(self.expr_id(expr)?)
|
||||
.map(|ty| ty.to_chalk(DbInterner::conjure()))
|
||||
fn ty_of_expr(&self, expr: ast::Expr) -> Option<Ty<'db>> {
|
||||
self.infer()?.type_of_expr_or_pat(self.expr_id(expr)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,20 +10,21 @@
|
|||
|
||||
use std::iter;
|
||||
|
||||
use hir_ty::TyBuilder;
|
||||
use hir_ty::db::HirDatabase;
|
||||
use hir_ty::mir::BorrowKind;
|
||||
use hir_ty::{
|
||||
db::HirDatabase,
|
||||
mir::BorrowKind,
|
||||
next_solver::{DbInterner, Ty},
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use rustc_hash::FxHashSet;
|
||||
use rustc_type_ir::inherent::Ty as _;
|
||||
use span::Edition;
|
||||
|
||||
use crate::{
|
||||
Adt, AssocItem, GenericDef, GenericParam, HasAttrs, HasVisibility, Impl, ModuleDef, ScopeDef,
|
||||
Type, TypeParam,
|
||||
Type, TypeParam, term_search::Expr,
|
||||
};
|
||||
|
||||
use crate::term_search::Expr;
|
||||
|
||||
use super::{LookupTable, NewTypesKey, TermSearchCtx};
|
||||
|
||||
/// # Trivial tactic
|
||||
|
|
@ -596,10 +597,13 @@ pub(super) fn famous_types<'a, 'lt, 'db, DB: HirDatabase>(
|
|||
) -> impl Iterator<Item = Expr<'db>> + use<'a, 'db, 'lt, DB> {
|
||||
let db = ctx.sema.db;
|
||||
let module = ctx.scope.module();
|
||||
let interner = DbInterner::new_with(db, None, None);
|
||||
let bool_ty = Ty::new_bool(interner);
|
||||
let unit_ty = Ty::new_unit(interner);
|
||||
[
|
||||
Expr::FamousType { ty: Type::new(db, module.id, TyBuilder::bool()), value: "true" },
|
||||
Expr::FamousType { ty: Type::new(db, module.id, TyBuilder::bool()), value: "false" },
|
||||
Expr::FamousType { ty: Type::new(db, module.id, TyBuilder::unit()), value: "()" },
|
||||
Expr::FamousType { ty: Type::new(db, module.id, bool_ty), value: "true" },
|
||||
Expr::FamousType { ty: Type::new(db, module.id, bool_ty), value: "false" },
|
||||
Expr::FamousType { ty: Type::new(db, module.id, unit_ty), value: "()" },
|
||||
]
|
||||
.into_iter()
|
||||
.inspect(|exprs| {
|
||||
|
|
|
|||
|
|
@ -695,7 +695,7 @@ pub(super) fn definition(
|
|||
DropInfo { drop_glue: field.ty(db).to_type(db).drop_glue(db), has_dtor: None }
|
||||
}
|
||||
Definition::Adt(Adt::Struct(strukt)) => {
|
||||
let struct_drop_glue = strukt.ty_placeholders(db).drop_glue(db);
|
||||
let struct_drop_glue = strukt.ty_params(db).drop_glue(db);
|
||||
let mut fields_drop_glue = strukt
|
||||
.fields(db)
|
||||
.iter()
|
||||
|
|
@ -716,10 +716,10 @@ pub(super) fn definition(
|
|||
// Unions cannot have fields with drop glue.
|
||||
Definition::Adt(Adt::Union(union)) => DropInfo {
|
||||
drop_glue: DropGlue::None,
|
||||
has_dtor: Some(union.ty_placeholders(db).drop_glue(db) != DropGlue::None),
|
||||
has_dtor: Some(union.ty_params(db).drop_glue(db) != DropGlue::None),
|
||||
},
|
||||
Definition::Adt(Adt::Enum(enum_)) => {
|
||||
let enum_drop_glue = enum_.ty_placeholders(db).drop_glue(db);
|
||||
let enum_drop_glue = enum_.ty_params(db).drop_glue(db);
|
||||
let fields_drop_glue = enum_
|
||||
.variants(db)
|
||||
.iter()
|
||||
|
|
@ -748,7 +748,7 @@ pub(super) fn definition(
|
|||
DropInfo { drop_glue: fields_drop_glue, has_dtor: None }
|
||||
}
|
||||
Definition::TypeAlias(type_alias) => {
|
||||
DropInfo { drop_glue: type_alias.ty_placeholders(db).drop_glue(db), has_dtor: None }
|
||||
DropInfo { drop_glue: type_alias.ty_params(db).drop_glue(db), has_dtor: None }
|
||||
}
|
||||
Definition::Local(local) => {
|
||||
DropInfo { drop_glue: local.ty(db).drop_glue(db), has_dtor: None }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue