Bump chalk

This commit is contained in:
Laurențiu Nicola 2021-12-19 18:58:39 +02:00
parent e687e53695
commit 32b6f103a6
32 changed files with 602 additions and 620 deletions

16
Cargo.lock generated
View file

@ -171,9 +171,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chalk-derive"
version = "0.74.0"
version = "0.75.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d8c85134e234bead3fb78e4abd3ca2bdc228e5897b7f0fcd5265c4f4294375"
checksum = "d54e3b5f9e3425e6b119ff07568d8d006bfa5a8d6f78a9cbc3530b1e962e316c"
dependencies = [
"proc-macro2",
"quote",
@ -183,9 +183,9 @@ dependencies = [
[[package]]
name = "chalk-ir"
version = "0.74.0"
version = "0.75.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b08046b4a060d3fbf9df521a3aca331ff14d0a50c184b09a7b80edca1bf2aa79"
checksum = "2b79e5a1d04b79311e90c69356a2c62027853906a7e33b3e070b93c055fc3e8a"
dependencies = [
"bitflags",
"chalk-derive",
@ -194,9 +194,9 @@ dependencies = [
[[package]]
name = "chalk-recursive"
version = "0.74.0"
version = "0.75.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8d0190d6f86bdd3395fb4482879cda3e40a14a4c32241805301fb079fd7b62c"
checksum = "c39f59e975a6ffdee8eae3b396fc903fca18b8d1de674bb2aae4da643db07685"
dependencies = [
"chalk-derive",
"chalk-ir",
@ -207,9 +207,9 @@ dependencies = [
[[package]]
name = "chalk-solve"
version = "0.74.0"
version = "0.75.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bb39cbb1887edb2e12513ad811bea9a70faf4f98f4de794c5899c2c2e43e1b4"
checksum = "a5d2a1db6605aba70a58820bd80ac422b218913a510f1a40beef9efc5371ea1d"
dependencies = [
"chalk-derive",
"chalk-ir",

View file

@ -247,7 +247,7 @@ impl HirDisplay for TypeParam {
let bounds = f.db.generic_predicates_for_param(self.id, None);
let substs = TyBuilder::type_params_subst(f.db, self.id.parent);
let predicates: Vec<_> =
bounds.iter().cloned().map(|b| b.substitute(&Interner, &substs)).collect();
bounds.iter().cloned().map(|b| b.substitute(Interner, &substs)).collect();
let krate = self.id.parent.krate(f.db).id;
let sized_trait =
f.db.lang_item(krate, SmolStr::new_inline("sized"))

View file

@ -796,7 +796,7 @@ impl Field {
VariantDef::Variant(it) => it.parent.id.into(),
};
let substs = TyBuilder::type_params_subst(db, generic_def_id);
let ty = db.field_types(var_id)[self.id].clone().substitute(&Interner, &substs);
let ty = db.field_types(var_id)[self.id].clone().substitute(Interner, &substs);
Type::new(db, self.parent.module(db).id.krate(), var_id, ty)
}
@ -2136,7 +2136,7 @@ impl TypeParam {
pub fn ty(self, db: &dyn HirDatabase) -> Type {
let resolver = self.id.parent.resolver(db.upcast());
let krate = self.id.parent.module(db.upcast()).krate();
let ty = TyKind::Placeholder(hir_ty::to_placeholder_idx(db, self.id)).intern(&Interner);
let ty = TyKind::Placeholder(hir_ty::to_placeholder_idx(db, self.id)).intern(Interner);
Type::new_with_resolver_inner(db, krate, &resolver, ty)
}
@ -2159,7 +2159,7 @@ impl TypeParam {
let krate = self.id.parent.module(db.upcast()).krate();
let ty = params.get(local_idx)?.clone();
let subst = TyBuilder::type_params_subst(db, self.id.parent);
let ty = ty.substitute(&Interner, &subst_prefix(&subst, local_idx));
let ty = ty.substitute(Interner, &subst_prefix(&subst, local_idx));
Some(Type::new_with_resolver_inner(db, krate, &resolver, ty))
}
}
@ -2381,31 +2381,31 @@ impl Type {
}
pub fn is_unit(&self) -> bool {
matches!(self.ty.kind(&Interner), TyKind::Tuple(0, ..))
matches!(self.ty.kind(Interner), TyKind::Tuple(0, ..))
}
pub fn is_bool(&self) -> bool {
matches!(self.ty.kind(&Interner), TyKind::Scalar(Scalar::Bool))
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Bool))
}
pub fn is_never(&self) -> bool {
matches!(self.ty.kind(&Interner), TyKind::Never)
matches!(self.ty.kind(Interner), TyKind::Never)
}
pub fn is_mutable_reference(&self) -> bool {
matches!(self.ty.kind(&Interner), TyKind::Ref(hir_ty::Mutability::Mut, ..))
matches!(self.ty.kind(Interner), TyKind::Ref(hir_ty::Mutability::Mut, ..))
}
pub fn is_reference(&self) -> bool {
matches!(self.ty.kind(&Interner), TyKind::Ref(..))
matches!(self.ty.kind(Interner), TyKind::Ref(..))
}
pub fn is_usize(&self) -> bool {
matches!(self.ty.kind(&Interner), TyKind::Scalar(Scalar::Uint(UintTy::Usize)))
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Uint(UintTy::Usize)))
}
pub fn remove_ref(&self) -> Option<Type> {
match &self.ty.kind(&Interner) {
match &self.ty.kind(Interner) {
TyKind::Ref(.., ty) => Some(self.derived(ty.clone())),
_ => None,
}
@ -2434,7 +2434,7 @@ impl Type {
};
let canonical_ty =
Canonical { value: self.ty.clone(), binders: CanonicalVarKinds::empty(&Interner) };
Canonical { value: self.ty.clone(), binders: CanonicalVarKinds::empty(Interner) };
method_resolution::implements_trait(
&canonical_ty,
db,
@ -2457,7 +2457,7 @@ impl Type {
};
let canonical_ty =
Canonical { value: self.ty.clone(), binders: CanonicalVarKinds::empty(&Interner) };
Canonical { value: self.ty.clone(), binders: CanonicalVarKinds::empty(Interner) };
method_resolution::implements_trait_unique(
&canonical_ty,
db,
@ -2474,8 +2474,8 @@ impl Type {
.build();
let goal = Canonical {
value: hir_ty::InEnvironment::new(&self.env.env, trait_ref.cast(&Interner)),
binders: CanonicalVarKinds::empty(&Interner),
value: hir_ty::InEnvironment::new(&self.env.env, trait_ref.cast(Interner)),
binders: CanonicalVarKinds::empty(Interner),
};
db.trait_solve(self.krate, goal).is_some()
@ -2497,9 +2497,9 @@ impl Type {
AliasEq {
alias: AliasTy::Projection(projection),
ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
.intern(&Interner),
.intern(Interner),
}
.cast(&Interner),
.cast(Interner),
),
[TyVariableKind::General].into_iter(),
);
@ -2508,9 +2508,9 @@ impl Type {
Solution::Unique(s) => s
.value
.subst
.as_slice(&Interner)
.as_slice(Interner)
.first()
.map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone())),
.map(|ty| self.derived(ty.assert_ty_ref(Interner).clone())),
Solution::Ambig(_) => None,
}
}
@ -2532,15 +2532,15 @@ impl Type {
}
pub fn is_closure(&self) -> bool {
matches!(&self.ty.kind(&Interner), TyKind::Closure { .. })
matches!(&self.ty.kind(Interner), TyKind::Closure { .. })
}
pub fn is_fn(&self) -> bool {
matches!(&self.ty.kind(&Interner), TyKind::FnDef(..) | TyKind::Function { .. })
matches!(&self.ty.kind(Interner), TyKind::FnDef(..) | TyKind::Function { .. })
}
pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
let adt_id = match *self.ty.kind(&Interner) {
let adt_id = match *self.ty.kind(Interner) {
TyKind::Adt(hir_ty::AdtId(adt_id), ..) => adt_id,
_ => return false,
};
@ -2553,14 +2553,14 @@ impl Type {
}
pub fn is_raw_ptr(&self) -> bool {
matches!(&self.ty.kind(&Interner), TyKind::Raw(..))
matches!(&self.ty.kind(Interner), TyKind::Raw(..))
}
pub fn contains_unknown(&self) -> bool {
return go(&self.ty);
fn go(ty: &Ty) -> bool {
match ty.kind(&Interner) {
match ty.kind(Interner) {
TyKind::Error => true,
TyKind::Adt(_, substs)
@ -2569,7 +2569,7 @@ impl Type {
| TyKind::OpaqueType(_, substs)
| TyKind::FnDef(_, substs)
| TyKind::Closure(_, substs) => {
substs.iter(&Interner).filter_map(|a| a.ty(&Interner)).any(go)
substs.iter(Interner).filter_map(|a| a.ty(Interner)).any(go)
}
TyKind::Array(_ty, len) if len.is_unknown() => true,
@ -2595,7 +2595,7 @@ impl Type {
}
pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
let (variant_id, substs) = match self.ty.kind(&Interner) {
let (variant_id, substs) = match self.ty.kind(Interner) {
TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), substs) => ((*s).into(), substs),
TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), substs) => ((*u).into(), substs),
_ => return Vec::new(),
@ -2605,17 +2605,17 @@ impl Type {
.iter()
.map(|(local_id, ty)| {
let def = Field { parent: variant_id.into(), id: local_id };
let ty = ty.clone().substitute(&Interner, substs);
let ty = ty.clone().substitute(Interner, substs);
(def, self.derived(ty))
})
.collect()
}
pub fn tuple_fields(&self, _db: &dyn HirDatabase) -> Vec<Type> {
if let TyKind::Tuple(_, substs) = &self.ty.kind(&Interner) {
if let TyKind::Tuple(_, substs) = &self.ty.kind(Interner) {
substs
.iter(&Interner)
.map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone()))
.iter(Interner)
.map(|ty| self.derived(ty.assert_ty_ref(Interner).clone()))
.collect()
} else {
Vec::new()
@ -2678,8 +2678,8 @@ impl Type {
.strip_references()
.as_adt()
.into_iter()
.flat_map(|(_, substs)| substs.iter(&Interner))
.filter_map(|arg| arg.ty(&Interner).cloned())
.flat_map(|(_, substs)| substs.iter(Interner))
.filter_map(|arg| arg.ty(Interner).cloned())
.map(move |ty| self.derived(ty))
}
@ -2819,7 +2819,7 @@ impl Type {
pub fn env_traits<'a>(&'a self, db: &'a dyn HirDatabase) -> impl Iterator<Item = Trait> + 'a {
let _p = profile::span("env_traits");
self.autoderef_(db)
.filter(|ty| matches!(ty.kind(&Interner), TyKind::Placeholder(_)))
.filter(|ty| matches!(ty.kind(Interner), TyKind::Placeholder(_)))
.flat_map(|ty| {
self.env
.traits_in_scope_from_clauses(ty)
@ -2857,7 +2857,7 @@ impl Type {
substs: &Substitution,
cb: &mut impl FnMut(Type),
) {
for ty in substs.iter(&Interner).filter_map(|a| a.ty(&Interner)) {
for ty in substs.iter(Interner).filter_map(|a| a.ty(Interner)) {
walk_type(db, &type_.derived(ty.clone()), cb);
}
}
@ -2872,11 +2872,8 @@ impl Type {
if let WhereClause::Implemented(trait_ref) = pred.skip_binders() {
cb(type_.clone());
// skip the self type. it's likely the type we just got the bounds from
for ty in trait_ref
.substitution
.iter(&Interner)
.skip(1)
.filter_map(|a| a.ty(&Interner))
for ty in
trait_ref.substitution.iter(Interner).skip(1).filter_map(|a| a.ty(Interner))
{
walk_type(db, &type_.derived(ty.clone()), cb);
}
@ -2886,7 +2883,7 @@ impl Type {
fn walk_type(db: &dyn HirDatabase, type_: &Type, cb: &mut impl FnMut(Type)) {
let ty = type_.ty.strip_references();
match ty.kind(&Interner) {
match ty.kind(Interner) {
TyKind::Adt(_, substs) => {
cb(type_.derived(ty.clone()));
walk_substs(db, type_, substs, cb);

View file

@ -821,7 +821,7 @@ impl<'db> SemanticsImpl<'db> {
fn resolve_method_call_as_callable(&self, call: &ast::MethodCallExpr) -> Option<Callable> {
let (func, subst) = self.analyze(call.syntax()).resolve_method_call(self.db, call)?;
let ty = self.db.value_ty(func.into()).substitute(&Interner, &subst);
let ty = self.db.value_ty(func.into()).substitute(Interner, &subst);
let resolver = self.analyze(call.syntax()).resolver;
let ty = Type::new_with_resolver(self.db, &resolver, ty)?;
let mut res = ty.as_callable(self.db)?;

View file

@ -201,7 +201,7 @@ impl SourceAnalyzer {
let variant_data = variant.variant_data(db.upcast());
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(variant).get(field.local_id)?.clone().substitute(Interner, subst);
Some((field.into(), local, Type::new_with_resolver(db, &self.resolver, field_ty)?))
}
@ -417,7 +417,7 @@ impl SourceAnalyzer {
.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].clone().substitute(Interner, substs);
(field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty))
})
.collect()

View file

@ -18,9 +18,9 @@ ena = "0.14.0"
tracing = "0.1"
rustc-hash = "1.1.0"
scoped-tls = "1"
chalk-solve = { version = "0.74", default-features = false }
chalk-ir = "0.74"
chalk-recursive = { version = "0.74", default-features = false }
chalk-solve = { version = "0.75", default-features = false }
chalk-ir = "0.75"
chalk-recursive = { version = "0.75", default-features = false }
la-arena = { version = "0.3.0", path = "../../lib/arena" }
once_cell = { version = "1.5.0" }

View file

@ -122,7 +122,7 @@ pub(crate) fn deref(
}
fn builtin_deref(ty: &Ty) -> Option<&Ty> {
match ty.kind(&Interner) {
match ty.kind(Interner) {
TyKind::Ref(.., ty) => Some(ty),
TyKind::Raw(.., ty) => Some(ty),
_ => None,
@ -158,7 +158,7 @@ fn deref_by_trait(
let implements_goal = Canonical {
binders: ty.goal.binders.clone(),
value: InEnvironment {
goal: trait_ref.cast(&Interner),
goal: trait_ref.cast(Interner),
environment: ty.environment.clone(),
},
};
@ -171,18 +171,18 @@ fn deref_by_trait(
alias: AliasTy::Projection(projection),
ty: TyKind::BoundVar(BoundVar::new(
DebruijnIndex::INNERMOST,
ty.goal.binders.len(&Interner),
ty.goal.binders.len(Interner),
))
.intern(&Interner),
.intern(Interner),
};
let in_env = InEnvironment { goal: alias_eq.cast(&Interner), environment: ty.environment };
let in_env = InEnvironment { goal: alias_eq.cast(Interner), environment: ty.environment };
let canonical = Canonical {
value: in_env,
binders: CanonicalVarKinds::from_iter(
&Interner,
ty.goal.binders.iter(&Interner).cloned().chain(Some(chalk_ir::WithKind::new(
Interner,
ty.goal.binders.iter(Interner).cloned().chain(Some(chalk_ir::WithKind::new(
VariableKind::Ty(chalk_ir::TyVariableKind::General),
chalk_ir::UniverseIndex::ROOT,
))),
@ -209,8 +209,8 @@ fn deref_by_trait(
// assumptions will be broken. We would need to properly introduce
// new variables in that case
for i in 1..binders.len(&Interner) {
if subst.at(&Interner, i - 1).assert_ty_ref(&Interner).kind(&Interner)
for i in 1..binders.len(Interner) {
if subst.at(Interner, i - 1).assert_ty_ref(Interner).kind(Interner)
!= &TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, i - 1))
{
warn!("complex solution for derefing {:?}: {:?}, ignoring", ty.goal, solution);
@ -220,10 +220,7 @@ fn deref_by_trait(
// FIXME: we remove lifetime variables here since they can confuse
// the method resolution code later
Some(fixup_lifetime_variables(Canonical {
value: subst
.at(&Interner, subst.len(&Interner) - 1)
.assert_ty_ref(&Interner)
.clone(),
value: subst.at(Interner, subst.len(Interner) - 1).assert_ty_ref(Interner).clone(),
binders: binders.clone(),
}))
}
@ -240,25 +237,25 @@ fn fixup_lifetime_variables<T: Fold<Interner, Result = T> + HasInterner<Interner
// Removes lifetime variables from the Canonical, replacing them by static lifetimes.
let mut i = 0;
let subst = Substitution::from_iter(
&Interner,
c.binders.iter(&Interner).map(|vk| match vk.kind {
Interner,
c.binders.iter(Interner).map(|vk| match vk.kind {
VariableKind::Ty(_) => {
let index = i;
i += 1;
BoundVar::new(DebruijnIndex::INNERMOST, index).to_ty(&Interner).cast(&Interner)
BoundVar::new(DebruijnIndex::INNERMOST, index).to_ty(Interner).cast(Interner)
}
VariableKind::Lifetime => static_lifetime().cast(&Interner),
VariableKind::Lifetime => static_lifetime().cast(Interner),
VariableKind::Const(_) => unimplemented!(),
}),
);
let binders = CanonicalVarKinds::from_iter(
&Interner,
c.binders.iter(&Interner).filter(|vk| match vk.kind {
Interner,
c.binders.iter(Interner).filter(|vk| match vk.kind {
VariableKind::Ty(_) => true,
VariableKind::Lifetime => false,
VariableKind::Const(_) => true,
}),
);
let value = subst.apply(c.value, &Interner);
let value = subst.apply(c.value, Interner);
Canonical { binders, value }
}

View file

@ -33,12 +33,12 @@ impl<D> TyBuilder<D> {
fn build_internal(self) -> (D, Substitution) {
assert_eq!(self.vec.len(), self.param_count);
let subst = Substitution::from_iter(&Interner, self.vec);
let subst = Substitution::from_iter(Interner, self.vec);
(self.data, subst)
}
pub fn push(mut self, arg: impl CastTo<GenericArg>) -> Self {
self.vec.push(arg.cast(&Interner));
self.vec.push(arg.cast(Interner));
self
}
@ -49,56 +49,56 @@ impl<D> TyBuilder<D> {
pub fn fill_with_bound_vars(self, debruijn: DebruijnIndex, starting_from: usize) -> Self {
self.fill(
(starting_from..)
.map(|idx| TyKind::BoundVar(BoundVar::new(debruijn, idx)).intern(&Interner)),
.map(|idx| TyKind::BoundVar(BoundVar::new(debruijn, idx)).intern(Interner)),
)
}
pub fn fill_with_unknown(self) -> Self {
self.fill(iter::repeat(TyKind::Error.intern(&Interner)))
self.fill(iter::repeat(TyKind::Error.intern(Interner)))
}
pub fn fill(mut self, filler: impl Iterator<Item = impl CastTo<GenericArg>>) -> Self {
self.vec.extend(filler.take(self.remaining()).casted(&Interner));
self.vec.extend(filler.take(self.remaining()).casted(Interner));
assert_eq!(self.remaining(), 0);
self
}
pub fn use_parent_substs(mut self, parent_substs: &Substitution) -> Self {
assert!(self.vec.is_empty());
assert!(parent_substs.len(&Interner) <= self.param_count);
self.vec.extend(parent_substs.iter(&Interner).cloned());
assert!(parent_substs.len(Interner) <= self.param_count);
self.vec.extend(parent_substs.iter(Interner).cloned());
self
}
}
impl TyBuilder<()> {
pub fn unit() -> Ty {
TyKind::Tuple(0, Substitution::empty(&Interner)).intern(&Interner)
TyKind::Tuple(0, Substitution::empty(Interner)).intern(Interner)
}
pub fn fn_ptr(sig: CallableSig) -> Ty {
TyKind::Function(sig.to_fn_ptr()).intern(&Interner)
TyKind::Function(sig.to_fn_ptr()).intern(Interner)
}
pub fn builtin(builtin: BuiltinType) -> Ty {
match builtin {
BuiltinType::Char => TyKind::Scalar(Scalar::Char).intern(&Interner),
BuiltinType::Bool => TyKind::Scalar(Scalar::Bool).intern(&Interner),
BuiltinType::Str => TyKind::Str.intern(&Interner),
BuiltinType::Char => TyKind::Scalar(Scalar::Char).intern(Interner),
BuiltinType::Bool => TyKind::Scalar(Scalar::Bool).intern(Interner),
BuiltinType::Str => TyKind::Str.intern(Interner),
BuiltinType::Int(t) => {
TyKind::Scalar(Scalar::Int(primitive::int_ty_from_builtin(t))).intern(&Interner)
TyKind::Scalar(Scalar::Int(primitive::int_ty_from_builtin(t))).intern(Interner)
}
BuiltinType::Uint(t) => {
TyKind::Scalar(Scalar::Uint(primitive::uint_ty_from_builtin(t))).intern(&Interner)
TyKind::Scalar(Scalar::Uint(primitive::uint_ty_from_builtin(t))).intern(Interner)
}
BuiltinType::Float(t) => {
TyKind::Scalar(Scalar::Float(primitive::float_ty_from_builtin(t))).intern(&Interner)
TyKind::Scalar(Scalar::Float(primitive::float_ty_from_builtin(t))).intern(Interner)
}
}
}
pub fn slice(argument: Ty) -> Ty {
TyKind::Slice(argument).intern(&Interner)
TyKind::Slice(argument).intern(Interner)
}
pub fn type_params_subst(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substitution {
@ -134,12 +134,12 @@ impl TyBuilder<hir_def::AdtId> {
let defaults = db.generic_defaults(self.data.into());
for default_ty in defaults.iter().skip(self.vec.len()) {
if default_ty.skip_binders().is_unknown() {
self.vec.push(fallback().cast(&Interner));
self.vec.push(fallback().cast(Interner));
} else {
// each default can depend on the previous parameters
let subst_so_far = Substitution::from_iter(&Interner, self.vec.clone());
let subst_so_far = Substitution::from_iter(Interner, self.vec.clone());
self.vec
.push(default_ty.clone().substitute(&Interner, &subst_so_far).cast(&Interner));
.push(default_ty.clone().substitute(Interner, &subst_so_far).cast(Interner));
}
}
self
@ -147,7 +147,7 @@ impl TyBuilder<hir_def::AdtId> {
pub fn build(self) -> Ty {
let (adt, subst) = self.build_internal();
TyKind::Adt(AdtId(adt), subst).intern(&Interner)
TyKind::Adt(AdtId(adt), subst).intern(Interner)
}
}
@ -159,7 +159,7 @@ impl TyBuilder<Tuple> {
pub fn build(self) -> Ty {
let (Tuple(size), subst) = self.build_internal();
TyKind::Tuple(size, subst).intern(&Interner)
TyKind::Tuple(size, subst).intern(Interner)
}
}
@ -194,13 +194,13 @@ impl TyBuilder<TypeAliasId> {
impl<T: HasInterner<Interner = Interner> + Fold<Interner>> TyBuilder<Binders<T>> {
fn subst_binders(b: Binders<T>) -> Self {
let param_count = b.binders.len(&Interner);
let param_count = b.binders.len(Interner);
TyBuilder::new(b, param_count)
}
pub fn build(self) -> <T as Fold<Interner>>::Result {
let (b, subst) = self.build_internal();
b.substitute(&Interner, &subst)
b.substitute(Interner, &subst)
}
}

View file

@ -61,7 +61,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
}
fn discriminant_type(&self, _ty: chalk_ir::Ty<Interner>) -> chalk_ir::Ty<Interner> {
// FIXME: keep track of this
chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::U32)).intern(&Interner)
chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::U32)).intern(Interner)
}
fn impl_datum(&self, impl_id: ImplId) -> Arc<ImplDatum> {
self.db.impl_datum(self.krate, impl_id)
@ -83,14 +83,14 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
debug!("impls_for_trait {:?}", trait_id);
let trait_: hir_def::TraitId = from_chalk_trait_id(trait_id);
let ty: Ty = parameters[0].assert_ty_ref(&Interner).clone();
let ty: Ty = parameters[0].assert_ty_ref(Interner).clone();
fn binder_kind(
ty: &Ty,
binders: &CanonicalVarKinds<Interner>,
) -> Option<chalk_ir::TyVariableKind> {
if let TyKind::BoundVar(bv) = ty.kind(&Interner) {
let binders = binders.as_slice(&Interner);
if let TyKind::BoundVar(bv) = ty.kind(Interner) {
let binders = binders.as_slice(Interner);
if bv.debruijn == DebruijnIndex::INNERMOST {
if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind {
return Some(tk);
@ -173,8 +173,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
// We don't do coherence checking (yet)
unimplemented!()
}
fn interner(&self) -> &Interner {
&Interner
fn interner(&self) -> Interner {
Interner
}
fn well_known_trait_id(
&self,
@ -232,12 +232,12 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
trait_id: to_chalk_trait_id(future_trait),
// Self type as the first parameter.
substitution: Substitution::from1(
&Interner,
Interner,
TyKind::BoundVar(BoundVar {
debruijn: DebruijnIndex::INNERMOST,
index: 0,
})
.intern(&Interner),
.intern(Interner),
),
});
let proj_bound = WhereClause::AliasEq(AliasEq {
@ -245,14 +245,14 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
associated_ty_id: to_assoc_type_id(future_output),
// Self type as the first parameter.
substitution: Substitution::from1(
&Interner,
Interner,
TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
.intern(&Interner),
.intern(Interner),
),
}),
// The parameter of the opaque type.
ty: TyKind::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 })
.intern(&Interner),
.intern(Interner),
});
let bound = OpaqueTyDatumBound {
bounds: make_only_type_binders(
@ -283,7 +283,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
fn hidden_opaque_type(&self, _id: chalk_ir::OpaqueTyId<Interner>) -> chalk_ir::Ty<Interner> {
// FIXME: actually provide the hidden type; it is relevant for auto traits
TyKind::Error.intern(&Interner)
TyKind::Error.intern(Interner)
}
fn is_object_safe(&self, _trait_id: chalk_ir::TraitId<Interner>) -> bool {
@ -304,13 +304,13 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
_closure_id: chalk_ir::ClosureId<Interner>,
substs: &chalk_ir::Substitution<Interner>,
) -> chalk_ir::Binders<rust_ir::FnDefInputsAndOutputDatum<Interner>> {
let sig_ty = substs.at(&Interner, 0).assert_ty_ref(&Interner).clone();
let sig_ty = substs.at(Interner, 0).assert_ty_ref(Interner).clone();
let sig = &sig_ty.callable_sig(self.db).expect("first closure param should be fn ptr");
let io = rust_ir::FnDefInputsAndOutputDatum {
argument_types: sig.params().to_vec(),
return_type: sig.ret().clone(),
};
make_only_type_binders(0, io.shifted_in(&Interner))
make_only_type_binders(0, io.shifted_in(Interner))
}
fn closure_upvars(
&self,
@ -325,7 +325,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
_closure_id: chalk_ir::ClosureId<Interner>,
_substs: &chalk_ir::Substitution<Interner>,
) -> chalk_ir::Substitution<Interner> {
Substitution::empty(&Interner)
Substitution::empty(Interner)
}
fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String {
@ -409,7 +409,7 @@ pub(crate) fn associated_ty_data_query(
let ctx = crate::TyLoweringContext::new(db, &resolver)
.with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable);
let self_ty =
TyKind::BoundVar(BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)).intern(&Interner);
TyKind::BoundVar(BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)).intern(Interner);
let mut bounds: Vec<_> = type_alias_data
.bounds
.iter()
@ -426,7 +426,7 @@ pub(crate) fn associated_ty_data_query(
let trait_bound =
rust_ir::TraitBound { trait_id: sized_trait, args_no_self: Default::default() };
let inline_bound = rust_ir::InlineBound::TraitBound(trait_bound);
chalk_ir::Binders::empty(&Interner, inline_bound)
chalk_ir::Binders::empty(Interner, inline_bound)
});
bounds.extend(sized_bound);
bounds.shrink_to_fit();
@ -472,7 +472,7 @@ pub(crate) fn trait_datum_query(
lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name));
let trait_datum = TraitDatum {
id: trait_id,
binders: make_only_type_binders(bound_vars.len(&Interner), trait_datum_bound),
binders: make_only_type_binders(bound_vars.len(Interner), trait_datum_bound),
flags,
associated_ty_ids,
well_known,
@ -611,7 +611,7 @@ fn impl_def_datum(
.collect();
debug!("impl_datum: {:?}", impl_datum_bound);
let impl_datum = ImplDatum {
binders: make_only_type_binders(bound_vars.len(&Interner), impl_datum_bound),
binders: make_only_type_binders(bound_vars.len(Interner), impl_datum_bound),
impl_type,
polarity,
associated_ty_value_ids,
@ -677,7 +677,7 @@ pub(crate) fn fn_def_datum_query(
argument_types: sig.params().to_vec(),
return_type: sig.ret().clone(),
}
.shifted_in(&Interner),
.shifted_in(Interner),
),
where_clauses,
};
@ -693,7 +693,7 @@ pub(crate) fn fn_def_variance_query(db: &dyn HirDatabase, fn_def_id: FnDefId) ->
let callable_def: CallableDefId = from_chalk(db, fn_def_id);
let generic_params = generics(db.upcast(), callable_def.into());
Variances::from_iter(
&Interner,
Interner,
std::iter::repeat(chalk_ir::Variance::Invariant).take(generic_params.len()),
)
}
@ -704,7 +704,7 @@ pub(crate) fn adt_variance_query(
) -> Variances {
let generic_params = generics(db.upcast(), adt_id.into());
Variances::from_iter(
&Interner,
Interner,
std::iter::repeat(chalk_ir::Variance::Invariant).take(generic_params.len()),
)
}
@ -717,7 +717,7 @@ pub(super) fn convert_where_clauses(
let generic_predicates = db.generic_predicates(def);
let mut result = Vec::with_capacity(generic_predicates.len());
for pred in generic_predicates.iter() {
result.push(pred.clone().substitute(&Interner, substs));
result.push(pred.clone().substitute(Interner, substs));
}
result
}
@ -729,30 +729,30 @@ pub(super) fn generic_predicate_to_inline_bound(
) -> Option<chalk_ir::Binders<rust_ir::InlineBound<Interner>>> {
// An InlineBound is like a GenericPredicate, except the self type is left out.
// We don't have a special type for this, but Chalk does.
let self_ty_shifted_in = self_ty.clone().shifted_in_from(&Interner, DebruijnIndex::ONE);
let self_ty_shifted_in = self_ty.clone().shifted_in_from(Interner, DebruijnIndex::ONE);
let (pred, binders) = pred.as_ref().into_value_and_skipped_binders();
match pred {
WhereClause::Implemented(trait_ref) => {
if trait_ref.self_type_parameter(&Interner) != self_ty_shifted_in {
if trait_ref.self_type_parameter(Interner) != self_ty_shifted_in {
// we can only convert predicates back to type bounds if they
// have the expected self type
return None;
}
let args_no_self = trait_ref.substitution.as_slice(&Interner)[1..]
let args_no_self = trait_ref.substitution.as_slice(Interner)[1..]
.iter()
.map(|ty| ty.clone().cast(&Interner))
.map(|ty| ty.clone().cast(Interner))
.collect();
let trait_bound = rust_ir::TraitBound { trait_id: trait_ref.trait_id, args_no_self };
Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
}
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
if projection_ty.self_type_parameter(&Interner) != self_ty_shifted_in {
if projection_ty.self_type_parameter(Interner) != self_ty_shifted_in {
return None;
}
let trait_ = projection_ty.trait_(db);
let args_no_self = projection_ty.substitution.as_slice(&Interner)[1..]
let args_no_self = projection_ty.substitution.as_slice(Interner)[1..]
.iter()
.map(|ty| ty.clone().cast(&Interner))
.map(|ty| ty.clone().cast(Interner))
.collect();
let alias_eq_bound = rust_ir::AliasEqBound {
value: ty.clone(),

View file

@ -46,30 +46,30 @@ pub trait TyExt {
impl TyExt for Ty {
fn is_unit(&self) -> bool {
matches!(self.kind(&Interner), TyKind::Tuple(0, _))
matches!(self.kind(Interner), TyKind::Tuple(0, _))
}
fn is_never(&self) -> bool {
matches!(self.kind(&Interner), TyKind::Never)
matches!(self.kind(Interner), TyKind::Never)
}
fn is_unknown(&self) -> bool {
matches!(self.kind(&Interner), TyKind::Error)
matches!(self.kind(Interner), TyKind::Error)
}
fn is_ty_var(&self) -> bool {
matches!(self.kind(&Interner), TyKind::InferenceVar(_, _))
matches!(self.kind(Interner), TyKind::InferenceVar(_, _))
}
fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)> {
match self.kind(&Interner) {
match self.kind(Interner) {
TyKind::Adt(AdtId(adt), parameters) => Some((*adt, parameters)),
_ => None,
}
}
fn as_builtin(&self) -> Option<BuiltinType> {
match self.kind(&Interner) {
match self.kind(Interner) {
TyKind::Str => Some(BuiltinType::Str),
TyKind::Scalar(Scalar::Bool) => Some(BuiltinType::Bool),
TyKind::Scalar(Scalar::Char) => Some(BuiltinType::Char),
@ -98,7 +98,7 @@ impl TyExt for Ty {
}
fn as_tuple(&self) -> Option<&Substitution> {
match self.kind(&Interner) {
match self.kind(Interner) {
TyKind::Tuple(_, substs) => Some(substs),
_ => None,
}
@ -111,14 +111,14 @@ impl TyExt for Ty {
}
}
fn as_reference(&self) -> Option<(&Ty, Lifetime, Mutability)> {
match self.kind(&Interner) {
match self.kind(Interner) {
TyKind::Ref(mutability, lifetime, ty) => Some((ty, lifetime.clone(), *mutability)),
_ => None,
}
}
fn as_reference_or_ptr(&self) -> Option<(&Ty, Rawness, Mutability)> {
match self.kind(&Interner) {
match self.kind(Interner) {
TyKind::Ref(mutability, _, ty) => Some((ty, Rawness::Ref, *mutability)),
TyKind::Raw(mutability, ty) => Some((ty, Rawness::RawPtr, *mutability)),
_ => None,
@ -126,7 +126,7 @@ impl TyExt for Ty {
}
fn as_generic_def(&self, db: &dyn HirDatabase) -> Option<GenericDefId> {
match *self.kind(&Interner) {
match *self.kind(Interner) {
TyKind::Adt(AdtId(adt), ..) => Some(adt.into()),
TyKind::FnDef(callable, ..) => {
Some(db.lookup_intern_callable_def(callable.into()).into())
@ -138,22 +138,22 @@ impl TyExt for Ty {
}
fn callable_def(&self, db: &dyn HirDatabase) -> Option<CallableDefId> {
match self.kind(&Interner) {
match self.kind(Interner) {
&TyKind::FnDef(def, ..) => Some(db.lookup_intern_callable_def(def.into())),
_ => None,
}
}
fn callable_sig(&self, db: &dyn HirDatabase) -> Option<CallableSig> {
match self.kind(&Interner) {
match self.kind(Interner) {
TyKind::Function(fn_ptr) => Some(CallableSig::from_fn_ptr(fn_ptr)),
TyKind::FnDef(def, parameters) => {
let callable_def = db.lookup_intern_callable_def((*def).into());
let sig = db.callable_item_signature(callable_def);
Some(sig.substitute(&Interner, &parameters))
Some(sig.substitute(Interner, &parameters))
}
TyKind::Closure(.., substs) => {
let sig_param = substs.at(&Interner, 0).assert_ty_ref(&Interner);
let sig_param = substs.at(Interner, 0).assert_ty_ref(Interner);
sig_param.callable_sig(db)
}
_ => None,
@ -161,7 +161,7 @@ impl TyExt for Ty {
}
fn dyn_trait(&self) -> Option<TraitId> {
let trait_ref = match self.kind(&Interner) {
let trait_ref = match self.kind(Interner) {
TyKind::Dyn(dyn_ty) => dyn_ty.bounds.skip_binders().interned().get(0).and_then(|b| {
match b.skip_binders() {
WhereClause::Implemented(trait_ref) => Some(trait_ref),
@ -175,14 +175,14 @@ impl TyExt for Ty {
fn strip_references(&self) -> &Ty {
let mut t: &Ty = self;
while let TyKind::Ref(_mutability, _lifetime, ty) = t.kind(&Interner) {
while let TyKind::Ref(_mutability, _lifetime, ty) = t.kind(Interner) {
t = ty;
}
t
}
fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>> {
match self.kind(&Interner) {
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) => {
@ -195,10 +195,10 @@ impl TyExt for Ty {
// Parameters will be walked outside, and projection predicate is not used.
// So just provide the Future trait.
let impl_bound = Binders::empty(
&Interner,
Interner,
WhereClause::Implemented(TraitRef {
trait_id: to_chalk_trait_id(future_trait),
substitution: Substitution::empty(&Interner),
substitution: Substitution::empty(Interner),
}),
);
Some(vec![impl_bound])
@ -211,7 +211,7 @@ impl TyExt for Ty {
let data = (*it)
.as_ref()
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
data.substitute(&Interner, &subst).into_value_and_skipped_binders().0
data.substitute(Interner, &subst).into_value_and_skipped_binders().0
})
}
}
@ -224,7 +224,7 @@ impl TyExt for Ty {
let data = (*it)
.as_ref()
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
data.substitute(&Interner, &opaque_ty.substitution)
data.substitute(Interner, &opaque_ty.substitution)
})
}
// It always has an parameter for Future::Output type.
@ -243,15 +243,15 @@ impl TyExt for Ty {
let predicates = db
.generic_predicates(id.parent)
.iter()
.map(|pred| pred.clone().substitute(&Interner, &substs))
.map(|pred| pred.clone().substitute(Interner, &substs))
.filter(|wc| match &wc.skip_binders() {
WhereClause::Implemented(tr) => {
&tr.self_type_parameter(&Interner) == self
&tr.self_type_parameter(Interner) == self
}
WhereClause::AliasEq(AliasEq {
alias: AliasTy::Projection(proj),
ty: _,
}) => &proj.self_type_parameter(&Interner) == self,
}) => &proj.self_type_parameter(Interner) == self,
_ => false,
})
.collect::<Vec<_>>();
@ -266,7 +266,7 @@ impl TyExt for Ty {
}
fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId> {
match self.kind(&Interner) {
match self.kind(Interner) {
TyKind::AssociatedType(id, ..) => {
match from_assoc_type_id(*id).lookup(db.upcast()).container {
ItemContainerId::TraitId(trait_id) => Some(trait_id),
@ -287,7 +287,7 @@ impl TyExt for Ty {
}
fn equals_ctor(&self, other: &Ty) -> bool {
match (self.kind(&Interner), other.kind(&Interner)) {
match (self.kind(Interner), other.kind(Interner)) {
(TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2,
(TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_, _), TyKind::Array(_, _)) => {
true

View file

@ -18,7 +18,7 @@ pub trait ConstExt {
impl ConstExt for Const {
fn is_unknown(&self) -> bool {
match self.data(&Interner).value {
match self.data(Interner).value {
// interned Unknown
chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst {
interned: ConstScalar::Unknown,
@ -49,10 +49,10 @@ pub fn eval_usize(expr: &Expr) -> Option<u64> {
/// Interns a possibly-unknown target usize
pub fn usize_const(value: Option<u64>) -> Const {
ConstData {
ty: TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::Usize)).intern(&Interner),
ty: TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::Usize)).intern(Interner),
value: ConstValue::Concrete(chalk_ir::ConcreteConst {
interned: value.map(ConstScalar::Usize).unwrap_or(ConstScalar::Unknown),
}),
}
.intern(&Interner)
.intern(Interner)
}

View file

@ -224,7 +224,7 @@ impl ExprValidator {
Some(it) => it,
None => return,
};
let sig = db.callable_item_signature(callee.into()).substitute(&Interner, &subst);
let sig = db.callable_item_signature(callee.into()).substitute(Interner, &subst);
(sig, args.len() + 1)
}
@ -389,7 +389,7 @@ impl ExprValidator {
_ => return,
};
let (params, required) = match mismatch.expected.kind(&Interner) {
let (params, required) = match mismatch.expected.kind(Interner) {
TyKind::Adt(AdtId(hir_def::AdtId::EnumId(enum_id)), parameters)
if *enum_id == core_result_enum =>
{
@ -403,8 +403,7 @@ impl ExprValidator {
_ => return,
};
if params.len(&Interner) > 0
&& params.at(&Interner, 0).ty(&Interner) == Some(&mismatch.actual)
if params.len(Interner) > 0 && params.at(Interner, 0).ty(Interner) == Some(&mismatch.actual)
{
self.diagnostics
.push(BodyValidationDiagnostic::MissingOkOrSomeInTailExpr { expr: id, required });
@ -520,8 +519,8 @@ fn check_missing_refs(
(None, Some((referenced_ty, _, mutability))) if referenced_ty == arg_ty => {
Some((arg, Mutability::from_mutable(matches!(mutability, chalk_ir::Mutability::Mut))))
}
(None, Some((referenced_ty, _, mutability))) => match referenced_ty.kind(&Interner) {
TyKind::Slice(subst) if matches!(arg_ty.kind(&Interner), TyKind::Array(arr_subst, _) if arr_subst == subst) => {
(None, Some((referenced_ty, _, mutability))) => match referenced_ty.kind(Interner) {
TyKind::Slice(subst) if matches!(arg_ty.kind(Interner), TyKind::Array(arr_subst, _) if arr_subst == subst) => {
Some((
arg,
Mutability::from_mutable(matches!(mutability, chalk_ir::Mutability::Mut)),

View file

@ -130,7 +130,7 @@ impl<'a> PatCtxt<'a> {
}
hir_def::expr::Pat::Tuple { ref args, ellipsis } => {
let arity = match *ty.kind(&Interner) {
let arity = match *ty.kind(Interner) {
TyKind::Tuple(arity, _) => arity,
_ => panic!("unexpected type for tuple pattern: {:?}", ty),
};
@ -139,7 +139,7 @@ impl<'a> PatCtxt<'a> {
}
hir_def::expr::Pat::Bind { subpat, .. } => {
if let TyKind::Ref(.., rty) = ty.kind(&Interner) {
if let TyKind::Ref(.., rty) = ty.kind(Interner) {
ty = rty;
}
PatKind::Binding { subpattern: self.lower_opt_pattern(subpat) }
@ -224,7 +224,7 @@ impl<'a> PatCtxt<'a> {
let kind = match self.infer.variant_resolution_for_pat(pat) {
Some(variant_id) => {
if let VariantId::EnumVariantId(enum_variant) = variant_id {
let substs = match ty.kind(&Interner) {
let substs = match ty.kind(Interner) {
TyKind::Adt(_, substs) | TyKind::FnDef(_, substs) => substs.clone(),
TyKind::Error => {
return PatKind::Wild;

View file

@ -85,7 +85,7 @@ impl IntRange {
#[inline]
fn is_integral(ty: &Ty) -> bool {
matches!(
ty.kind(&Interner),
ty.kind(Interner),
TyKind::Scalar(Scalar::Char | Scalar::Int(_) | Scalar::Uint(_) | Scalar::Bool)
)
}
@ -479,7 +479,7 @@ impl SplitWildcard {
// returned list of constructors.
// Invariant: this is empty if and only if the type is uninhabited (as determined by
// `cx.is_uninhabited()`).
let all_ctors = match pcx.ty.kind(&Interner) {
let all_ctors = match pcx.ty.kind(Interner) {
TyKind::Scalar(Scalar::Bool) => smallvec![make_range(0, 1, Scalar::Bool)],
// TyKind::Array(..) if ... => unhandled(),
TyKind::Array(..) | TyKind::Slice(..) => unhandled(),
@ -647,16 +647,16 @@ impl Fields {
let wildcard_from_ty = |ty: &Ty| cx.alloc_pat(Pat::wildcard_from_ty(ty.clone()));
let ret = match constructor {
Single | Variant(_) => match ty.kind(&Interner) {
Single | Variant(_) => match ty.kind(Interner) {
TyKind::Tuple(_, substs) => {
let tys = substs.iter(&Interner).map(|ty| ty.assert_ty_ref(&Interner));
let tys = substs.iter(Interner).map(|ty| ty.assert_ty_ref(Interner));
Fields::wildcards_from_tys(cx, tys.cloned())
}
TyKind::Ref(.., rty) => Fields::from_single_pattern(wildcard_from_ty(rty)),
&TyKind::Adt(AdtId(adt), ref substs) => {
if adt_is_box(adt, cx) {
// Use T as the sub pattern type of Box<T>.
let subst_ty = substs.at(&Interner, 0).assert_ty_ref(&Interner);
let subst_ty = substs.at(Interner, 0).assert_ty_ref(Interner);
Fields::from_single_pattern(wildcard_from_ty(subst_ty))
} else {
let variant_id = constructor.variant_id_for_adt(adt);
@ -671,7 +671,7 @@ impl Fields {
let field_tys = || {
field_ty_data
.iter()
.map(|(_, binders)| binders.clone().substitute(&Interner, substs))
.map(|(_, binders)| binders.clone().substitute(Interner, substs))
};
// In the following cases, we don't need to filter out any fields. This is
@ -725,7 +725,7 @@ impl Fields {
const UNHANDLED: PatKind = PatKind::Wild;
let pat = match ctor {
Single | Variant(_) => match pcx.ty.kind(&Interner) {
Single | Variant(_) => match pcx.ty.kind(Interner) {
TyKind::Adt(..) | TyKind::Tuple(..) => {
// We want the real indices here.
let subpatterns = subpatterns_and_indices

View file

@ -347,7 +347,7 @@ struct LiteralExpander;
impl PatternFolder for LiteralExpander {
fn fold_pattern(&mut self, pat: &Pat) -> Pat {
match (pat.ty.kind(&Interner), pat.kind.as_ref()) {
match (pat.ty.kind(Interner), pat.kind.as_ref()) {
(_, PatKind::Binding { subpattern: Some(s), .. }) => s.fold_with(self),
_ => pat.super_fold_with(self),
}

View file

@ -82,7 +82,7 @@ fn walk_unsafe(
}
}
Expr::UnaryOp { expr, op: UnaryOp::Deref } => {
if let TyKind::Raw(..) = &infer[*expr].kind(&Interner) {
if let TyKind::Raw(..) = &infer[*expr].kind(Interner) {
unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block });
}
}

View file

@ -274,11 +274,11 @@ impl HirDisplay for ProjectionTy {
let trait_ = f.db.trait_data(self.trait_(f.db));
write!(f, "<")?;
self.self_type_parameter(&Interner).hir_fmt(f)?;
self.self_type_parameter(Interner).hir_fmt(f)?;
write!(f, " as {}", trait_.name)?;
if self.substitution.len(&Interner) > 1 {
if self.substitution.len(Interner) > 1 {
write!(f, "<")?;
f.write_joined(&self.substitution.as_slice(&Interner)[1..], ", ")?;
f.write_joined(&self.substitution.as_slice(Interner)[1..], ", ")?;
write!(f, ">")?;
}
write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty_id)).name)?;
@ -292,7 +292,7 @@ impl HirDisplay for OpaqueTy {
return write!(f, "{}", TYPE_HINT_TRUNCATION);
}
self.substitution.at(&Interner, 0).hir_fmt(f)
self.substitution.at(Interner, 0).hir_fmt(f)
}
}
@ -335,7 +335,7 @@ impl HirDisplay for Ty {
return write!(f, "{}", TYPE_HINT_TRUNCATION);
}
match self.kind(&Interner) {
match self.kind(Interner) {
TyKind::Never => write!(f, "!")?,
TyKind::Str => write!(f, "str")?,
TyKind::Scalar(Scalar::Bool) => write!(f, "bool")?,
@ -356,7 +356,7 @@ impl HirDisplay for Ty {
write!(f, "]")?;
}
TyKind::Raw(m, t) | TyKind::Ref(m, _, t) => {
if matches!(self.kind(&Interner), TyKind::Raw(..)) {
if matches!(self.kind(Interner), TyKind::Raw(..)) {
write!(
f,
"*{}",
@ -387,7 +387,7 @@ impl HirDisplay for Ty {
}
})
};
let (preds_to_print, has_impl_fn_pred) = match t.kind(&Interner) {
let (preds_to_print, has_impl_fn_pred) = match t.kind(Interner) {
TyKind::Dyn(dyn_ty) if dyn_ty.bounds.skip_binders().interned().len() > 1 => {
let bounds = dyn_ty.bounds.skip_binders().interned();
(bounds.len(), contains_impl_fn(bounds))
@ -406,7 +406,7 @@ impl HirDisplay for Ty {
let data = (*datas)
.as_ref()
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
let bounds = data.substitute(&Interner, parameters);
let bounds = data.substitute(Interner, parameters);
let mut len = bounds.skip_binders().len();
// Don't count Sized but count when it absent
@ -456,13 +456,13 @@ impl HirDisplay for Ty {
}
}
TyKind::Tuple(_, substs) => {
if substs.len(&Interner) == 1 {
if substs.len(Interner) == 1 {
write!(f, "(")?;
substs.at(&Interner, 0).hir_fmt(f)?;
substs.at(Interner, 0).hir_fmt(f)?;
write!(f, ",)")?;
} else {
write!(f, "(")?;
f.write_joined(&*substs.as_slice(&Interner), ", ")?;
f.write_joined(&*substs.as_slice(Interner), ", ")?;
write!(f, ")")?;
}
}
@ -472,7 +472,7 @@ impl HirDisplay for Ty {
}
TyKind::FnDef(def, parameters) => {
let def = from_chalk(f.db, *def);
let sig = f.db.callable_item_signature(def).substitute(&Interner, parameters);
let sig = f.db.callable_item_signature(def).substitute(Interner, parameters);
match def {
CallableDefId::FunctionId(ff) => {
write!(f, "fn {}", f.db.function_data(ff).name)?
@ -482,7 +482,7 @@ impl HirDisplay for Ty {
write!(f, "{}", f.db.enum_data(e.parent).variants[e.local_id].name)?
}
};
if parameters.len(&Interner) > 0 {
if parameters.len(Interner) > 0 {
let generics = generics(f.db.upcast(), def.into());
let (parent_params, self_param, type_params, _impl_trait_params) =
generics.provenance_split();
@ -490,7 +490,7 @@ impl HirDisplay for Ty {
// We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self?
if total_len > 0 {
write!(f, "<")?;
f.write_joined(&parameters.as_slice(&Interner)[..total_len], ", ")?;
f.write_joined(&parameters.as_slice(Interner)[..total_len], ", ")?;
write!(f, ">")?;
}
}
@ -528,7 +528,7 @@ impl HirDisplay for Ty {
}
}
if parameters.len(&Interner) > 0 {
if parameters.len(Interner) > 0 {
let parameters_to_write = if f.display_target.is_source_code()
|| f.omit_verbose_types()
{
@ -537,35 +537,33 @@ impl HirDisplay for Ty {
.map(|generic_def_id| f.db.generic_defaults(generic_def_id))
.filter(|defaults| !defaults.is_empty())
{
None => parameters.as_slice(&Interner),
None => parameters.as_slice(Interner),
Some(default_parameters) => {
let mut default_from = 0;
for (i, parameter) in parameters.iter(&Interner).enumerate() {
for (i, parameter) in parameters.iter(Interner).enumerate() {
match (
parameter.assert_ty_ref(&Interner).kind(&Interner),
parameter.assert_ty_ref(Interner).kind(Interner),
default_parameters.get(i),
) {
(&TyKind::Error, _) | (_, None) => {
default_from = i + 1;
}
(_, Some(default_parameter)) => {
let actual_default =
default_parameter.clone().substitute(
&Interner,
&subst_prefix(parameters, i),
);
if parameter.assert_ty_ref(&Interner) != &actual_default
let actual_default = default_parameter
.clone()
.substitute(Interner, &subst_prefix(parameters, i));
if parameter.assert_ty_ref(Interner) != &actual_default
{
default_from = i + 1;
}
}
}
}
&parameters.as_slice(&Interner)[0..default_from]
&parameters.as_slice(Interner)[0..default_from]
}
}
} else {
parameters.as_slice(&Interner)
parameters.as_slice(Interner)
};
if !parameters_to_write.is_empty() {
write!(f, "<")?;
@ -586,9 +584,9 @@ impl HirDisplay for Ty {
// Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types)
if f.display_target.is_test() {
write!(f, "{}::{}", trait_.name, type_alias_data.name)?;
if parameters.len(&Interner) > 0 {
if parameters.len(Interner) > 0 {
write!(f, "<")?;
f.write_joined(&*parameters.as_slice(&Interner), ", ")?;
f.write_joined(&*parameters.as_slice(Interner), ", ")?;
write!(f, ">")?;
}
} else {
@ -613,7 +611,7 @@ impl HirDisplay for Ty {
let data = (*datas)
.as_ref()
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
let bounds = data.substitute(&Interner, &parameters);
let bounds = data.substitute(Interner, &parameters);
let krate = func.lookup(f.db.upcast()).module(f.db.upcast()).krate();
write_bounds_like_dyn_trait_with_prefix(
"impl",
@ -625,7 +623,7 @@ impl HirDisplay for Ty {
}
ImplTraitId::AsyncBlockTypeImplTrait(..) => {
write!(f, "impl Future<Output = ")?;
parameters.at(&Interner, 0).hir_fmt(f)?;
parameters.at(Interner, 0).hir_fmt(f)?;
write!(f, ">")?;
}
}
@ -636,7 +634,7 @@ impl HirDisplay for Ty {
DisplaySourceCodeError::Closure,
));
}
let sig = substs.at(&Interner, 0).assert_ty_ref(&Interner).callable_sig(f.db);
let sig = substs.at(Interner, 0).assert_ty_ref(Interner).callable_sig(f.db);
if let Some(sig) = sig {
if sig.params().is_empty() {
write!(f, "||")?;
@ -667,15 +665,15 @@ impl HirDisplay for Ty {
let bounds =
f.db.generic_predicates(id.parent)
.iter()
.map(|pred| pred.clone().substitute(&Interner, &substs))
.map(|pred| pred.clone().substitute(Interner, &substs))
.filter(|wc| match &wc.skip_binders() {
WhereClause::Implemented(tr) => {
&tr.self_type_parameter(&Interner) == self
&tr.self_type_parameter(Interner) == self
}
WhereClause::AliasEq(AliasEq {
alias: AliasTy::Projection(proj),
ty: _,
}) => &proj.self_type_parameter(&Interner) == self,
}) => &proj.self_type_parameter(Interner) == self,
_ => false,
})
.collect::<Vec<_>>();
@ -708,7 +706,7 @@ impl HirDisplay for Ty {
let data = (*datas)
.as_ref()
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
let bounds = data.substitute(&Interner, &opaque_ty.substitution);
let bounds = data.substitute(Interner, &opaque_ty.substitution);
let krate = func.lookup(f.db.upcast()).module(f.db.upcast()).krate();
write_bounds_like_dyn_trait_with_prefix(
"impl",
@ -841,13 +839,13 @@ fn write_bounds_like_dyn_trait(
// existential) here, which is the only thing that's
// possible in actual Rust, and hence don't print it
write!(f, "{}", f.db.trait_data(trait_).name)?;
if let [_, params @ ..] = &*trait_ref.substitution.as_slice(&Interner) {
if let [_, params @ ..] = &*trait_ref.substitution.as_slice(Interner) {
if is_fn_trait {
if let Some(args) =
params.first().and_then(|it| it.assert_ty_ref(&Interner).as_tuple())
params.first().and_then(|it| it.assert_ty_ref(Interner).as_tuple())
{
write!(f, "(")?;
f.write_joined(args.as_slice(&Interner), ", ")?;
f.write_joined(args.as_slice(Interner), ", ")?;
write!(f, ")")?;
}
} else if !params.is_empty() {
@ -906,16 +904,16 @@ fn fmt_trait_ref(tr: &TraitRef, f: &mut HirFormatter, use_as: bool) -> Result<()
return write!(f, "{}", TYPE_HINT_TRUNCATION);
}
tr.self_type_parameter(&Interner).hir_fmt(f)?;
tr.self_type_parameter(Interner).hir_fmt(f)?;
if use_as {
write!(f, " as ")?;
} else {
write!(f, ": ")?;
}
write!(f, "{}", f.db.trait_data(tr.hir_trait_id()).name)?;
if tr.substitution.len(&Interner) > 1 {
if tr.substitution.len(Interner) > 1 {
write!(f, "<")?;
f.write_joined(&tr.substitution.as_slice(&Interner)[1..], ", ")?;
f.write_joined(&tr.substitution.as_slice(Interner)[1..], ", ")?;
write!(f, ">")?;
}
Ok(())

View file

@ -140,9 +140,9 @@ struct InternedStandardTypes {
impl Default for InternedStandardTypes {
fn default() -> Self {
InternedStandardTypes {
unknown: TyKind::Error.intern(&Interner),
bool_: TyKind::Scalar(Scalar::Bool).intern(&Interner),
unit: TyKind::Tuple(0, Substitution::empty(&Interner)).intern(&Interner),
unknown: TyKind::Error.intern(Interner),
bool_: TyKind::Scalar(Scalar::Bool).intern(Interner),
unit: TyKind::Tuple(0, Substitution::empty(Interner)).intern(Interner),
}
}
}
@ -378,7 +378,7 @@ impl<'a> InferenceContext<'a> {
result: InferenceResult::default(),
table: unify::InferenceTable::new(db, trait_env.clone()),
trait_env,
return_ty: TyKind::Error.intern(&Interner), // set in collect_fn_signature
return_ty: TyKind::Error.intern(Interner), // set in collect_fn_signature
db,
owner,
body: db.body(owner),
@ -472,7 +472,7 @@ impl<'a> InferenceContext<'a> {
/// Replaces Ty::Unknown by a new type var, so we can maybe still infer it.
fn insert_type_vars_shallow(&mut self, ty: Ty) -> Ty {
match ty.kind(&Interner) {
match ty.kind(Interner) {
TyKind::Error => self.table.new_type_var(),
TyKind::InferenceVar(..) => {
let ty_resolved = self.resolve_ty_shallow(&ty);
@ -495,7 +495,7 @@ impl<'a> InferenceContext<'a> {
}
fn push_obligation(&mut self, o: DomainGoal) {
self.table.register_obligation(o.cast(&Interner));
self.table.register_obligation(o.cast(Interner));
}
fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool {
@ -535,8 +535,8 @@ impl<'a> InferenceContext<'a> {
}),
ty: ty.clone(),
};
self.push_obligation(trait_ref.cast(&Interner));
self.push_obligation(alias_eq.cast(&Interner));
self.push_obligation(trait_ref.cast(Interner));
self.push_obligation(alias_eq.cast(Interner));
ty
}
None => self.err_ty(),
@ -568,13 +568,13 @@ impl<'a> InferenceContext<'a> {
ValueNs::EnumVariantId(var) => {
let substs = ctx.substs_from_path(path, var.into(), true);
let ty = self.db.ty(var.parent.into());
let ty = self.insert_type_vars(ty.substitute(&Interner, &substs));
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
return (ty, Some(var.into()));
}
ValueNs::StructId(strukt) => {
let substs = ctx.substs_from_path(path, strukt.into(), true);
let ty = self.db.ty(strukt.into());
let ty = self.insert_type_vars(ty.substitute(&Interner, &substs));
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
return (ty, Some(strukt.into()));
}
_ => return (self.err_ty(), None),
@ -592,25 +592,25 @@ impl<'a> InferenceContext<'a> {
TypeNs::AdtId(AdtId::StructId(strukt)) => {
let substs = ctx.substs_from_path(path, strukt.into(), true);
let ty = self.db.ty(strukt.into());
let ty = self.insert_type_vars(ty.substitute(&Interner, &substs));
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
forbid_unresolved_segments((ty, Some(strukt.into())), unresolved)
}
TypeNs::AdtId(AdtId::UnionId(u)) => {
let substs = ctx.substs_from_path(path, u.into(), true);
let ty = self.db.ty(u.into());
let ty = self.insert_type_vars(ty.substitute(&Interner, &substs));
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
forbid_unresolved_segments((ty, Some(u.into())), unresolved)
}
TypeNs::EnumVariantId(var) => {
let substs = ctx.substs_from_path(path, var.into(), true);
let ty = self.db.ty(var.parent.into());
let ty = self.insert_type_vars(ty.substitute(&Interner, &substs));
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
forbid_unresolved_segments((ty, Some(var.into())), unresolved)
}
TypeNs::SelfType(impl_id) => {
let generics = crate::utils::generics(self.db.upcast(), impl_id.into());
let substs = generics.type_params_subst(self.db);
let ty = self.db.impl_self_ty(impl_id).substitute(&Interner, &substs);
let ty = self.db.impl_self_ty(impl_id).substitute(Interner, &substs);
self.resolve_variant_on_alias(ty, unresolved, path)
}
TypeNs::TypeAliasId(it) => {
@ -641,7 +641,7 @@ impl<'a> InferenceContext<'a> {
result
} else {
// FIXME diagnostic
(TyKind::Error.intern(&Interner), None)
(TyKind::Error.intern(Interner), None)
}
}
}
@ -854,7 +854,7 @@ impl Expectation {
/// for examples of where this comes up,.
fn rvalue_hint(table: &mut unify::InferenceTable, ty: Ty) -> Self {
// FIXME: do struct_tail_without_normalization
match table.resolve_ty_shallow(&ty).kind(&Interner) {
match table.resolve_ty_shallow(&ty).kind(Interner) {
TyKind::Slice(_) | TyKind::Str | TyKind::Dyn(_) => Expectation::RValueLikeUnsized(ty),
_ => Expectation::has_type(ty),
}

View file

@ -28,9 +28,9 @@ impl InferenceContext<'_> {
let _ = self.coerce(Some(closure_expr), closure_ty, &expected_ty);
// Deduction based on the expected `dyn Fn` is done separately.
if let TyKind::Dyn(dyn_ty) = expected_ty.kind(&Interner) {
if let TyKind::Dyn(dyn_ty) = expected_ty.kind(Interner) {
if let Some(sig) = self.deduce_sig_from_dyn_ty(dyn_ty) {
let expected_sig_ty = TyKind::Function(sig).intern(&Interner);
let expected_sig_ty = TyKind::Function(sig).intern(Interner);
self.unify(sig_ty, &expected_sig_ty);
}
@ -45,9 +45,9 @@ impl InferenceContext<'_> {
.map(to_chalk_trait_id)
.collect();
let self_ty = TyKind::Error.intern(&Interner);
let bounds = dyn_ty.bounds.clone().substitute(&Interner, &[self_ty.cast(&Interner)]);
for bound in bounds.iter(&Interner) {
let self_ty = TyKind::Error.intern(Interner);
let bounds = dyn_ty.bounds.clone().substitute(Interner, &[self_ty.cast(Interner)]);
for bound in bounds.iter(Interner) {
// NOTE(skip_binders): the extracted types are rebound by the returned `FnPointer`
if let WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection), ty }) =
bound.skip_binders()
@ -58,20 +58,20 @@ impl InferenceContext<'_> {
}
// Skip `Self`, get the type argument.
let arg = projection.substitution.as_slice(&Interner).get(1)?;
if let Some(subst) = arg.ty(&Interner)?.as_tuple() {
let generic_args = subst.as_slice(&Interner);
let arg = projection.substitution.as_slice(Interner).get(1)?;
if let Some(subst) = arg.ty(Interner)?.as_tuple() {
let generic_args = subst.as_slice(Interner);
let mut sig_tys = Vec::new();
for arg in generic_args {
sig_tys.push(arg.ty(&Interner)?.clone());
sig_tys.push(arg.ty(Interner)?.clone());
}
sig_tys.push(ty.clone());
cov_mark::hit!(dyn_fn_param_informs_call_site_closure_signature);
return Some(FnPointer {
num_binders: bound.len(&Interner),
num_binders: bound.len(Interner),
sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false },
substitution: FnSubst(Substitution::from_iter(&Interner, sig_tys)),
substitution: FnSubst(Substitution::from_iter(Interner, sig_tys)),
});
}
}

View file

@ -71,7 +71,7 @@ impl CoerceMany {
// Special case: two function types. Try to coerce both to
// pointers to have a chance at getting a match. See
// https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916
let sig = match (self.expected_ty.kind(&Interner), expr_ty.kind(&Interner)) {
let sig = match (self.expected_ty.kind(Interner), expr_ty.kind(Interner)) {
(TyKind::FnDef(..) | TyKind::Closure(..), TyKind::FnDef(..) | TyKind::Closure(..)) => {
// FIXME: we're ignoring safety here. To be more correct, if we have one FnDef and one Closure,
// we should be coercing the closure to a fn pointer of the safety of the FnDef
@ -83,7 +83,7 @@ impl CoerceMany {
_ => None,
};
if let Some(sig) = sig {
let target_ty = TyKind::Function(sig.to_fn_ptr()).intern(&Interner);
let target_ty = TyKind::Function(sig.to_fn_ptr()).intern(Interner);
let result1 = ctx.coerce_inner(self.expected_ty.clone(), &target_ty);
let result2 = ctx.coerce_inner(expr_ty.clone(), &target_ty);
if let (Ok(result1), Ok(result2)) = (result1, result2) {
@ -153,7 +153,7 @@ impl<'a> InferenceContext<'a> {
// let _: Option<?T> = Some({ return; });
//
// here, we would coerce from `!` to `?T`.
if let TyKind::InferenceVar(tv, TyVariableKind::General) = to_ty.kind(&Interner) {
if let TyKind::InferenceVar(tv, TyVariableKind::General) = to_ty.kind(Interner) {
self.table.set_diverging(*tv, true);
}
return success(simple(Adjust::NeverToAny)(to_ty.clone()), to_ty.clone(), vec![]);
@ -165,13 +165,13 @@ impl<'a> InferenceContext<'a> {
}
// Examine the supertype and consider auto-borrowing.
match to_ty.kind(&Interner) {
match to_ty.kind(Interner) {
TyKind::Raw(mt, _) => return self.coerce_ptr(from_ty, to_ty, *mt),
TyKind::Ref(mt, _, _) => return self.coerce_ref(from_ty, to_ty, *mt),
_ => {}
}
match from_ty.kind(&Interner) {
match from_ty.kind(Interner) {
TyKind::FnDef(..) => {
// Function items are coercible to any closure
// type; function pointers are not (that would
@ -209,7 +209,7 @@ impl<'a> InferenceContext<'a> {
}
fn coerce_ptr(&mut self, from_ty: Ty, to_ty: &Ty, to_mt: Mutability) -> CoerceResult {
let (is_ref, from_mt, from_inner) = match from_ty.kind(&Interner) {
let (is_ref, from_mt, from_inner) = match from_ty.kind(Interner) {
TyKind::Ref(mt, _, ty) => (true, mt, ty),
TyKind::Raw(mt, ty) => (false, mt, ty),
_ => return self.unify_and(&from_ty, to_ty, identity),
@ -218,7 +218,7 @@ impl<'a> InferenceContext<'a> {
coerce_mutabilities(*from_mt, to_mt)?;
// Check that the types which they point at are compatible.
let from_raw = TyKind::Raw(to_mt, from_inner.clone()).intern(&Interner);
let from_raw = TyKind::Raw(to_mt, from_inner.clone()).intern(Interner);
// Although references and unsafe ptrs have the same
// representation, we still register an Adjust::DerefRef so that
@ -245,7 +245,7 @@ impl<'a> InferenceContext<'a> {
/// To match `A` with `B`, autoderef will be performed,
/// calling `deref`/`deref_mut` where necessary.
fn coerce_ref(&mut self, from_ty: Ty, to_ty: &Ty, to_mt: Mutability) -> CoerceResult {
let from_mt = match from_ty.kind(&Interner) {
let from_mt = match from_ty.kind(Interner) {
&TyKind::Ref(mt, _, _) => {
coerce_mutabilities(mt, to_mt)?;
mt
@ -303,7 +303,7 @@ impl<'a> InferenceContext<'a> {
// mutability [1], since it may be that we are coercing
// from `&mut T` to `&U`.
let lt = static_lifetime(); // FIXME: handle lifetimes correctly, see rustc
let derefd_from_ty = TyKind::Ref(to_mt, lt, referent_ty).intern(&Interner);
let derefd_from_ty = TyKind::Ref(to_mt, lt, referent_ty).intern(Interner);
match self.table.try_unify(&derefd_from_ty, to_ty) {
Ok(result) => {
found = Some(result.map(|()| derefd_from_ty));
@ -370,7 +370,7 @@ impl<'a> InferenceContext<'a> {
/// Attempts to coerce from the type of a Rust function item into a function pointer.
fn coerce_from_fn_item(&mut self, from_ty: Ty, to_ty: &Ty) -> CoerceResult {
match to_ty.kind(&Interner) {
match to_ty.kind(Interner) {
TyKind::Function(_) => {
let from_sig = from_ty.callable_sig(self.db).expect("FnDef had no sig");
@ -380,7 +380,7 @@ impl<'a> InferenceContext<'a> {
// FIXME rustc normalizes assoc types in the sig here, not sure if necessary
let from_sig = from_sig.to_fn_ptr();
let from_fn_pointer = TyKind::Function(from_sig.clone()).intern(&Interner);
let from_fn_pointer = TyKind::Function(from_sig.clone()).intern(Interner);
let ok = self.coerce_from_safe_fn(
from_fn_pointer.clone(),
&from_sig,
@ -433,12 +433,12 @@ impl<'a> InferenceContext<'a> {
F: FnOnce(Ty) -> Vec<Adjustment>,
G: FnOnce(Ty) -> Vec<Adjustment>,
{
if let TyKind::Function(to_fn_ptr) = to_ty.kind(&Interner) {
if let TyKind::Function(to_fn_ptr) = to_ty.kind(Interner) {
if let (chalk_ir::Safety::Safe, chalk_ir::Safety::Unsafe) =
(from_fn_ptr.sig.safety, to_fn_ptr.sig.safety)
{
let from_unsafe =
TyKind::Function(safe_to_unsafe_fn_ty(from_fn_ptr.clone())).intern(&Interner);
TyKind::Function(safe_to_unsafe_fn_ty(from_fn_ptr.clone())).intern(Interner);
return self.unify_and(&from_unsafe, to_ty, to_unsafe);
}
}
@ -453,7 +453,7 @@ impl<'a> InferenceContext<'a> {
from_substs: &Substitution,
to_ty: &Ty,
) -> CoerceResult {
match to_ty.kind(&Interner) {
match to_ty.kind(Interner) {
// if from_substs is non-capturing (FIXME)
TyKind::Function(fn_ty) => {
// We coerce the closure, which has fn type
@ -507,7 +507,7 @@ impl<'a> InferenceContext<'a> {
}
// Handle reborrows before trying to solve `Source: CoerceUnsized<Target>`.
let reborrow = match (from_ty.kind(&Interner), to_ty.kind(&Interner)) {
let reborrow = match (from_ty.kind(Interner), to_ty.kind(Interner)) {
(TyKind::Ref(from_mt, _, from_inner), &TyKind::Ref(to_mt, _, _)) => {
coerce_mutabilities(*from_mt, to_mt)?;
@ -516,7 +516,7 @@ impl<'a> InferenceContext<'a> {
Adjustment { kind: Adjust::Deref(None), target: from_inner.clone() },
Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(to_mt)),
target: TyKind::Ref(to_mt, lt, from_inner.clone()).intern(&Interner),
target: TyKind::Ref(to_mt, lt, from_inner.clone()).intern(Interner),
},
))
}
@ -527,7 +527,7 @@ impl<'a> InferenceContext<'a> {
Adjustment { kind: Adjust::Deref(None), target: from_inner.clone() },
Adjustment {
kind: Adjust::Borrow(AutoBorrow::RawPtr(to_mt)),
target: TyKind::Raw(to_mt, from_inner.clone()).intern(&Interner),
target: TyKind::Raw(to_mt, from_inner.clone()).intern(Interner),
},
))
}
@ -553,7 +553,7 @@ impl<'a> InferenceContext<'a> {
};
let goal: InEnvironment<DomainGoal> =
InEnvironment::new(&self.trait_env.env, coerce_unsized_tref.cast(&Interner));
InEnvironment::new(&self.trait_env.env, coerce_unsized_tref.cast(Interner));
let canonicalized = self.canonicalize(goal);
@ -563,7 +563,7 @@ impl<'a> InferenceContext<'a> {
// Need to find out in what cases this is necessary
let solution = self
.db
.trait_solve(krate, canonicalized.value.clone().cast(&Interner))
.trait_solve(krate, canonicalized.value.clone().cast(Interner))
.ok_or(TypeError)?;
match solution {
@ -593,15 +593,15 @@ impl<'a> InferenceContext<'a> {
}
fn coerce_closure_fn_ty(closure_substs: &Substitution, safety: chalk_ir::Safety) -> Ty {
let closure_sig = closure_substs.at(&Interner, 0).assert_ty_ref(&Interner).clone();
match closure_sig.kind(&Interner) {
let closure_sig = closure_substs.at(Interner, 0).assert_ty_ref(Interner).clone();
match closure_sig.kind(Interner) {
TyKind::Function(fn_ty) => TyKind::Function(FnPointer {
num_binders: fn_ty.num_binders,
sig: FnSig { safety, ..fn_ty.sig },
substitution: fn_ty.substitution.clone(),
})
.intern(&Interner),
_ => TyKind::Error.intern(&Interner),
.intern(Interner),
_ => TyKind::Error.intern(Interner),
}
}

View file

@ -105,11 +105,11 @@ impl<'a> InferenceContext<'a> {
let trait_env = self.trait_env.env.clone();
let obligation = InEnvironment {
goal: projection.trait_ref(self.db).cast(&Interner),
goal: projection.trait_ref(self.db).cast(Interner),
environment: trait_env,
};
let canonical = self.canonicalize(obligation.clone());
if self.db.trait_solve(krate, canonical.value.cast(&Interner)).is_some() {
if self.db.trait_solve(krate, canonical.value.cast(Interner)).is_some() {
self.push_obligation(obligation.goal);
let return_ty = self.table.normalize_projection_ty(projection);
Some((arg_tys, return_ty))
@ -135,7 +135,7 @@ impl<'a> InferenceContext<'a> {
// if let is desugared to match, so this is always simple if
self.infer_expr(
condition,
&Expectation::has_type(TyKind::Scalar(Scalar::Bool).intern(&Interner)),
&Expectation::has_type(TyKind::Scalar(Scalar::Bool).intern(Interner)),
);
let condition_diverges = mem::replace(&mut self.diverges, Diverges::Maybe);
@ -201,8 +201,8 @@ impl<'a> InferenceContext<'a> {
let inner_ty = self.infer_expr(*body, &Expectation::none());
let impl_trait_id = crate::ImplTraitId::AsyncBlockTypeImplTrait(self.owner, *body);
let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into();
TyKind::OpaqueType(opaque_ty_id, Substitution::from1(&Interner, inner_ty))
.intern(&Interner)
TyKind::OpaqueType(opaque_ty_id, Substitution::from1(Interner, inner_ty))
.intern(Interner)
}
Expr::Loop { body, label } => {
self.breakables.push(BreakableContext {
@ -218,7 +218,7 @@ impl<'a> InferenceContext<'a> {
self.diverges = Diverges::Maybe;
ctxt.coerce.complete()
} else {
TyKind::Never.intern(&Interner)
TyKind::Never.intern(Interner)
}
}
Expr::While { condition, body, label } => {
@ -230,7 +230,7 @@ impl<'a> InferenceContext<'a> {
// while let is desugared to a match loop, so this is always simple while
self.infer_expr(
*condition,
&Expectation::has_type(TyKind::Scalar(Scalar::Bool).intern(&Interner)),
&Expectation::has_type(TyKind::Scalar(Scalar::Bool).intern(Interner)),
);
self.infer_expr(*body, &Expectation::has_type(TyBuilder::unit()));
let _ctxt = self.breakables.pop().expect("breakable stack broken");
@ -281,14 +281,14 @@ impl<'a> InferenceContext<'a> {
num_binders: 0,
sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false },
substitution: FnSubst(
Substitution::from_iter(&Interner, sig_tys.clone()).shifted_in(&Interner),
Substitution::from_iter(Interner, sig_tys.clone()).shifted_in(Interner),
),
})
.intern(&Interner);
.intern(Interner);
let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
let closure_ty =
TyKind::Closure(closure_id, Substitution::from1(&Interner, sig_ty.clone()))
.intern(&Interner);
TyKind::Closure(closure_id, Substitution::from1(Interner, sig_ty.clone()))
.intern(Interner);
// Eagerly try to relate the closure type with the expected
// type, otherwise we often won't have enough information to
@ -363,7 +363,7 @@ impl<'a> InferenceContext<'a> {
let expected = expected.adjust_for_branches(&mut self.table);
let result_ty = if arms.is_empty() {
TyKind::Never.intern(&Interner)
TyKind::Never.intern(Interner)
} else {
match &expected {
Expectation::HasType(ty) => ty.clone(),
@ -383,7 +383,7 @@ impl<'a> InferenceContext<'a> {
self.infer_expr(
guard_expr,
&Expectation::has_type(
TyKind::Scalar(Scalar::Bool).intern(&Interner),
TyKind::Scalar(Scalar::Bool).intern(Interner),
),
);
}
@ -408,7 +408,7 @@ impl<'a> InferenceContext<'a> {
let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr);
self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or_else(|| self.err_ty())
}
Expr::Continue { .. } => TyKind::Never.intern(&Interner),
Expr::Continue { .. } => TyKind::Never.intern(Interner),
Expr::Break { expr, label } => {
let mut coerce = match find_breakable(&mut self.breakables, label.as_ref()) {
Some(ctxt) => {
@ -439,7 +439,7 @@ impl<'a> InferenceContext<'a> {
});
};
TyKind::Never.intern(&Interner)
TyKind::Never.intern(Interner)
}
Expr::Return { expr } => {
if let Some(expr) = expr {
@ -448,14 +448,14 @@ impl<'a> InferenceContext<'a> {
let unit = TyBuilder::unit();
let _ = self.coerce(Some(tgt_expr), &unit, &self.return_ty.clone());
}
TyKind::Never.intern(&Interner)
TyKind::Never.intern(Interner)
}
Expr::Yield { expr } => {
// FIXME: track yield type for coercion
if let Some(expr) = expr {
self.infer_expr(*expr, &Expectation::none());
}
TyKind::Never.intern(&Interner)
TyKind::Never.intern(Interner)
}
Expr::RecordLit { path, fields, spread } => {
let (ty, def_id) = self.resolve_variant(path.as_deref(), false);
@ -470,7 +470,7 @@ impl<'a> InferenceContext<'a> {
let substs = ty
.as_adt()
.map(|(_, s)| s.clone())
.unwrap_or_else(|| Substitution::empty(&Interner));
.unwrap_or_else(|| Substitution::empty(Interner));
let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default();
let variant_data = def_id.map(|it| it.variant_data(self.db.upcast()));
for field in fields.iter() {
@ -485,7 +485,7 @@ impl<'a> InferenceContext<'a> {
}
});
let field_ty = field_def.map_or(self.err_ty(), |it| {
field_types[it.local_id].clone().substitute(&Interner, &substs)
field_types[it.local_id].clone().substitute(Interner, &substs)
});
self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty));
}
@ -519,13 +519,13 @@ impl<'a> InferenceContext<'a> {
};
match canonicalized
.decanonicalize_ty(&mut self.table, derefed_ty)
.kind(&Interner)
.kind(Interner)
{
TyKind::Tuple(_, substs) => name.as_tuple_index().and_then(|idx| {
substs
.as_slice(&Interner)
.as_slice(Interner)
.get(idx)
.map(|a| a.assert_ty_ref(&Interner))
.map(|a| a.assert_ty_ref(Interner))
.cloned()
}),
TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => {
@ -536,7 +536,7 @@ impl<'a> InferenceContext<'a> {
Some(
self.db.field_types((*s).into())[field.local_id]
.clone()
.substitute(&Interner, &parameters),
.substitute(Interner, &parameters),
)
} else {
None
@ -550,7 +550,7 @@ impl<'a> InferenceContext<'a> {
Some(
self.db.field_types((*u).into())[field.local_id]
.clone()
.substitute(&Interner, &parameters),
.substitute(Interner, &parameters),
)
} else {
None
@ -608,7 +608,7 @@ impl<'a> InferenceContext<'a> {
Rawness::RawPtr => TyKind::Raw(mutability, inner_ty),
Rawness::Ref => TyKind::Ref(mutability, static_lifetime(), inner_ty),
}
.intern(&Interner)
.intern(Interner)
}
Expr::Box { expr } => {
let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
@ -645,7 +645,7 @@ impl<'a> InferenceContext<'a> {
None => self.err_ty(),
},
UnaryOp::Neg => {
match inner_ty.kind(&Interner) {
match inner_ty.kind(Interner) {
// Fast path for builtins
TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_) | Scalar::Float(_))
| TyKind::InferenceVar(
@ -658,7 +658,7 @@ impl<'a> InferenceContext<'a> {
}
}
UnaryOp::Not => {
match inner_ty.kind(&Interner) {
match inner_ty.kind(Interner) {
// Fast path for builtins
TyKind::Scalar(Scalar::Bool | Scalar::Int(_) | Scalar::Uint(_))
| TyKind::InferenceVar(_, TyVariableKind::Integer) => inner_ty,
@ -756,11 +756,11 @@ impl<'a> InferenceContext<'a> {
let mut tys = match expected
.only_has_type(&mut self.table)
.as_ref()
.map(|t| t.kind(&Interner))
.map(|t| t.kind(Interner))
{
Some(TyKind::Tuple(_, substs)) => substs
.iter(&Interner)
.map(|a| a.assert_ty_ref(&Interner).clone())
.iter(Interner)
.map(|a| a.assert_ty_ref(Interner).clone())
.chain(repeat_with(|| self.table.new_type_var()))
.take(exprs.len())
.collect::<Vec<_>>(),
@ -771,11 +771,11 @@ impl<'a> InferenceContext<'a> {
self.infer_expr_coerce(*expr, &Expectation::has_type(ty.clone()));
}
TyKind::Tuple(tys.len(), Substitution::from_iter(&Interner, tys)).intern(&Interner)
TyKind::Tuple(tys.len(), Substitution::from_iter(Interner, tys)).intern(Interner)
}
Expr::Array(array) => {
let elem_ty =
match expected.to_option(&mut self.table).as_ref().map(|t| t.kind(&Interner)) {
match expected.to_option(&mut self.table).as_ref().map(|t| t.kind(Interner)) {
Some(TyKind::Array(st, _) | TyKind::Slice(st)) => st.clone(),
_ => self.table.new_type_var(),
};
@ -795,7 +795,7 @@ impl<'a> InferenceContext<'a> {
self.infer_expr(
repeat,
&Expectation::has_type(
TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner),
TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(Interner),
),
);
@ -804,41 +804,41 @@ impl<'a> InferenceContext<'a> {
}
};
TyKind::Array(coerce.complete(), consteval::usize_const(len)).intern(&Interner)
TyKind::Array(coerce.complete(), consteval::usize_const(len)).intern(Interner)
}
Expr::Literal(lit) => match lit {
Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner),
Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(Interner),
Literal::String(..) => {
TyKind::Ref(Mutability::Not, static_lifetime(), TyKind::Str.intern(&Interner))
.intern(&Interner)
TyKind::Ref(Mutability::Not, static_lifetime(), TyKind::Str.intern(Interner))
.intern(Interner)
}
Literal::ByteString(bs) => {
let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner);
let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(Interner);
let len = consteval::usize_const(Some(bs.len() as u64));
let array_type = TyKind::Array(byte_type, len).intern(&Interner);
TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner)
let array_type = TyKind::Array(byte_type, len).intern(Interner);
TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(Interner)
}
Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner),
Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(Interner),
Literal::Int(_v, ty) => match ty {
Some(int_ty) => {
TyKind::Scalar(Scalar::Int(primitive::int_ty_from_builtin(*int_ty)))
.intern(&Interner)
.intern(Interner)
}
None => self.table.new_integer_var(),
},
Literal::Uint(_v, ty) => match ty {
Some(int_ty) => {
TyKind::Scalar(Scalar::Uint(primitive::uint_ty_from_builtin(*int_ty)))
.intern(&Interner)
.intern(Interner)
}
None => self.table.new_integer_var(),
},
Literal::Float(_v, ty) => match ty {
Some(float_ty) => {
TyKind::Scalar(Scalar::Float(primitive::float_ty_from_builtin(*float_ty)))
.intern(&Interner)
.intern(Interner)
}
None => self.table.new_float_var(),
},
@ -880,7 +880,7 @@ impl<'a> InferenceContext<'a> {
.build();
self.write_method_resolution(tgt_expr, func, subst.clone());
let method_ty = self.db.value_ty(func.into()).substitute(&Interner, &subst);
let method_ty = self.db.value_ty(func.into()).substitute(Interner, &subst);
self.register_obligations_for_call(&method_ty);
self.infer_expr_coerce(rhs, &Expectation::has_type(rhs_ty.clone()));
@ -934,7 +934,7 @@ impl<'a> InferenceContext<'a> {
if let Some(expr) = else_branch {
self.infer_expr_coerce(
*expr,
&Expectation::has_type(Ty::new(&Interner, TyKind::Never)),
&Expectation::has_type(Ty::new(Interner, TyKind::Never)),
);
}
@ -1003,11 +1003,11 @@ impl<'a> InferenceContext<'a> {
}
None => (
receiver_ty,
Binders::empty(&Interner, self.err_ty()),
Substitution::empty(&Interner),
Binders::empty(Interner, self.err_ty()),
Substitution::empty(Interner),
),
};
let method_ty = method_ty.substitute(&Interner, &substs);
let method_ty = method_ty.substitute(Interner, &substs);
self.register_obligations_for_call(&method_ty);
let (formal_receiver_ty, param_tys, ret_ty) = match method_ty.callable_sig(self.db) {
Some(sig) => {
@ -1038,12 +1038,12 @@ impl<'a> InferenceContext<'a> {
self.table.fudge_inference(|table| {
if table.try_unify(&expected_ty, &output).is_ok() {
table.resolve_with_fallback(inputs, &|var, kind, _, _| match kind {
chalk_ir::VariableKind::Ty(tk) => var.to_ty(&Interner, tk).cast(&Interner),
chalk_ir::VariableKind::Ty(tk) => var.to_ty(Interner, tk).cast(Interner),
chalk_ir::VariableKind::Lifetime => {
var.to_lifetime(&Interner).cast(&Interner)
var.to_lifetime(Interner).cast(Interner)
}
chalk_ir::VariableKind::Const(ty) => {
var.to_const(&Interner, ty).cast(&Interner)
var.to_const(Interner, ty).cast(Interner)
}
})
} else {
@ -1148,21 +1148,21 @@ impl<'a> InferenceContext<'a> {
substs.push(self.table.new_type_var());
}
assert_eq!(substs.len(), total_len);
Substitution::from_iter(&Interner, substs)
Substitution::from_iter(Interner, substs)
}
fn register_obligations_for_call(&mut self, callable_ty: &Ty) {
let callable_ty = self.resolve_ty_shallow(callable_ty);
if let TyKind::FnDef(fn_def, parameters) = callable_ty.kind(&Interner) {
if let TyKind::FnDef(fn_def, parameters) = callable_ty.kind(Interner) {
let def: CallableDefId = from_chalk(self.db, *fn_def);
let generic_predicates = self.db.generic_predicates(def.into());
for predicate in generic_predicates.iter() {
let (predicate, binders) = predicate
.clone()
.substitute(&Interner, parameters)
.substitute(Interner, parameters)
.into_value_and_skipped_binders();
always!(binders.len(&Interner) == 0); // quantified where clauses not yet handled
self.push_obligation(predicate.cast(&Interner));
always!(binders.len(Interner) == 0); // quantified where clauses not yet handled
self.push_obligation(predicate.cast(Interner));
}
// add obligation for trait implementation, if this is a trait method
match def {
@ -1175,7 +1175,7 @@ impl<'a> InferenceContext<'a> {
);
self.push_obligation(
TraitRef { trait_id: to_chalk_trait_id(trait_), substitution: substs }
.cast(&Interner),
.cast(Interner),
);
}
}
@ -1189,17 +1189,17 @@ impl<'a> InferenceContext<'a> {
let rhs_ty = self.resolve_ty_shallow(&rhs_ty);
match op {
BinaryOp::LogicOp(_) | BinaryOp::CmpOp(_) => {
Some(TyKind::Scalar(Scalar::Bool).intern(&Interner))
Some(TyKind::Scalar(Scalar::Bool).intern(Interner))
}
BinaryOp::Assignment { .. } => Some(TyBuilder::unit()),
BinaryOp::ArithOp(ArithOp::Shl | ArithOp::Shr) => {
// all integer combinations are valid here
if matches!(
lhs_ty.kind(&Interner),
lhs_ty.kind(Interner),
TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_))
| TyKind::InferenceVar(_, TyVariableKind::Integer)
) && matches!(
rhs_ty.kind(&Interner),
rhs_ty.kind(Interner),
TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_))
| TyKind::InferenceVar(_, TyVariableKind::Integer)
) {
@ -1208,7 +1208,7 @@ impl<'a> InferenceContext<'a> {
None
}
}
BinaryOp::ArithOp(_) => match (lhs_ty.kind(&Interner), rhs_ty.kind(&Interner)) {
BinaryOp::ArithOp(_) => match (lhs_ty.kind(Interner), rhs_ty.kind(Interner)) {
// (int, int) | (uint, uint) | (float, float)
(TyKind::Scalar(Scalar::Int(_)), TyKind::Scalar(Scalar::Int(_)))
| (TyKind::Scalar(Scalar::Uint(_)), TyKind::Scalar(Scalar::Uint(_)))
@ -1251,11 +1251,11 @@ impl<'a> InferenceContext<'a> {
fn builtin_binary_op_rhs_expectation(&mut self, op: BinaryOp, lhs_ty: Ty) -> Option<Ty> {
Some(match op {
BinaryOp::LogicOp(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner),
BinaryOp::LogicOp(..) => TyKind::Scalar(Scalar::Bool).intern(Interner),
BinaryOp::Assignment { op: None } => lhs_ty,
BinaryOp::CmpOp(CmpOp::Eq { .. }) => match self
.resolve_ty_shallow(&lhs_ty)
.kind(&Interner)
.kind(Interner)
{
TyKind::Scalar(_) | TyKind::Str => lhs_ty,
TyKind::InferenceVar(_, TyVariableKind::Integer | TyVariableKind::Float) => lhs_ty,
@ -1264,7 +1264,7 @@ impl<'a> InferenceContext<'a> {
BinaryOp::ArithOp(ArithOp::Shl | ArithOp::Shr) => return None,
BinaryOp::CmpOp(CmpOp::Ord { .. })
| BinaryOp::Assignment { op: Some(_) }
| BinaryOp::ArithOp(_) => match self.resolve_ty_shallow(&lhs_ty).kind(&Interner) {
| BinaryOp::ArithOp(_) => match self.resolve_ty_shallow(&lhs_ty).kind(Interner) {
TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_) | Scalar::Float(_)) => lhs_ty,
TyKind::InferenceVar(_, TyVariableKind::Integer | TyVariableKind::Float) => lhs_ty,
_ => return None,

View file

@ -35,7 +35,7 @@ impl<'a> InferenceContext<'a> {
self.unify(&ty, expected);
let substs =
ty.as_adt().map(|(_, s)| s.clone()).unwrap_or_else(|| Substitution::empty(&Interner));
ty.as_adt().map(|(_, s)| s.clone()).unwrap_or_else(|| Substitution::empty(Interner));
let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default();
let (pre, post) = match ellipsis {
@ -51,7 +51,7 @@ impl<'a> InferenceContext<'a> {
.as_ref()
.and_then(|d| d.field(&Name::new_tuple_field(i)))
.map_or(self.err_ty(), |field| {
field_tys[field].clone().substitute(&Interner, &substs)
field_tys[field].clone().substitute(Interner, &substs)
});
let expected_ty = self.normalize_associated_types_in(expected_ty);
self.infer_pat(subpat, &expected_ty, default_bm);
@ -77,13 +77,13 @@ impl<'a> InferenceContext<'a> {
self.unify(&ty, expected);
let substs =
ty.as_adt().map(|(_, s)| s.clone()).unwrap_or_else(|| Substitution::empty(&Interner));
ty.as_adt().map(|(_, s)| s.clone()).unwrap_or_else(|| Substitution::empty(Interner));
let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default();
for subpat in subpats {
let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name));
let expected_ty = matching_field.map_or(self.err_ty(), |field| {
field_tys[field].clone().substitute(&Interner, &substs)
field_tys[field].clone().substitute(Interner, &substs)
});
let expected_ty = self.normalize_associated_types_in(expected_ty);
self.infer_pat(subpat.pat, &expected_ty, default_bm);
@ -134,7 +134,7 @@ impl<'a> InferenceContext<'a> {
let ty = match &body[pat] {
Pat::Tuple { args, ellipsis } => {
let expectations = match expected.as_tuple() {
Some(parameters) => &*parameters.as_slice(&Interner),
Some(parameters) => &*parameters.as_slice(Interner),
_ => &[],
};
@ -146,7 +146,7 @@ impl<'a> InferenceContext<'a> {
};
let err_ty = self.err_ty();
let mut expectations_iter =
expectations.iter().map(|a| a.assert_ty_ref(&Interner)).chain(repeat(&err_ty));
expectations.iter().map(|a| a.assert_ty_ref(Interner)).chain(repeat(&err_ty));
let mut infer_pat = |(&pat, ty)| self.infer_pat(pat, ty, default_bm);
let mut inner_tys = Vec::with_capacity(n_uncovered_patterns + args.len());
@ -154,8 +154,8 @@ impl<'a> InferenceContext<'a> {
inner_tys.extend(expectations_iter.by_ref().take(n_uncovered_patterns).cloned());
inner_tys.extend(post.iter().zip(expectations_iter).map(infer_pat));
TyKind::Tuple(inner_tys.len(), Substitution::from_iter(&Interner, inner_tys))
.intern(&Interner)
TyKind::Tuple(inner_tys.len(), Substitution::from_iter(Interner, inner_tys))
.intern(Interner)
}
Pat::Or(pats) => {
if let Some((first_pat, rest)) = pats.split_first() {
@ -180,7 +180,7 @@ impl<'a> InferenceContext<'a> {
_ => self.result.standard_types.unknown.clone(),
};
let subty = self.infer_pat(*pat, &expectation, default_bm);
TyKind::Ref(mutability, static_lifetime(), subty).intern(&Interner)
TyKind::Ref(mutability, static_lifetime(), subty).intern(Interner)
}
Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat(
p.as_deref(),
@ -213,7 +213,7 @@ impl<'a> InferenceContext<'a> {
let bound_ty = match mode {
BindingMode::Ref(mutability) => {
TyKind::Ref(mutability, static_lifetime(), inner_ty.clone())
.intern(&Interner)
.intern(Interner)
}
BindingMode::Move => inner_ty.clone(),
};
@ -221,7 +221,7 @@ impl<'a> InferenceContext<'a> {
return inner_ty;
}
Pat::Slice { prefix, slice, suffix } => {
let elem_ty = match expected.kind(&Interner) {
let elem_ty = match expected.kind(Interner) {
TyKind::Array(st, _) | TyKind::Slice(st) => st.clone(),
_ => self.err_ty(),
};
@ -230,11 +230,11 @@ impl<'a> InferenceContext<'a> {
self.infer_pat(pat_id, &elem_ty, default_bm);
}
let pat_ty = match expected.kind(&Interner) {
let pat_ty = match expected.kind(Interner) {
TyKind::Array(_, const_) => TyKind::Array(elem_ty, const_.clone()),
_ => TyKind::Slice(elem_ty),
}
.intern(&Interner);
.intern(Interner);
if let &Some(slice_pat_id) = slice {
self.infer_pat(slice_pat_id, &pat_ty, default_bm);
}
@ -251,8 +251,8 @@ impl<'a> InferenceContext<'a> {
Some(box_adt) => {
let (inner_ty, alloc_ty) = match expected.as_adt() {
Some((adt, subst)) if adt == box_adt => (
subst.at(&Interner, 0).assert_ty_ref(&Interner).clone(),
subst.as_slice(&Interner).get(1).and_then(|a| a.ty(&Interner).cloned()),
subst.at(Interner, 0).assert_ty_ref(Interner).clone(),
subst.as_slice(Interner).get(1).and_then(|a| a.ty(Interner).cloned()),
),
_ => (self.result.standard_types.unknown.clone(), None),
};

View file

@ -83,9 +83,9 @@ impl<'a> InferenceContext<'a> {
ValueNs::ImplSelf(impl_id) => {
let generics = crate::utils::generics(self.db.upcast(), impl_id.into());
let substs = generics.type_params_subst(self.db);
let ty = self.db.impl_self_ty(impl_id).substitute(&Interner, &substs);
let ty = self.db.impl_self_ty(impl_id).substitute(Interner, &substs);
if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() {
let ty = self.db.value_ty(struct_id.into()).substitute(&Interner, &substs);
let ty = self.db.value_ty(struct_id.into()).substitute(Interner, &substs);
return Some(ty);
} else {
// FIXME: diagnostic, invalid Self reference
@ -95,12 +95,12 @@ impl<'a> InferenceContext<'a> {
ValueNs::GenericParam(it) => return Some(self.db.const_param_ty(it)),
};
let parent_substs = self_subst.unwrap_or_else(|| Substitution::empty(&Interner));
let parent_substs = self_subst.unwrap_or_else(|| Substitution::empty(Interner));
let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver);
let substs = ctx.substs_from_path(path, typable, true);
let ty = TyBuilder::value_ty(self.db, typable)
.use_parent_substs(&parent_substs)
.fill(substs.as_slice(&Interner)[parent_substs.len(&Interner)..].iter().cloned())
.fill(substs.as_slice(Interner)[parent_substs.len(Interner)..].iter().cloned())
.build();
Some(ty)
}
@ -144,7 +144,7 @@ impl<'a> InferenceContext<'a> {
remaining_segments_for_ty,
true,
);
if let TyKind::Error = ty.kind(&Interner) {
if let TyKind::Error = ty.kind(Interner) {
return None;
}
@ -209,7 +209,7 @@ impl<'a> InferenceContext<'a> {
name: &Name,
id: ExprOrPatId,
) -> Option<(ValueNs, Option<Substitution>)> {
if let TyKind::Error = ty.kind(&Interner) {
if let TyKind::Error = ty.kind(Interner) {
return None;
}
@ -246,7 +246,7 @@ impl<'a> InferenceContext<'a> {
.fill(iter::repeat_with(|| self.table.new_type_var()))
.build();
let impl_self_ty =
self.db.impl_self_ty(impl_id).substitute(&Interner, &impl_substs);
self.db.impl_self_ty(impl_id).substitute(Interner, &impl_substs);
self.unify(&impl_self_ty, &ty);
Some(impl_substs)
}
@ -256,7 +256,7 @@ impl<'a> InferenceContext<'a> {
.push(ty.clone())
.fill(std::iter::repeat_with(|| self.table.new_type_var()))
.build();
self.push_obligation(trait_ref.clone().cast(&Interner));
self.push_obligation(trait_ref.clone().cast(Interner));
Some(trait_ref.substitution)
}
ItemContainerId::ModuleId(_) | ItemContainerId::ExternBlockId(_) => None,

View file

@ -44,10 +44,10 @@ impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
/// this method is wrong and shouldn't exist
pub(super) fn decanonicalize_ty(&self, table: &mut InferenceTable, ty: Canonical<Ty>) -> Ty {
let mut vars = self.free_vars.clone();
while ty.binders.len(&Interner) > vars.len() {
vars.push(table.new_type_var().cast(&Interner));
while ty.binders.len(Interner) > vars.len() {
vars.push(table.new_type_var().cast(Interner));
}
chalk_ir::Substitute::apply(&vars, ty.value, &Interner)
chalk_ir::Substitute::apply(&vars, ty.value, Interner)
}
pub(super) fn apply_solution(
@ -57,25 +57,25 @@ impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
) {
// the solution may contain new variables, which we need to convert to new inference vars
let new_vars = Substitution::from_iter(
&Interner,
solution.binders.iter(&Interner).map(|k| match k.kind {
VariableKind::Ty(TyVariableKind::General) => ctx.new_type_var().cast(&Interner),
VariableKind::Ty(TyVariableKind::Integer) => ctx.new_integer_var().cast(&Interner),
VariableKind::Ty(TyVariableKind::Float) => ctx.new_float_var().cast(&Interner),
Interner,
solution.binders.iter(Interner).map(|k| match k.kind {
VariableKind::Ty(TyVariableKind::General) => ctx.new_type_var().cast(Interner),
VariableKind::Ty(TyVariableKind::Integer) => ctx.new_integer_var().cast(Interner),
VariableKind::Ty(TyVariableKind::Float) => ctx.new_float_var().cast(Interner),
// Chalk can sometimes return new lifetime variables. We just use the static lifetime everywhere
VariableKind::Lifetime => static_lifetime().cast(&Interner),
VariableKind::Lifetime => static_lifetime().cast(Interner),
_ => panic!("const variable in solution"),
}),
);
for (i, v) in solution.value.iter(&Interner).enumerate() {
for (i, v) in solution.value.iter(Interner).enumerate() {
let var = self.free_vars[i].clone();
if let Some(ty) = v.ty(&Interner) {
if let Some(ty) = v.ty(Interner) {
// eagerly replace projections in the type; we may be getting types
// e.g. from where clauses where this hasn't happened yet
let ty = ctx.normalize_associated_types_in(new_vars.apply(ty.clone(), &Interner));
ctx.unify(var.assert_ty_ref(&Interner), &ty);
let ty = ctx.normalize_associated_types_in(new_vars.apply(ty.clone(), Interner));
ctx.unify(var.assert_ty_ref(Interner), &ty);
} else {
let _ = ctx.try_unify(&var, &new_vars.apply(v.clone(), &Interner));
let _ = ctx.try_unify(&var, &new_vars.apply(v.clone(), Interner));
}
}
}
@ -96,39 +96,39 @@ pub(crate) fn unify(
) -> Option<Substitution> {
let mut table = InferenceTable::new(db, env);
let vars = Substitution::from_iter(
&Interner,
Interner,
tys.binders
.iter(&Interner)
.iter(Interner)
// we always use type vars here because we want everything to
// fallback to Unknown in the end (kind of hacky, as below)
.map(|_| table.new_type_var()),
);
let ty1_with_vars = vars.apply(tys.value.0.clone(), &Interner);
let ty2_with_vars = vars.apply(tys.value.1.clone(), &Interner);
let ty1_with_vars = vars.apply(tys.value.0.clone(), Interner);
let ty2_with_vars = vars.apply(tys.value.1.clone(), Interner);
if !table.unify(&ty1_with_vars, &ty2_with_vars) {
return None;
}
// default any type vars that weren't unified back to their original bound vars
// (kind of hacky)
let find_var = |iv| {
vars.iter(&Interner).position(|v| match v.interned() {
chalk_ir::GenericArgData::Ty(ty) => ty.inference_var(&Interner),
chalk_ir::GenericArgData::Lifetime(lt) => lt.inference_var(&Interner),
chalk_ir::GenericArgData::Const(c) => c.inference_var(&Interner),
vars.iter(Interner).position(|v| match v.interned() {
chalk_ir::GenericArgData::Ty(ty) => ty.inference_var(Interner),
chalk_ir::GenericArgData::Lifetime(lt) => lt.inference_var(Interner),
chalk_ir::GenericArgData::Const(c) => c.inference_var(Interner),
} == Some(iv))
};
let fallback = |iv, kind, default, binder| match kind {
chalk_ir::VariableKind::Ty(_ty_kind) => find_var(iv)
.map_or(default, |i| BoundVar::new(binder, i).to_ty(&Interner).cast(&Interner)),
.map_or(default, |i| BoundVar::new(binder, i).to_ty(Interner).cast(Interner)),
chalk_ir::VariableKind::Lifetime => find_var(iv)
.map_or(default, |i| BoundVar::new(binder, i).to_lifetime(&Interner).cast(&Interner)),
.map_or(default, |i| BoundVar::new(binder, i).to_lifetime(Interner).cast(Interner)),
chalk_ir::VariableKind::Const(ty) => find_var(iv)
.map_or(default, |i| BoundVar::new(binder, i).to_const(&Interner, ty).cast(&Interner)),
.map_or(default, |i| BoundVar::new(binder, i).to_const(Interner, ty).cast(Interner)),
};
Some(Substitution::from_iter(
&Interner,
vars.iter(&Interner)
.map(|v| table.resolve_with_fallback(v.assert_ty_ref(&Interner).clone(), &fallback)),
Interner,
vars.iter(Interner)
.map(|v| table.resolve_with_fallback(v.assert_ty_ref(Interner).clone(), &fallback)),
))
}
@ -200,7 +200,7 @@ impl<'a> InferenceTable<'a> {
TyVariableKind::Integer => TyKind::Scalar(Scalar::Int(IntTy::I32)),
TyVariableKind::Float => TyKind::Scalar(Scalar::Float(FloatTy::F64)),
}
.intern(&Interner)
.intern(Interner)
}
pub(super) fn canonicalize<T: Fold<Interner> + HasInterner<Interner = Interner>>(
@ -210,11 +210,11 @@ impl<'a> InferenceTable<'a> {
where
T::Result: HasInterner<Interner = Interner>,
{
let result = self.var_unification_table.canonicalize(&Interner, t);
let result = self.var_unification_table.canonicalize(Interner, t);
let free_vars = result
.free_vars
.into_iter()
.map(|free_var| free_var.to_generic_arg(&Interner))
.map(|free_var| free_var.to_generic_arg(Interner))
.collect();
Canonicalized { value: result.quantified, free_vars }
}
@ -228,7 +228,7 @@ impl<'a> InferenceTable<'a> {
pub(super) fn normalize_associated_types_in(&mut self, ty: Ty) -> Ty {
fold_tys(
ty,
|ty, _| match ty.kind(&Interner) {
|ty, _| match ty.kind(Interner) {
TyKind::Alias(AliasTy::Projection(proj_ty)) => {
self.normalize_projection_ty(proj_ty.clone())
}
@ -241,7 +241,7 @@ impl<'a> InferenceTable<'a> {
pub(super) fn normalize_projection_ty(&mut self, proj_ty: ProjectionTy) -> Ty {
let var = self.new_type_var();
let alias_eq = AliasEq { alias: AliasTy::Projection(proj_ty), ty: var.clone() };
let obligation = alias_eq.cast(&Interner);
let obligation = alias_eq.cast(Interner);
self.register_obligation(obligation);
var
}
@ -259,7 +259,7 @@ impl<'a> InferenceTable<'a> {
self.extend_type_variable_table(var.index() as usize);
assert_eq!(var.index() as usize, self.type_variable_table.len() - 1);
self.type_variable_table[var.index() as usize].diverging = diverging;
var.to_ty_with_kind(&Interner, kind)
var.to_ty_with_kind(Interner, kind)
}
pub(crate) fn new_type_var(&mut self) -> Ty {
@ -280,12 +280,12 @@ impl<'a> InferenceTable<'a> {
pub(crate) fn new_const_var(&mut self, ty: Ty) -> Const {
let var = self.var_unification_table.new_variable(UniverseIndex::ROOT);
var.to_const(&Interner, ty)
var.to_const(Interner, ty)
}
pub(crate) fn new_lifetime_var(&mut self) -> Lifetime {
let var = self.var_unification_table.new_variable(UniverseIndex::ROOT);
var.to_lifetime(&Interner)
var.to_lifetime(Interner)
}
pub(crate) fn resolve_with_fallback<T>(
@ -336,7 +336,7 @@ impl<'a> InferenceTable<'a> {
/// caller needs to deal with them.
pub(crate) fn try_unify<T: Zip<Interner>>(&mut self, t1: &T, t2: &T) -> InferResult<()> {
match self.var_unification_table.relate(
&Interner,
Interner,
&self.db,
&self.trait_env.env,
chalk_ir::Variance::Invariant,
@ -351,7 +351,7 @@ impl<'a> InferenceTable<'a> {
/// If `ty` is a type variable with known type, returns that type;
/// otherwise, return ty.
pub(crate) fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty {
self.var_unification_table.normalize_ty_shallow(&Interner, ty).unwrap_or_else(|| ty.clone())
self.var_unification_table.normalize_ty_shallow(Interner, ty).unwrap_or_else(|| ty.clone())
}
pub(crate) fn snapshot(&mut self) -> InferenceTableSnapshot {
@ -395,7 +395,7 @@ impl<'a> InferenceTable<'a> {
let uncanonical = chalk_ir::Substitute::apply(
&canonicalized.free_vars,
canonicalized.value.value,
&Interner,
Interner,
);
self.register_obligation_in_env(uncanonical);
}
@ -411,15 +411,15 @@ impl<'a> InferenceTable<'a> {
table: &'a mut InferenceTable<'b>,
highest_known_var: InferenceVar,
}
impl<'a, 'b> Folder<'static, Interner> for VarFudger<'a, 'b> {
impl<'a, 'b> Folder<Interner> for VarFudger<'a, 'b> {
type Error = NoSolution;
fn as_dyn(&mut self) -> &mut dyn Folder<'static, Interner, Error = Self::Error> {
fn as_dyn(&mut self) -> &mut dyn Folder<Interner, Error = Self::Error> {
self
}
fn interner(&self) -> &'static Interner {
&Interner
fn interner(&self) -> Interner {
Interner
}
fn fold_inference_ty(
@ -429,7 +429,7 @@ impl<'a> InferenceTable<'a> {
_outer_binder: chalk_ir::DebruijnIndex,
) -> chalk_ir::Fallible<chalk_ir::Ty<Interner>> {
Ok(if var < self.highest_known_var {
var.to_ty(&Interner, kind)
var.to_ty(Interner, kind)
} else {
self.table.new_type_var()
})
@ -441,7 +441,7 @@ impl<'a> InferenceTable<'a> {
_outer_binder: chalk_ir::DebruijnIndex,
) -> chalk_ir::Fallible<chalk_ir::Lifetime<Interner>> {
Ok(if var < self.highest_known_var {
var.to_lifetime(&Interner)
var.to_lifetime(Interner)
} else {
self.table.new_lifetime_var()
})
@ -454,7 +454,7 @@ impl<'a> InferenceTable<'a> {
_outer_binder: chalk_ir::DebruijnIndex,
) -> chalk_ir::Fallible<chalk_ir::Const<Interner>> {
Ok(if var < self.highest_known_var {
var.to_const(&Interner, ty)
var.to_const(Interner, ty)
} else {
self.table.new_const_var(ty)
})
@ -462,8 +462,7 @@ impl<'a> InferenceTable<'a> {
}
let snapshot = self.snapshot();
let highest_known_var =
self.new_type_var().inference_var(&Interner).expect("inference_var");
let highest_known_var = self.new_type_var().inference_var(Interner).expect("inference_var");
let result = f(self);
self.rollback_to(snapshot);
result
@ -477,10 +476,10 @@ impl<'a> InferenceTable<'a> {
/// again -- it'll give the same result as last time.
fn check_changed(&mut self, canonicalized: &Canonicalized<InEnvironment<Goal>>) -> bool {
canonicalized.free_vars.iter().any(|var| {
let iv = match var.data(&Interner) {
chalk_ir::GenericArgData::Ty(ty) => ty.inference_var(&Interner),
chalk_ir::GenericArgData::Lifetime(lt) => lt.inference_var(&Interner),
chalk_ir::GenericArgData::Const(c) => c.inference_var(&Interner),
let iv = match var.data(Interner) {
chalk_ir::GenericArgData::Ty(ty) => ty.inference_var(Interner),
chalk_ir::GenericArgData::Lifetime(lt) => lt.inference_var(Interner),
chalk_ir::GenericArgData::Const(c) => c.inference_var(Interner),
}
.expect("free var is not inference var");
if self.var_unification_table.probe_var(iv).is_some() {
@ -549,18 +548,18 @@ mod resolve {
pub(super) var_stack: &'a mut Vec<InferenceVar>,
pub(super) fallback: F,
}
impl<'a, 'b, 'i, F> Folder<'i, Interner> for Resolver<'a, 'b, F>
impl<'a, 'b, 'i, F> Folder<Interner> for Resolver<'a, 'b, F>
where
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg + 'i,
{
type Error = NoSolution;
fn as_dyn(&mut self) -> &mut dyn Folder<'i, Interner, Error = Self::Error> {
fn as_dyn(&mut self) -> &mut dyn Folder<Interner, Error = Self::Error> {
self
}
fn interner(&self) -> &'i Interner {
&Interner
fn interner(&self) -> Interner {
Interner
}
fn fold_inference_ty(
@ -572,9 +571,9 @@ mod resolve {
let var = self.table.var_unification_table.inference_var_root(var);
if self.var_stack.contains(&var) {
// recursive type
let default = self.table.fallback_value(var, kind).cast(&Interner);
let default = self.table.fallback_value(var, kind).cast(Interner);
return Ok((self.fallback)(var, VariableKind::Ty(kind), default, outer_binder)
.assert_ty_ref(&Interner)
.assert_ty_ref(Interner)
.clone());
}
let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
@ -583,11 +582,11 @@ mod resolve {
let result =
known_ty.fold_with(self, outer_binder).expect("fold failed unexpectedly");
self.var_stack.pop();
result.assert_ty_ref(&Interner).clone()
result.assert_ty_ref(Interner).clone()
} else {
let default = self.table.fallback_value(var, kind).cast(&Interner);
let default = self.table.fallback_value(var, kind).cast(Interner);
(self.fallback)(var, VariableKind::Ty(kind), default, outer_binder)
.assert_ty_ref(&Interner)
.assert_ty_ref(Interner)
.clone()
};
Ok(result)
@ -604,12 +603,12 @@ mod resolve {
ty: ty.clone(),
value: ConstValue::Concrete(ConcreteConst { interned: ConstScalar::Unknown }),
}
.intern(&Interner)
.cast(&Interner);
.intern(Interner)
.cast(Interner);
if self.var_stack.contains(&var) {
// recursive
return Ok((self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
.assert_const_ref(&Interner)
.assert_const_ref(Interner)
.clone());
}
let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
@ -618,10 +617,10 @@ mod resolve {
let result =
known_ty.fold_with(self, outer_binder).expect("fold failed unexpectedly");
self.var_stack.pop();
result.assert_const_ref(&Interner).clone()
result.assert_const_ref(Interner).clone()
} else {
(self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
.assert_const_ref(&Interner)
.assert_const_ref(Interner)
.clone()
};
Ok(result)

View file

@ -124,25 +124,25 @@ impl chalk_ir::interner::Interner for Interner {
}
fn debug_ty(ty: &chalk_ir::Ty<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", ty.data(&Interner)))
Some(write!(fmt, "{:?}", ty.data(Interner)))
}
fn debug_lifetime(
lifetime: &chalk_ir::Lifetime<Interner>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", lifetime.data(&Interner)))
Some(write!(fmt, "{:?}", lifetime.data(Interner)))
}
fn debug_generic_arg(
parameter: &GenericArg,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", parameter.data(&Interner).inner_debug()))
Some(write!(fmt, "{:?}", parameter.data(Interner).inner_debug()))
}
fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
let goal_data = goal.data(&Interner);
let goal_data = goal.data(Interner);
Some(write!(fmt, "{:?}", goal_data))
}
@ -150,28 +150,28 @@ impl chalk_ir::interner::Interner for Interner {
goals: &chalk_ir::Goals<Interner>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", goals.debug(&Interner)))
Some(write!(fmt, "{:?}", goals.debug(Interner)))
}
fn debug_program_clause_implication(
pci: &chalk_ir::ProgramClauseImplication<Interner>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", pci.debug(&Interner)))
Some(write!(fmt, "{:?}", pci.debug(Interner)))
}
fn debug_substitution(
substitution: &chalk_ir::Substitution<Interner>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", substitution.debug(&Interner)))
Some(write!(fmt, "{:?}", substitution.debug(Interner)))
}
fn debug_separator_trait_ref(
separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", separator_trait_ref.debug(&Interner)))
Some(write!(fmt, "{:?}", separator_trait_ref.debug(Interner)))
}
fn debug_fn_def_id(
@ -184,75 +184,75 @@ impl chalk_ir::interner::Interner for Interner {
constant: &chalk_ir::Const<Self>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", constant.data(&Interner)))
Some(write!(fmt, "{:?}", constant.data(Interner)))
}
fn debug_variable_kinds(
variable_kinds: &chalk_ir::VariableKinds<Self>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", variable_kinds.as_slice(&Interner)))
Some(write!(fmt, "{:?}", variable_kinds.as_slice(Interner)))
}
fn debug_variable_kinds_with_angles(
variable_kinds: &chalk_ir::VariableKinds<Self>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", variable_kinds.inner_debug(&Interner)))
Some(write!(fmt, "{:?}", variable_kinds.inner_debug(Interner)))
}
fn debug_canonical_var_kinds(
canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", canonical_var_kinds.as_slice(&Interner)))
Some(write!(fmt, "{:?}", canonical_var_kinds.as_slice(Interner)))
}
fn debug_program_clause(
clause: &chalk_ir::ProgramClause<Self>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", clause.data(&Interner)))
Some(write!(fmt, "{:?}", clause.data(Interner)))
}
fn debug_program_clauses(
clauses: &chalk_ir::ProgramClauses<Self>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", clauses.as_slice(&Interner)))
Some(write!(fmt, "{:?}", clauses.as_slice(Interner)))
}
fn debug_quantified_where_clauses(
clauses: &chalk_ir::QuantifiedWhereClauses<Self>,
fmt: &mut fmt::Formatter<'_>,
) -> Option<fmt::Result> {
Some(write!(fmt, "{:?}", clauses.as_slice(&Interner)))
Some(write!(fmt, "{:?}", clauses.as_slice(Interner)))
}
fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType {
fn intern_ty(self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType {
let flags = kind.compute_flags(self);
Interned::new(InternedWrapper(chalk_ir::TyData { kind, flags }))
}
fn ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self> {
fn ty_data<'a>(self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self> {
&ty.0
}
fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime {
fn intern_lifetime(self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime {
Interned::new(InternedWrapper(lifetime))
}
fn lifetime_data<'a>(
&self,
self,
lifetime: &'a Self::InternedLifetime,
) -> &'a chalk_ir::LifetimeData<Self> {
&lifetime.0
}
fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst {
fn intern_const(self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst {
Interned::new(InternedWrapper(constant))
}
fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> {
fn const_data<'a>(self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> {
&constant.0
}
fn const_eq(
&self,
self,
_ty: &Self::InternedType,
c1: &Self::InternedConcreteConst,
c2: &Self::InternedConcreteConst,
@ -266,131 +266,131 @@ impl chalk_ir::interner::Interner for Interner {
}
fn intern_generic_arg(
&self,
self,
parameter: chalk_ir::GenericArgData<Self>,
) -> Self::InternedGenericArg {
parameter
}
fn generic_arg_data<'a>(
&self,
self,
parameter: &'a Self::InternedGenericArg,
) -> &'a chalk_ir::GenericArgData<Self> {
parameter
}
fn intern_goal(&self, goal: GoalData<Self>) -> Self::InternedGoal {
fn intern_goal(self, goal: GoalData<Self>) -> Self::InternedGoal {
Arc::new(goal)
}
fn intern_goals<E>(
&self,
self,
data: impl IntoIterator<Item = Result<Goal<Self>, E>>,
) -> Result<Self::InternedGoals, E> {
data.into_iter().collect()
}
fn goal_data<'a>(&self, goal: &'a Self::InternedGoal) -> &'a GoalData<Self> {
fn goal_data<'a>(self, goal: &'a Self::InternedGoal) -> &'a GoalData<Self> {
goal
}
fn goals_data<'a>(&self, goals: &'a Self::InternedGoals) -> &'a [Goal<Interner>] {
fn goals_data<'a>(self, goals: &'a Self::InternedGoals) -> &'a [Goal<Interner>] {
goals
}
fn intern_substitution<E>(
&self,
self,
data: impl IntoIterator<Item = Result<GenericArg, E>>,
) -> Result<Self::InternedSubstitution, E> {
Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
}
fn substitution_data<'a>(
&self,
self,
substitution: &'a Self::InternedSubstitution,
) -> &'a [GenericArg] {
&substitution.as_ref().0
}
fn intern_program_clause(
&self,
self,
data: chalk_ir::ProgramClauseData<Self>,
) -> Self::InternedProgramClause {
data
}
fn program_clause_data<'a>(
&self,
self,
clause: &'a Self::InternedProgramClause,
) -> &'a chalk_ir::ProgramClauseData<Self> {
clause
}
fn intern_program_clauses<E>(
&self,
self,
data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>,
) -> Result<Self::InternedProgramClauses, E> {
Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
}
fn program_clauses_data<'a>(
&self,
self,
clauses: &'a Self::InternedProgramClauses,
) -> &'a [chalk_ir::ProgramClause<Self>] {
clauses
}
fn intern_quantified_where_clauses<E>(
&self,
self,
data: impl IntoIterator<Item = Result<chalk_ir::QuantifiedWhereClause<Self>, E>>,
) -> Result<Self::InternedQuantifiedWhereClauses, E> {
Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
}
fn quantified_where_clauses_data<'a>(
&self,
self,
clauses: &'a Self::InternedQuantifiedWhereClauses,
) -> &'a [chalk_ir::QuantifiedWhereClause<Self>] {
clauses
}
fn intern_generic_arg_kinds<E>(
&self,
self,
data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>,
) -> Result<Self::InternedVariableKinds, E> {
Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
}
fn variable_kinds_data<'a>(
&self,
self,
parameter_kinds: &'a Self::InternedVariableKinds,
) -> &'a [chalk_ir::VariableKind<Self>] {
&parameter_kinds.as_ref().0
}
fn intern_canonical_var_kinds<E>(
&self,
self,
data: impl IntoIterator<Item = Result<chalk_ir::CanonicalVarKind<Self>, E>>,
) -> Result<Self::InternedCanonicalVarKinds, E> {
Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
}
fn canonical_var_kinds_data<'a>(
&self,
self,
canonical_var_kinds: &'a Self::InternedCanonicalVarKinds,
) -> &'a [chalk_ir::CanonicalVarKind<Self>] {
canonical_var_kinds
}
fn intern_constraints<E>(
&self,
self,
data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>,
) -> Result<Self::InternedConstraints, E> {
data.into_iter().collect()
}
fn constraints_data<'a>(
&self,
self,
constraints: &'a Self::InternedConstraints,
) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
constraints
@ -409,14 +409,14 @@ impl chalk_ir::interner::Interner for Interner {
}
fn intern_variances<E>(
&self,
self,
data: impl IntoIterator<Item = Result<chalk_ir::Variance, E>>,
) -> Result<Self::InternedVariances, E> {
Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
}
fn variances_data<'a>(
&self,
self,
variances: &'a Self::InternedVariances,
) -> &'a [chalk_ir::Variance] {
variances

View file

@ -123,8 +123,8 @@ pub type WhereClause = chalk_ir::WhereClause<Interner>;
// FIXME: get rid of this
pub fn subst_prefix(s: &Substitution, n: usize) -> Substitution {
Substitution::from_iter(
&Interner,
s.as_slice(&Interner)[..std::cmp::min(s.len(&Interner), n)].iter().cloned(),
Interner,
s.as_slice(Interner)[..std::cmp::min(s.len(Interner), n)].iter().cloned(),
)
}
@ -137,7 +137,7 @@ pub(crate) fn wrap_empty_binders<T>(value: T) -> Binders<T>
where
T: Fold<Interner, Result = T> + HasInterner<Interner = Interner>,
{
Binders::empty(&Interner, value.shifted_in_from(&Interner, DebruijnIndex::ONE))
Binders::empty(Interner, value.shifted_in_from(Interner, DebruijnIndex::ONE))
}
pub(crate) fn make_only_type_binders<T: HasInterner<Interner = Interner>>(
@ -146,7 +146,7 @@ pub(crate) fn make_only_type_binders<T: HasInterner<Interner = Interner>>(
) -> Binders<T> {
Binders::new(
VariableKinds::from_iter(
&Interner,
Interner,
std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General))
.take(num_vars),
),
@ -165,7 +165,7 @@ pub fn make_canonical<T: HasInterner<Interner = Interner>>(
chalk_ir::UniverseIndex::ROOT,
)
});
Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) }
Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(Interner, kinds) }
}
// FIXME: get rid of this, just replace it by FnPointer
@ -199,12 +199,12 @@ impl CallableSig {
params_and_return: fn_ptr
.substitution
.clone()
.shifted_out_to(&Interner, DebruijnIndex::ONE)
.shifted_out_to(Interner, DebruijnIndex::ONE)
.expect("unexpected lifetime vars in fn ptr")
.0
.as_slice(&Interner)
.as_slice(Interner)
.iter()
.map(|arg| arg.assert_ty_ref(&Interner).clone())
.map(|arg| arg.assert_ty_ref(Interner).clone())
.collect(),
is_varargs: fn_ptr.sig.variadic,
legacy_const_generics_indices: Arc::new([]),
@ -220,7 +220,7 @@ impl CallableSig {
num_binders: 0,
sig: FnSig { abi: (), safety: Safety::Safe, variadic: self.is_varargs },
substitution: FnSubst(Substitution::from_iter(
&Interner,
Interner,
self.params_and_return.iter().cloned(),
)),
}
@ -238,14 +238,11 @@ impl CallableSig {
impl Fold<Interner> for CallableSig {
type Result = CallableSig;
fn fold_with<'i, E>(
fn fold_with<E>(
self,
folder: &mut dyn chalk_ir::fold::Folder<'i, Interner, Error = E>,
folder: &mut dyn chalk_ir::fold::Folder<Interner, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self::Result, E>
where
Interner: 'i,
{
) -> Result<Self::Result, E> {
let vec = self.params_and_return.to_vec();
let folded = vec.fold_with(folder, outer_binder)?;
Ok(CallableSig {
@ -275,18 +272,18 @@ pub(crate) struct ReturnTypeImplTrait {
}
pub fn static_lifetime() -> Lifetime {
LifetimeData::Static.intern(&Interner)
LifetimeData::Static.intern(Interner)
}
pub fn dummy_usize_const() -> Const {
let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(&Interner);
let usize_ty = chalk_ir::TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(Interner);
chalk_ir::ConstData {
ty: usize_ty,
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst {
interned: ConstScalar::Unknown,
}),
}
.intern(&Interner)
.intern(Interner)
}
pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + Fold<Interner>>(
@ -295,15 +292,15 @@ pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + Fold<Interner
) -> T::Result {
use chalk_ir::{fold::Folder, Fallible};
struct FreeVarFolder<F>(F);
impl<'i, F: FnMut(BoundVar, DebruijnIndex) -> Ty + 'i> Folder<'i, Interner> for FreeVarFolder<F> {
impl<'i, F: FnMut(BoundVar, DebruijnIndex) -> Ty + 'i> Folder<Interner> for FreeVarFolder<F> {
type Error = NoSolution;
fn as_dyn(&mut self) -> &mut dyn Folder<'i, Interner, Error = Self::Error> {
fn as_dyn(&mut self) -> &mut dyn Folder<Interner, Error = Self::Error> {
self
}
fn interner(&self) -> &'i Interner {
&Interner
fn interner(&self) -> Interner {
Interner
}
fn fold_free_var_ty(
@ -327,15 +324,15 @@ pub(crate) fn fold_tys<T: HasInterner<Interner = Interner> + Fold<Interner>>(
Fallible,
};
struct TyFolder<F>(F);
impl<'i, F: FnMut(Ty, DebruijnIndex) -> Ty + 'i> Folder<'i, Interner> for TyFolder<F> {
impl<'i, F: FnMut(Ty, DebruijnIndex) -> Ty + 'i> Folder<Interner> for TyFolder<F> {
type Error = NoSolution;
fn as_dyn(&mut self) -> &mut dyn Folder<'i, Interner, Error = Self::Error> {
fn as_dyn(&mut self) -> &mut dyn Folder<Interner, Error = Self::Error> {
self
}
fn interner(&self) -> &'i Interner {
&Interner
fn interner(&self) -> Interner {
Interner
}
fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
@ -361,22 +358,22 @@ where
struct ErrorReplacer {
vars: usize,
}
impl<'i> Folder<'i, Interner> for ErrorReplacer {
impl<'i> Folder<Interner> for ErrorReplacer {
type Error = NoSolution;
fn as_dyn(&mut self) -> &mut dyn Folder<'i, Interner, Error = Self::Error> {
fn as_dyn(&mut self) -> &mut dyn Folder<Interner, Error = Self::Error> {
self
}
fn interner(&self) -> &'i Interner {
&Interner
fn interner(&self) -> Interner {
Interner
}
fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
if let TyKind::Error = ty.kind(&Interner) {
if let TyKind::Error = ty.kind(Interner) {
let index = self.vars;
self.vars += 1;
Ok(TyKind::BoundVar(BoundVar::new(outer_binder, index)).intern(&Interner))
Ok(TyKind::BoundVar(BoundVar::new(outer_binder, index)).intern(Interner))
} else {
let ty = ty.super_fold_with(self.as_dyn(), outer_binder)?;
Ok(ty)
@ -394,7 +391,7 @@ where
// won't contain the whole thing, which would not be very helpful
Err(NoSolution)
} else {
Ok(TyKind::Error.intern(&Interner))
Ok(TyKind::Error.intern(Interner))
}
}
@ -408,7 +405,7 @@ where
// won't contain the whole thing, which would not be very helpful
Err(NoSolution)
} else {
Ok(TyKind::Error.intern(&Interner))
Ok(TyKind::Error.intern(Interner))
}
}
@ -473,5 +470,5 @@ where
chalk_ir::UniverseIndex::ROOT,
)
});
Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) }
Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(Interner, kinds) }
}

View file

@ -166,11 +166,11 @@ impl<'a> TyLoweringContext<'a> {
pub fn lower_ty_ext(&self, type_ref: &TypeRef) -> (Ty, Option<TypeNs>) {
let mut res = None;
let ty = match type_ref {
TypeRef::Never => TyKind::Never.intern(&Interner),
TypeRef::Never => TyKind::Never.intern(Interner),
TypeRef::Tuple(inner) => {
let inner_tys = inner.iter().map(|tr| self.lower_ty(tr));
TyKind::Tuple(inner_tys.len(), Substitution::from_iter(&Interner, inner_tys))
.intern(&Interner)
TyKind::Tuple(inner_tys.len(), Substitution::from_iter(Interner, inner_tys))
.intern(Interner)
}
TypeRef::Path(path) => {
let (ty, res_) = self.lower_path(path);
@ -179,48 +179,48 @@ impl<'a> TyLoweringContext<'a> {
}
TypeRef::RawPtr(inner, mutability) => {
let inner_ty = self.lower_ty(inner);
TyKind::Raw(lower_to_chalk_mutability(*mutability), inner_ty).intern(&Interner)
TyKind::Raw(lower_to_chalk_mutability(*mutability), inner_ty).intern(Interner)
}
TypeRef::Array(inner, len) => {
let inner_ty = self.lower_ty(inner);
let const_len = consteval::usize_const(len.as_usize());
TyKind::Array(inner_ty, const_len).intern(&Interner)
TyKind::Array(inner_ty, const_len).intern(Interner)
}
TypeRef::Slice(inner) => {
let inner_ty = self.lower_ty(inner);
TyKind::Slice(inner_ty).intern(&Interner)
TyKind::Slice(inner_ty).intern(Interner)
}
TypeRef::Reference(inner, _, mutability) => {
let inner_ty = self.lower_ty(inner);
let lifetime = static_lifetime();
TyKind::Ref(lower_to_chalk_mutability(*mutability), lifetime, inner_ty)
.intern(&Interner)
.intern(Interner)
}
TypeRef::Placeholder => TyKind::Error.intern(&Interner),
TypeRef::Placeholder => TyKind::Error.intern(Interner),
TypeRef::Fn(params, is_varargs) => {
let substs = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
Substitution::from_iter(&Interner, params.iter().map(|tr| ctx.lower_ty(tr)))
Substitution::from_iter(Interner, params.iter().map(|tr| ctx.lower_ty(tr)))
});
TyKind::Function(FnPointer {
num_binders: 0, // FIXME lower `for<'a> fn()` correctly
sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs },
substitution: FnSubst(substs),
})
.intern(&Interner)
.intern(Interner)
}
TypeRef::DynTrait(bounds) => {
let self_ty =
TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(&Interner);
TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(Interner);
let bounds = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
QuantifiedWhereClauses::from_iter(
&Interner,
Interner,
bounds.iter().flat_map(|b| ctx.lower_type_bound(b, self_ty.clone(), false)),
)
});
let bounds = crate::make_only_type_binders(1, bounds);
TyKind::Dyn(DynTy { bounds, lifetime: static_lifetime() }).intern(&Interner)
TyKind::Dyn(DynTy { bounds, lifetime: static_lifetime() }).intern(Interner)
}
TypeRef::ImplTrait(bounds) => {
match self.impl_trait_mode {
@ -258,7 +258,7 @@ impl<'a> TyLoweringContext<'a> {
let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into();
let generics = generics(self.db.upcast(), func.into());
let parameters = generics.bound_vars_subst(self.in_binders);
TyKind::OpaqueType(opaque_ty_id, parameters).intern(&Interner)
TyKind::OpaqueType(opaque_ty_id, parameters).intern(Interner)
}
ImplTraitLoweringMode::Param => {
let idx = self.impl_trait_counter.get();
@ -275,9 +275,9 @@ impl<'a> TyLoweringContext<'a> {
.map_or(TyKind::Error, |(id, _)| {
TyKind::Placeholder(to_placeholder_idx(self.db, id))
});
param.intern(&Interner)
param.intern(Interner)
} else {
TyKind::Error.intern(&Interner)
TyKind::Error.intern(Interner)
}
}
ImplTraitLoweringMode::Variable => {
@ -295,11 +295,11 @@ impl<'a> TyLoweringContext<'a> {
self.in_binders,
idx as usize + parent_params + self_params + list_params,
))
.intern(&Interner)
.intern(Interner)
}
ImplTraitLoweringMode::Disallowed => {
// FIXME: report error
TyKind::Error.intern(&Interner)
TyKind::Error.intern(Interner)
}
}
}
@ -343,9 +343,9 @@ impl<'a> TyLoweringContext<'a> {
if recursion_start {
*self.expander.borrow_mut() = None;
}
ty.unwrap_or_else(|| TyKind::Error.intern(&Interner))
ty.unwrap_or_else(|| TyKind::Error.intern(Interner))
}
TypeRef::Error => TyKind::Error.intern(&Interner),
TypeRef::Error => TyKind::Error.intern(Interner),
};
(ty, res)
}
@ -391,7 +391,7 @@ impl<'a> TyLoweringContext<'a> {
}
_ => {
// FIXME report error (ambiguous associated type)
(TyKind::Error.intern(&Interner), None)
(TyKind::Error.intern(Interner), None)
}
}
}
@ -421,18 +421,18 @@ impl<'a> TyLoweringContext<'a> {
associated_ty_id: to_assoc_type_id(associated_ty),
substitution: trait_ref.substitution,
}))
.intern(&Interner)
.intern(Interner)
}
None => {
// FIXME: report error (associated type not found)
TyKind::Error.intern(&Interner)
TyKind::Error.intern(Interner)
}
}
}
0 => {
let self_ty = Some(
TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
.intern(&Interner),
.intern(Interner),
);
let trait_ref = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
ctx.lower_trait_ref_from_resolved_path(
@ -445,7 +445,7 @@ impl<'a> TyLoweringContext<'a> {
bounds: crate::make_only_type_binders(
1,
QuantifiedWhereClauses::from_iter(
&Interner,
Interner,
Some(crate::wrap_empty_binders(WhereClause::Implemented(
trait_ref,
))),
@ -453,11 +453,11 @@ impl<'a> TyLoweringContext<'a> {
),
lifetime: static_lifetime(),
};
TyKind::Dyn(dyn_ty).intern(&Interner)
TyKind::Dyn(dyn_ty).intern(Interner)
}
_ => {
// FIXME report error (ambiguous associated type)
TyKind::Error.intern(&Interner)
TyKind::Error.intern(Interner)
}
};
return (ty, None);
@ -476,7 +476,7 @@ impl<'a> TyLoweringContext<'a> {
TyKind::BoundVar(BoundVar::new(self.in_binders, idx))
}
}
.intern(&Interner)
.intern(Interner)
}
TypeNs::SelfType(impl_id) => {
let generics = generics(self.db.upcast(), impl_id.into());
@ -484,7 +484,7 @@ impl<'a> TyLoweringContext<'a> {
TypeParamLoweringMode::Placeholder => generics.type_params_subst(self.db),
TypeParamLoweringMode::Variable => generics.bound_vars_subst(self.in_binders),
};
self.db.impl_self_ty(impl_id).substitute(&Interner, &substs)
self.db.impl_self_ty(impl_id).substitute(Interner, &substs)
}
TypeNs::AdtSelfType(adt) => {
let generics = generics(self.db.upcast(), adt.into());
@ -492,7 +492,7 @@ impl<'a> TyLoweringContext<'a> {
TypeParamLoweringMode::Placeholder => generics.type_params_subst(self.db),
TypeParamLoweringMode::Variable => generics.bound_vars_subst(self.in_binders),
};
self.db.ty(adt.into()).substitute(&Interner, &substs)
self.db.ty(adt.into()).substitute(Interner, &substs)
}
TypeNs::AdtId(it) => self.lower_path_inner(resolved_segment, it.into(), infer_args),
@ -503,7 +503,7 @@ impl<'a> TyLoweringContext<'a> {
self.lower_path_inner(resolved_segment, it.into(), infer_args)
}
// FIXME: report error
TypeNs::EnumVariantId(_) => return (TyKind::Error.intern(&Interner), None),
TypeNs::EnumVariantId(_) => return (TyKind::Error.intern(Interner), None),
};
self.lower_ty_relative_path(ty, Some(resolution), remaining_segments)
}
@ -517,7 +517,7 @@ impl<'a> TyLoweringContext<'a> {
let (resolution, remaining_index) =
match self.resolver.resolve_path_in_type_ns(self.db.upcast(), path.mod_path()) {
Some(it) => it,
None => return (TyKind::Error.intern(&Interner), None),
None => return (TyKind::Error.intern(Interner), None),
};
let (resolved_segment, remaining_segments) = match remaining_index {
None => (
@ -548,20 +548,20 @@ impl<'a> TyLoweringContext<'a> {
),
);
let s = generics.type_params_subst(self.db);
s.apply(t.substitution.clone(), &Interner)
s.apply(t.substitution.clone(), Interner)
}
TypeParamLoweringMode::Variable => t.substitution.clone(),
};
// We need to shift in the bound vars, since
// associated_type_shorthand_candidates does not do that
let substs = substs.shifted_in_from(&Interner, self.in_binders);
let substs = substs.shifted_in_from(Interner, self.in_binders);
// FIXME handle type parameters on the segment
Some(
TyKind::Alias(AliasTy::Projection(ProjectionTy {
associated_ty_id: to_assoc_type_id(associated_ty),
substitution: substs,
}))
.intern(&Interner),
.intern(Interner),
)
} else {
None
@ -569,9 +569,9 @@ impl<'a> TyLoweringContext<'a> {
},
);
ty.unwrap_or_else(|| TyKind::Error.intern(&Interner))
ty.unwrap_or_else(|| TyKind::Error.intern(Interner))
} else {
TyKind::Error.intern(&Interner)
TyKind::Error.intern(Interner)
}
}
@ -587,7 +587,7 @@ impl<'a> TyLoweringContext<'a> {
TyDefId::TypeAliasId(it) => Some(it.into()),
};
let substs = self.substs_from_path_segment(segment, generic_def, infer_args, None);
self.db.ty(typeable).substitute(&Interner, &substs)
self.db.ty(typeable).substitute(Interner, &substs)
}
/// Collect generic arguments from a path into a `Substs`. See also
@ -640,13 +640,13 @@ impl<'a> TyLoweringContext<'a> {
def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split());
let total_len = parent_params + self_params + type_params + impl_trait_params;
substs.extend(iter::repeat(TyKind::Error.intern(&Interner)).take(parent_params));
substs.extend(iter::repeat(TyKind::Error.intern(Interner)).take(parent_params));
let fill_self_params = || {
substs.extend(
explicit_self_ty
.into_iter()
.chain(iter::repeat(TyKind::Error.intern(&Interner)))
.chain(iter::repeat(TyKind::Error.intern(Interner)))
.take(self_params),
)
};
@ -690,8 +690,8 @@ impl<'a> TyLoweringContext<'a> {
for default_ty in defaults.iter().skip(substs.len()) {
// each default can depend on the previous parameters
let substs_so_far = Substitution::from_iter(&Interner, substs.clone());
substs.push(default_ty.clone().substitute(&Interner, &substs_so_far));
let substs_so_far = Substitution::from_iter(Interner, substs.clone());
substs.push(default_ty.clone().substitute(Interner, &substs_so_far));
}
}
}
@ -699,11 +699,11 @@ impl<'a> TyLoweringContext<'a> {
// add placeholders for args that were not provided
// FIXME: emit diagnostics in contexts where this is not allowed
for _ in substs.len()..total_len {
substs.push(TyKind::Error.intern(&Interner));
substs.push(TyKind::Error.intern(Interner));
}
assert_eq!(substs.len(), total_len);
Substitution::from_iter(&Interner, substs)
Substitution::from_iter(Interner, substs)
}
fn lower_trait_ref_from_path(
@ -770,7 +770,7 @@ impl<'a> TyLoweringContext<'a> {
TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, idx))
}
}
.intern(&Interner)
.intern(Interner)
}
};
self.lower_type_bound(bound, self_ty, ignore_bindings)
@ -869,7 +869,7 @@ impl<'a> TyLoweringContext<'a> {
for bound in &binding.bounds {
preds.extend(self.lower_type_bound(
bound,
TyKind::Alias(AliasTy::Projection(projection_ty.clone())).intern(&Interner),
TyKind::Alias(AliasTy::Projection(projection_ty.clone())).intern(Interner),
false,
));
}
@ -883,8 +883,7 @@ impl<'a> TyLoweringContext<'a> {
func: FunctionId,
) -> ReturnTypeImplTrait {
cov_mark::hit!(lower_rpit);
let self_ty =
TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(&Interner);
let self_ty = TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(Interner);
let predicates = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
let mut predicates: Vec<_> = bounds
.iter()
@ -900,7 +899,7 @@ impl<'a> TyLoweringContext<'a> {
let sized_clause = sized_trait.map(|trait_id| {
let clause = WhereClause::Implemented(TraitRef {
trait_id,
substitution: Substitution::from1(&Interner, self_ty.clone()),
substitution: Substitution::from1(Interner, self_ty.clone()),
});
crate::wrap_empty_binders(clause)
});
@ -974,7 +973,7 @@ fn named_associated_type_shorthand_candidates<R>(
// FIXME: how to correctly handle higher-ranked bounds here?
WhereClause::Implemented(tr) => search(
tr.clone()
.shifted_out_to(&Interner, DebruijnIndex::ONE)
.shifted_out_to(Interner, DebruijnIndex::ONE)
.expect("FIXME unexpected higher-ranked trait bound"),
),
_ => None,
@ -1117,11 +1116,10 @@ pub(crate) fn trait_environment_query(
for pred in resolver.where_predicates_in_scope() {
for pred in ctx.lower_where_predicate(pred, false) {
if let WhereClause::Implemented(tr) = &pred.skip_binders() {
traits_in_scope
.push((tr.self_type_parameter(&Interner).clone(), tr.hir_trait_id()));
traits_in_scope.push((tr.self_type_parameter(Interner).clone(), tr.hir_trait_id()));
}
let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(&Interner);
clauses.push(program_clause.into_from_env_clause(&Interner));
let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(Interner);
clauses.push(program_clause.into_from_env_clause(Interner));
}
}
@ -1143,22 +1141,22 @@ pub(crate) fn trait_environment_query(
let substs = TyBuilder::type_params_subst(db, trait_id);
let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs };
let pred = WhereClause::Implemented(trait_ref);
let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(&Interner);
clauses.push(program_clause.into_from_env_clause(&Interner));
let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(Interner);
clauses.push(program_clause.into_from_env_clause(Interner));
}
let subst = generics(db.upcast(), def).type_params_subst(db);
let explicitly_unsized_tys = ctx.unsized_types.into_inner();
let implicitly_sized_clauses =
implicitly_sized_clauses(db, def, &explicitly_unsized_tys, &subst, &resolver).map(|pred| {
let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(&Interner);
program_clause.into_from_env_clause(&Interner)
let program_clause: chalk_ir::ProgramClause<Interner> = pred.cast(Interner);
program_clause.into_from_env_clause(Interner)
});
clauses.extend(implicitly_sized_clauses);
let krate = def.module(db.upcast()).krate();
let env = chalk_ir::Environment::new(&Interner).add_clauses(&Interner, clauses);
let env = chalk_ir::Environment::new(Interner).add_clauses(Interner, clauses);
Arc::new(TraitEnvironment { krate, traits_from_clauses: traits_in_scope, env })
}
@ -1197,7 +1195,7 @@ fn implicitly_sized_clauses<'a>(
resolver: &Resolver,
) -> impl Iterator<Item = WhereClause> + 'a {
let is_trait_def = matches!(def, GenericDefId::TraitId(..));
let generic_args = &substitution.as_slice(&Interner)[is_trait_def as usize..];
let generic_args = &substitution.as_slice(Interner)[is_trait_def as usize..];
let sized_trait = resolver
.krate()
.and_then(|krate| db.lang_item(krate, SmolStr::new_inline("sized")))
@ -1206,12 +1204,12 @@ fn implicitly_sized_clauses<'a>(
sized_trait.into_iter().flat_map(move |sized_trait| {
let implicitly_sized_tys = generic_args
.iter()
.filter_map(|generic_arg| generic_arg.ty(&Interner))
.filter_map(|generic_arg| generic_arg.ty(Interner))
.filter(move |&self_ty| !explicitly_unsized_tys.contains(self_ty));
implicitly_sized_tys.map(move |self_ty| {
WhereClause::Implemented(TraitRef {
trait_id: sized_trait,
substitution: Substitution::from1(&Interner, self_ty.clone()),
substitution: Substitution::from1(Interner, self_ty.clone()),
})
})
})
@ -1232,7 +1230,7 @@ pub(crate) fn generic_defaults_query(
.enumerate()
.map(|(idx, (_, p))| {
let mut ty =
p.default.as_ref().map_or(TyKind::Error.intern(&Interner), |t| ctx.lower_ty(t));
p.default.as_ref().map_or(TyKind::Error.intern(Interner), |t| ctx.lower_ty(t));
// Each default can only refer to previous parameters.
ty = crate::fold_free_vars(ty, |bound, binders| {
@ -1240,9 +1238,9 @@ pub(crate) fn generic_defaults_query(
// type variable default referring to parameter coming
// after it. This is forbidden (FIXME: report
// diagnostic)
TyKind::Error.intern(&Interner)
TyKind::Error.intern(Interner)
} else {
bound.shifted_in_from(binders).to_ty(&Interner)
bound.shifted_in_from(binders).to_ty(Interner)
}
});
@ -1265,7 +1263,7 @@ pub(crate) fn generic_defaults_recover(
.iter()
.enumerate()
.map(|(idx, _)| {
let ty = TyKind::Error.intern(&Interner);
let ty = TyKind::Error.intern(Interner);
crate::make_only_type_binders(idx, ty)
})
@ -1300,7 +1298,7 @@ fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> {
let substs = generics.bound_vars_subst(DebruijnIndex::INNERMOST);
make_binders(
&generics,
TyKind::FnDef(CallableDefId::FunctionId(def).to_chalk(db), substs).intern(&Interner),
TyKind::FnDef(CallableDefId::FunctionId(def).to_chalk(db), substs).intern(Interner),
)
}
@ -1321,7 +1319,7 @@ fn type_for_static(db: &dyn HirDatabase, def: StaticId) -> Binders<Ty> {
let resolver = def.resolver(db.upcast());
let ctx = TyLoweringContext::new(db, &resolver);
Binders::empty(&Interner, ctx.lower_ty(&data.type_ref))
Binders::empty(Interner, ctx.lower_ty(&data.type_ref))
}
fn fn_sig_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> PolyFnSig {
@ -1345,7 +1343,7 @@ fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Binders<T
let substs = generics.bound_vars_subst(DebruijnIndex::INNERMOST);
make_binders(
&generics,
TyKind::FnDef(CallableDefId::StructId(def).to_chalk(db), substs).intern(&Interner),
TyKind::FnDef(CallableDefId::StructId(def).to_chalk(db), substs).intern(Interner),
)
}
@ -1372,7 +1370,7 @@ fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -
let substs = generics.bound_vars_subst(DebruijnIndex::INNERMOST);
make_binders(
&generics,
TyKind::FnDef(CallableDefId::EnumVariantId(def).to_chalk(db), substs).intern(&Interner),
TyKind::FnDef(CallableDefId::EnumVariantId(def).to_chalk(db), substs).intern(Interner),
)
}
@ -1389,7 +1387,7 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
let ctx =
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
if db.type_alias_data(t).is_extern {
Binders::empty(&Interner, TyKind::Foreign(crate::to_foreign_def_id(t)).intern(&Interner))
Binders::empty(Interner, TyKind::Foreign(crate::to_foreign_def_id(t)).intern(Interner))
} else {
let type_ref = &db.type_alias_data(t).type_ref;
let inner = ctx.lower_ty(type_ref.as_deref().unwrap_or(&TypeRef::Error));
@ -1452,7 +1450,7 @@ impl_from!(FunctionId, StructId, UnionId, EnumVariantId, ConstId, StaticId for V
/// namespace.
pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders<Ty> {
match def {
TyDefId::BuiltinType(it) => Binders::empty(&Interner, TyBuilder::builtin(it)),
TyDefId::BuiltinType(it) => Binders::empty(Interner, TyBuilder::builtin(it)),
TyDefId::AdtId(it) => type_for_adt(db, it),
TyDefId::TypeAliasId(it) => type_for_type_alias(db, it),
}
@ -1460,13 +1458,11 @@ pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders<Ty> {
pub(crate) fn ty_recover(db: &dyn HirDatabase, _cycle: &[String], def: &TyDefId) -> Binders<Ty> {
let generics = match *def {
TyDefId::BuiltinType(_) => {
return Binders::empty(&Interner, TyKind::Error.intern(&Interner))
}
TyDefId::BuiltinType(_) => return Binders::empty(Interner, TyKind::Error.intern(Interner)),
TyDefId::AdtId(it) => generics(db.upcast(), it.into()),
TyDefId::TypeAliasId(it) => generics(db.upcast(), it.into()),
};
make_binders(&generics, TyKind::Error.intern(&Interner))
make_binders(&generics, TyKind::Error.intern(Interner))
}
pub(crate) fn value_ty_query(db: &dyn HirDatabase, def: ValueTyDefId) -> Binders<Ty> {
@ -1509,7 +1505,7 @@ pub(crate) fn impl_self_ty_recover(
impl_id: &ImplId,
) -> Binders<Ty> {
let generics = generics(db.upcast(), (*impl_id).into());
make_binders(&generics, TyKind::Error.intern(&Interner))
make_binders(&generics, TyKind::Error.intern(Interner))
}
pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option<Binders<TraitRef>> {

View file

@ -54,7 +54,7 @@ impl TyFingerprint {
/// an `impl S`, but not `impl &S`. Hence, this will return `None` for
/// reference types and such.
pub fn for_inherent_impl(ty: &Ty) -> Option<TyFingerprint> {
let fp = match ty.kind(&Interner) {
let fp = match ty.kind(Interner) {
TyKind::Str => TyFingerprint::Str,
TyKind::Never => TyFingerprint::Never,
TyKind::Slice(..) => TyFingerprint::Slice,
@ -71,7 +71,7 @@ impl TyFingerprint {
/// Creates a TyFingerprint for looking up a trait impl.
pub fn for_trait_impl(ty: &Ty) -> Option<TyFingerprint> {
let fp = match ty.kind(&Interner) {
let fp = match ty.kind(Interner) {
TyKind::Str => TyFingerprint::Str,
TyKind::Never => TyFingerprint::Never,
TyKind::Slice(..) => TyFingerprint::Slice,
@ -83,7 +83,7 @@ impl TyFingerprint {
TyKind::Dyn(_) => ty.dyn_trait().map(TyFingerprint::Dyn)?,
TyKind::Ref(_, _, ty) => return TyFingerprint::for_trait_impl(ty),
TyKind::Tuple(_, subst) => {
let first_ty = subst.interned().get(0).map(|arg| arg.assert_ty_ref(&Interner));
let first_ty = subst.interned().get(0).map(|arg| arg.assert_ty_ref(Interner));
match first_ty {
Some(ty) => return TyFingerprint::for_trait_impl(ty),
None => TyFingerprint::Unit,
@ -96,7 +96,7 @@ impl TyFingerprint {
| TyKind::Generator(..)
| TyKind::GeneratorWitness(..) => TyFingerprint::Unnameable,
TyKind::Function(fn_ptr) => {
TyFingerprint::Function(fn_ptr.substitution.0.len(&Interner) as u32)
TyFingerprint::Function(fn_ptr.substitution.0.len(Interner) as u32)
}
TyKind::Alias(_)
| TyKind::Placeholder(_)
@ -384,7 +384,7 @@ pub fn def_crates(
let mod_to_crate_ids = |module: ModuleId| Some(iter::once(module.krate()).collect());
let lang_item_targets = match ty.kind(&Interner) {
let lang_item_targets = match ty.kind(Interner) {
TyKind::Adt(AdtId(def_id), _) => {
return mod_to_crate_ids(def_id.module(db.upcast()));
}
@ -603,7 +603,7 @@ fn iterate_method_candidates_with_autoref(
let refed = Canonical {
binders: receiver_ty.binders.clone(),
value: TyKind::Ref(Mutability::Not, static_lifetime(), receiver_ty.value.clone())
.intern(&Interner),
.intern(Interner),
};
iterate_method_candidates_by_receiver(
@ -620,7 +620,7 @@ fn iterate_method_candidates_with_autoref(
let ref_muted = Canonical {
binders: receiver_ty.binders,
value: TyKind::Ref(Mutability::Mut, static_lifetime(), receiver_ty.value).intern(&Interner),
value: TyKind::Ref(Mutability::Mut, static_lifetime(), receiver_ty.value).intern(Interner),
};
iterate_method_candidates_by_receiver(
@ -712,11 +712,11 @@ fn iterate_trait_method_candidates(
receiver_ty: Option<&Canonical<Ty>>,
callback: &mut dyn FnMut(&Canonical<Ty>, AssocItemId) -> ControlFlow<()>,
) -> ControlFlow<()> {
let receiver_is_array = matches!(self_ty.value.kind(&Interner), chalk_ir::TyKind::Array(..));
let receiver_is_array = matches!(self_ty.value.kind(Interner), chalk_ir::TyKind::Array(..));
// if ty is `dyn Trait`, the trait doesn't need to be in scope
let inherent_trait =
self_ty.value.dyn_trait().into_iter().flat_map(|t| all_super_traits(db.upcast(), t));
let env_traits = matches!(self_ty.value.kind(&Interner), TyKind::Placeholder(_))
let env_traits = matches!(self_ty.value.kind(Interner), TyKind::Placeholder(_))
// if we have `T: Trait` in the param env, the trait doesn't need to be in scope
.then(|| {
env.traits_in_scope_from_clauses(self_ty.value.clone())
@ -754,7 +754,7 @@ fn iterate_trait_method_candidates(
}
if !known_implemented {
let goal = generic_implements_goal(db, env.clone(), t, self_ty.clone());
if db.trait_solve(krate, goal.cast(&Interner)).is_none() {
if db.trait_solve(krate, goal.cast(Interner)).is_none() {
continue 'traits;
}
}
@ -773,12 +773,12 @@ fn filter_inherent_impls_for_self_ty<'i>(
// inherent methods on arrays are fingerprinted as [T; {unknown}], so we must also consider them when
// resolving a method call on an array with a known len
let array_impls = {
match self_ty.kind(&Interner) {
match self_ty.kind(Interner) {
TyKind::Array(parameters, array_len) if !array_len.is_unknown() => {
let unknown_array_len_ty =
TyKind::Array(parameters.clone(), consteval::usize_const(None));
Some(impls.for_self_ty(&unknown_array_len_ty.intern(&Interner)))
Some(impls.for_self_ty(&unknown_array_len_ty.intern(Interner)))
}
_ => None,
}
@ -890,7 +890,7 @@ pub fn resolve_indexing_op(
let deref_chain = autoderef_method_receiver(db, krate, ty);
for ty in deref_chain {
let goal = generic_implements_goal(db, env.clone(), index_trait, ty.clone());
if db.trait_solve(krate, goal.cast(&Interner)).is_some() {
if db.trait_solve(krate, goal.cast(Interner)).is_some() {
return Some(ty);
}
}
@ -905,7 +905,7 @@ fn is_transformed_receiver_ty_equal(transformed_receiver_ty: &Ty, receiver_ty: &
// a transformed receiver may be considered equal (and a valid method call candidate) if it is an array
// with an unknown (i.e. generic) length, and the receiver is an array with the same item type but a known len,
// this allows inherent methods on arrays to be considered valid resolution candidates
match (transformed_receiver_ty.kind(&Interner), receiver_ty.kind(&Interner)) {
match (transformed_receiver_ty.kind(Interner), receiver_ty.kind(Interner)) {
(
TyKind::Array(transformed_array_ty, transformed_array_len),
TyKind::Array(receiver_array_ty, receiver_array_len),
@ -974,21 +974,21 @@ pub(crate) fn inherent_impl_substs(
) -> Option<Substitution> {
// we create a var for each type parameter of the impl; we need to keep in
// mind here that `self_ty` might have vars of its own
let self_ty_vars = self_ty.binders.len(&Interner);
let self_ty_vars = self_ty.binders.len(Interner);
let vars = TyBuilder::subst_for_def(db, impl_id)
.fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty_vars)
.build();
let self_ty_with_vars = db.impl_self_ty(impl_id).substitute(&Interner, &vars);
let self_ty_with_vars = db.impl_self_ty(impl_id).substitute(Interner, &vars);
let mut kinds = self_ty.binders.interned().to_vec();
kinds.extend(
iter::repeat(chalk_ir::WithKind::new(
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
UniverseIndex::ROOT,
))
.take(vars.len(&Interner)),
.take(vars.len(Interner)),
);
let tys = Canonical {
binders: CanonicalVarKinds::from_iter(&Interner, kinds),
binders: CanonicalVarKinds::from_iter(Interner, kinds),
value: (self_ty_with_vars, self_ty.value.clone()),
};
let substs = super::infer::unify(db, env, &tys)?;
@ -998,7 +998,7 @@ pub(crate) fn inherent_impl_substs(
// Unknown, and in that case we want the result to contain Unknown in those
// places again.
let suffix =
Substitution::from_iter(&Interner, substs.iter(&Interner).cloned().skip(self_ty_vars));
Substitution::from_iter(Interner, substs.iter(Interner).cloned().skip(self_ty_vars));
Some(fallback_bound_vars(suffix, self_ty_vars))
}
@ -1007,9 +1007,9 @@ pub(crate) fn inherent_impl_substs(
fn fallback_bound_vars(s: Substitution, num_vars_to_keep: usize) -> Substitution {
crate::fold_free_vars(s, |bound, binders| {
if bound.index >= num_vars_to_keep && bound.debruijn == DebruijnIndex::INNERMOST {
TyKind::Error.intern(&Interner)
TyKind::Error.intern(Interner)
} else {
bound.shifted_in_from(binders).to_ty(&Interner)
bound.shifted_in_from(binders).to_ty(Interner)
}
})
}
@ -1036,7 +1036,7 @@ fn transform_receiver_ty(
ItemContainerId::ModuleId(_) | ItemContainerId::ExternBlockId(_) => unreachable!(),
};
let sig = db.callable_item_signature(function_id.into());
Some(sig.map(|s| s.params()[0].clone()).substitute(&Interner, &substs))
Some(sig.map(|s| s.params()[0].clone()).substitute(Interner, &substs))
}
pub fn implements_trait(
@ -1047,7 +1047,7 @@ pub fn implements_trait(
trait_: TraitId,
) -> bool {
let goal = generic_implements_goal(db, env, trait_, ty.clone());
let solution = db.trait_solve(krate, goal.cast(&Interner));
let solution = db.trait_solve(krate, goal.cast(Interner));
solution.is_some()
}
@ -1060,7 +1060,7 @@ pub fn implements_trait_unique(
trait_: TraitId,
) -> bool {
let goal = generic_implements_goal(db, env, trait_, ty.clone());
let solution = db.trait_solve(krate, goal.cast(&Interner));
let solution = db.trait_solve(krate, goal.cast(Interner));
matches!(solution, Some(crate::Solution::Unique(_)))
}
@ -1083,11 +1083,11 @@ fn generic_implements_goal(
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
UniverseIndex::ROOT,
))
.take(trait_ref.substitution.len(&Interner) - 1),
.take(trait_ref.substitution.len(Interner) - 1),
);
let obligation = trait_ref.cast(&Interner);
let obligation = trait_ref.cast(Interner);
Canonical {
binders: CanonicalVarKinds::from_iter(&Interner, kinds),
binders: CanonicalVarKinds::from_iter(Interner, kinds),
value: InEnvironment::new(&env.env, obligation),
}
}
@ -1099,11 +1099,10 @@ fn autoderef_method_receiver(
) -> Vec<Canonical<Ty>> {
let mut deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty).collect();
// As a last step, we can do array unsizing (that's the only unsizing that rustc does for method receivers!)
if let Some(TyKind::Array(parameters, _)) =
deref_chain.last().map(|ty| ty.value.kind(&Interner))
if let Some(TyKind::Array(parameters, _)) = deref_chain.last().map(|ty| ty.value.kind(Interner))
{
let kinds = deref_chain.last().unwrap().binders.clone();
let unsized_ty = TyKind::Slice(parameters.clone()).intern(&Interner);
let unsized_ty = TyKind::Slice(parameters.clone()).intern(Interner);
deref_chain.push(Canonical { value: unsized_ty, binders: kinds })
}
deref_chain

View file

@ -64,7 +64,7 @@ impl DebugContext<'_> {
_ => panic!("associated type not in trait"),
};
let trait_data = self.0.trait_data(trait_);
let params = projection_ty.substitution.as_slice(&Interner);
let params = projection_ty.substitution.as_slice(Interner);
write!(fmt, "<{:?} as {}", &params[0], trait_data.name,)?;
if params.len() > 1 {
write!(

View file

@ -51,7 +51,7 @@ impl TraitEnvironment {
TraitEnvironment {
krate,
traits_from_clauses: Vec::new(),
env: chalk_ir::Environment::new(&Interner),
env: chalk_ir::Environment::new(Interner),
}
}
@ -71,7 +71,7 @@ pub(crate) fn trait_solve_query(
krate: CrateId,
goal: Canonical<InEnvironment<Goal>>,
) -> Option<Solution> {
let _p = profile::span("trait_solve_query").detail(|| match &goal.value.goal.data(&Interner) {
let _p = profile::span("trait_solve_query").detail(|| match &goal.value.goal.data(Interner) {
GoalData::DomainGoal(DomainGoal::Holds(WhereClause::Implemented(it))) => {
db.trait_data(it.hir_trait_id()).name.to_string()
}
@ -83,9 +83,9 @@ pub(crate) fn trait_solve_query(
if let GoalData::DomainGoal(DomainGoal::Holds(WhereClause::AliasEq(AliasEq {
alias: AliasTy::Projection(projection_ty),
..
}))) = &goal.value.goal.data(&Interner)
}))) = &goal.value.goal.data(Interner)
{
if let TyKind::BoundVar(_) = projection_ty.self_type_parameter(&Interner).kind(&Interner) {
if let TyKind::BoundVar(_) = projection_ty.self_type_parameter(Interner).kind(Interner) {
// Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible
return Some(Solution::Ambig(Guidance::Unknown));
}

View file

@ -90,13 +90,13 @@ fn direct_super_trait_refs(db: &dyn HirDatabase, trait_ref: &TraitRef) -> Vec<Tr
// FIXME: how to correctly handle higher-ranked bounds here?
WhereClause::Implemented(tr) => Some(
tr.clone()
.shifted_out_to(&Interner, DebruijnIndex::ONE)
.shifted_out_to(Interner, DebruijnIndex::ONE)
.expect("FIXME unexpected higher-ranked trait bound"),
),
_ => None,
})
})
.map(|pred| pred.substitute(&Interner, &trait_ref.substitution))
.map(|pred| pred.substitute(Interner, &trait_ref.substitution))
.collect()
}
@ -270,19 +270,19 @@ impl Generics {
/// Returns a Substitution that replaces each parameter by a bound variable.
pub(crate) fn bound_vars_subst(&self, debruijn: DebruijnIndex) -> Substitution {
Substitution::from_iter(
&Interner,
Interner,
self.iter()
.enumerate()
.map(|(idx, _)| TyKind::BoundVar(BoundVar::new(debruijn, idx)).intern(&Interner)),
.map(|(idx, _)| TyKind::BoundVar(BoundVar::new(debruijn, idx)).intern(Interner)),
)
}
/// Returns a Substitution that replaces each parameter by itself (i.e. `Ty::Param`).
pub(crate) fn type_params_subst(&self, db: &dyn HirDatabase) -> Substitution {
Substitution::from_iter(
&Interner,
Interner,
self.iter().map(|(id, _)| {
TyKind::Placeholder(crate::to_placeholder_idx(db, id)).intern(&Interner)
TyKind::Placeholder(crate::to_placeholder_idx(db, id)).intern(Interner)
}),
)
}

View file

@ -16,14 +16,14 @@ pub trait TypeWalk {
impl TypeWalk for Ty {
fn walk(&self, f: &mut impl FnMut(&Ty)) {
match self.kind(&Interner) {
match self.kind(Interner) {
TyKind::Alias(AliasTy::Projection(p_ty)) => {
for t in p_ty.substitution.iter(&Interner) {
for t in p_ty.substitution.iter(Interner) {
t.walk(f);
}
}
TyKind::Alias(AliasTy::Opaque(o_ty)) => {
for t in o_ty.substitution.iter(&Interner) {
for t in o_ty.substitution.iter(Interner) {
t.walk(f);
}
}
@ -94,7 +94,7 @@ impl TypeWalk for GenericArg {
impl TypeWalk for Substitution {
fn walk(&self, f: &mut impl FnMut(&Ty)) {
for t in self.iter(&Interner) {
for t in self.iter(Interner) {
t.walk(f);
}
}