Reduce direct mk_ty
usage.
We use more specific `mk_*` functions in most places, might as well use them as much as possible.
This commit is contained in:
parent
6248bbbf26
commit
7a72560154
25 changed files with 92 additions and 82 deletions
|
@ -385,10 +385,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
calculate_debuginfo_offset(bx, local, &var, base);
|
calculate_debuginfo_offset(bx, local, &var, base);
|
||||||
|
|
||||||
// Create a variable which will be a pointer to the actual value
|
// Create a variable which will be a pointer to the actual value
|
||||||
let ptr_ty = bx.tcx().mk_ty(ty::RawPtr(ty::TypeAndMut {
|
let ptr_ty = bx
|
||||||
mutbl: mir::Mutability::Mut,
|
.tcx()
|
||||||
ty: place.layout.ty,
|
.mk_ptr(ty::TypeAndMut { mutbl: mir::Mutability::Mut, ty: place.layout.ty });
|
||||||
}));
|
|
||||||
let ptr_layout = bx.layout_of(ptr_ty);
|
let ptr_layout = bx.layout_of(ptr_ty);
|
||||||
let alloca = PlaceRef::alloca(bx, ptr_layout);
|
let alloca = PlaceRef::alloca(bx, ptr_layout);
|
||||||
bx.set_var_name(alloca.llval, &(var.name.to_string() + ".dbg.spill"));
|
bx.set_var_name(alloca.llval, &(var.name.to_string() + ".dbg.spill"));
|
||||||
|
|
|
@ -193,7 +193,7 @@ fn get_info_on_unsized_field<'tcx>(
|
||||||
|
|
||||||
// Have to adjust type for ty::Str
|
// Have to adjust type for ty::Str
|
||||||
let unsized_inner_ty = match unsized_inner_ty.kind() {
|
let unsized_inner_ty = match unsized_inner_ty.kind() {
|
||||||
ty::Str => tcx.mk_ty(ty::Uint(ty::UintTy::U8)),
|
ty::Str => tcx.types.u8,
|
||||||
_ => unsized_inner_ty,
|
_ => unsized_inner_ty,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ fn create_pointee_place<'tcx>(
|
||||||
|
|
||||||
let (unsized_inner_ty, num_elems) = get_info_on_unsized_field(ty, valtree, tcx);
|
let (unsized_inner_ty, num_elems) = get_info_on_unsized_field(ty, valtree, tcx);
|
||||||
let unsized_inner_ty = match unsized_inner_ty.kind() {
|
let unsized_inner_ty = match unsized_inner_ty.kind() {
|
||||||
ty::Str => tcx.mk_ty(ty::Uint(ty::UintTy::U8)),
|
ty::Str => tcx.types.u8,
|
||||||
_ => unsized_inner_ty,
|
_ => unsized_inner_ty,
|
||||||
};
|
};
|
||||||
let unsized_inner_ty_size =
|
let unsized_inner_ty_size =
|
||||||
|
|
|
@ -217,10 +217,10 @@ impl Qualif for CustomEq {
|
||||||
|
|
||||||
fn in_adt_inherently<'tcx>(
|
fn in_adt_inherently<'tcx>(
|
||||||
cx: &ConstCx<'_, 'tcx>,
|
cx: &ConstCx<'_, 'tcx>,
|
||||||
adt: AdtDef<'tcx>,
|
def: AdtDef<'tcx>,
|
||||||
substs: SubstsRef<'tcx>,
|
substs: SubstsRef<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let ty = cx.tcx.mk_ty(ty::Adt(adt, substs));
|
let ty = cx.tcx.mk_adt(def, substs);
|
||||||
!ty.is_structural_eq_shallow(cx.tcx)
|
!ty.is_structural_eq_shallow(cx.tcx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1250,7 +1250,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
//
|
//
|
||||||
// Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty`
|
// Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty`
|
||||||
// parameter to have a skipped binder.
|
// parameter to have a skipped binder.
|
||||||
let param_ty = tcx.mk_ty(ty::Alias(ty::Projection, projection_ty.skip_binder()));
|
let param_ty = tcx.mk_alias(ty::Projection, projection_ty.skip_binder());
|
||||||
self.add_bounds(param_ty, ast_bounds.iter(), bounds, candidate.bound_vars());
|
self.add_bounds(param_ty, ast_bounds.iter(), bounds, candidate.bound_vars());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2930,7 +2930,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
tcx.mk_ty(ty::Array(self.ast_ty_to_ty(ty), length))
|
tcx.mk_array_with_const_len(self.ast_ty_to_ty(ty), length)
|
||||||
}
|
}
|
||||||
hir::TyKind::Typeof(e) => {
|
hir::TyKind::Typeof(e) => {
|
||||||
let ty_erased = tcx.type_of(e.def_id);
|
let ty_erased = tcx.type_of(e.def_id);
|
||||||
|
|
|
@ -1927,10 +1927,10 @@ pub(super) fn check_type_bounds<'tcx>(
|
||||||
let kind = ty::BoundTyKind::Param(param.def_id, param.name);
|
let kind = ty::BoundTyKind::Param(param.def_id, param.name);
|
||||||
let bound_var = ty::BoundVariableKind::Ty(kind);
|
let bound_var = ty::BoundVariableKind::Ty(kind);
|
||||||
bound_vars.push(bound_var);
|
bound_vars.push(bound_var);
|
||||||
tcx.mk_ty(ty::Bound(
|
tcx.mk_bound(
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundTy { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind },
|
ty::BoundTy { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind },
|
||||||
))
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
GenericParamDefKind::Lifetime => {
|
GenericParamDefKind::Lifetime => {
|
||||||
|
|
|
@ -603,8 +603,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
|
||||||
// our example, the type was `Self`, which will also be
|
// our example, the type was `Self`, which will also be
|
||||||
// `Self` in the GAT.
|
// `Self` in the GAT.
|
||||||
let ty_param = gat_generics.param_at(*ty_idx, tcx);
|
let ty_param = gat_generics.param_at(*ty_idx, tcx);
|
||||||
let ty_param = tcx
|
let ty_param = tcx.mk_ty_param(ty_param.index, ty_param.name);
|
||||||
.mk_ty(ty::Param(ty::ParamTy { index: ty_param.index, name: ty_param.name }));
|
|
||||||
// Same for the region. In our example, 'a corresponds
|
// Same for the region. In our example, 'a corresponds
|
||||||
// to the 'me parameter.
|
// to the 'me parameter.
|
||||||
let region_param = gat_generics.param_at(*region_a_idx, tcx);
|
let region_param = gat_generics.param_at(*region_a_idx, tcx);
|
||||||
|
|
|
@ -264,9 +264,7 @@ fn check_lang_start_fn<'tcx>(
|
||||||
// for example `start`'s generic should be a type parameter
|
// for example `start`'s generic should be a type parameter
|
||||||
let generics = tcx.generics_of(def_id);
|
let generics = tcx.generics_of(def_id);
|
||||||
let fn_generic = generics.param_at(0, tcx);
|
let fn_generic = generics.param_at(0, tcx);
|
||||||
let generic_tykind =
|
let generic_ty = tcx.mk_ty_param(fn_generic.index, fn_generic.name);
|
||||||
ty::Param(ty::ParamTy { index: fn_generic.index, name: fn_generic.name });
|
|
||||||
let generic_ty = tcx.mk_ty(generic_tykind);
|
|
||||||
let expected_fn_sig =
|
let expected_fn_sig =
|
||||||
tcx.mk_fn_sig([].iter(), &generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
|
tcx.mk_fn_sig([].iter(), &generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
|
||||||
let expected_ty = tcx.mk_fn_ptr(Binder::dummy(expected_fn_sig));
|
let expected_ty = tcx.mk_fn_ptr(Binder::dummy(expected_fn_sig));
|
||||||
|
|
|
@ -1429,7 +1429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
self.check_repeat_element_needs_copy_bound(element, count, element_ty);
|
self.check_repeat_element_needs_copy_bound(element, count, element_ty);
|
||||||
|
|
||||||
tcx.mk_ty(ty::Array(t, count))
|
tcx.mk_array_with_const_len(t, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_repeat_element_needs_copy_bound(
|
fn check_repeat_element_needs_copy_bound(
|
||||||
|
|
|
@ -1296,7 +1296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let element_tys = tcx.mk_type_list(element_tys_iter);
|
let element_tys = tcx.mk_type_list(element_tys_iter);
|
||||||
let pat_ty = tcx.mk_ty(ty::Tuple(element_tys));
|
let pat_ty = tcx.intern_tup(element_tys);
|
||||||
if let Some(mut err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, ti) {
|
if let Some(mut err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, ti) {
|
||||||
let reported = err.emit();
|
let reported = err.emit();
|
||||||
// Walk subpatterns with an expected type of `err` in this case to silence
|
// Walk subpatterns with an expected type of `err` in this case to silence
|
||||||
|
|
|
@ -752,7 +752,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
||||||
self.fold_ty(bound_to)
|
self.fold_ty(bound_to)
|
||||||
} else {
|
} else {
|
||||||
let var = self.canonical_var(info, ty_var.into());
|
let var = self.canonical_var(info, ty_var.into());
|
||||||
self.tcx().mk_ty(ty::Bound(self.binder_index, var.into()))
|
self.tcx().mk_bound(self.binder_index, var.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, name }) => {
|
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, name }) => {
|
||||||
let universe_mapped = universe_map(universe);
|
let universe_mapped = universe_map(universe);
|
||||||
let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, name };
|
let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, name };
|
||||||
self.tcx.mk_ty(ty::Placeholder(placeholder_mapped)).into()
|
self.tcx.mk_placeholder(placeholder_mapped).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
CanonicalVarKind::Region(ui) => self
|
CanonicalVarKind::Region(ui) => self
|
||||||
|
|
|
@ -88,10 +88,10 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
types: &mut |bound_ty: ty::BoundTy| {
|
types: &mut |bound_ty: ty::BoundTy| {
|
||||||
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
|
self.tcx.mk_placeholder(ty::PlaceholderType {
|
||||||
universe: next_universe,
|
universe: next_universe,
|
||||||
name: bound_ty.kind,
|
name: bound_ty.kind,
|
||||||
}))
|
})
|
||||||
},
|
},
|
||||||
consts: &mut |bound_var: ty::BoundVar, ty| {
|
consts: &mut |bound_var: ty::BoundVar, ty| {
|
||||||
self.tcx
|
self.tcx
|
||||||
|
|
|
@ -2071,14 +2071,14 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
|
||||||
|
|
||||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
if let ty::Infer(_) = t.kind() {
|
if let ty::Infer(_) = t.kind() {
|
||||||
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
|
self.tcx.mk_placeholder(ty::PlaceholderType {
|
||||||
universe: ty::UniverseIndex::ROOT,
|
universe: ty::UniverseIndex::ROOT,
|
||||||
name: ty::BoundTyKind::Anon({
|
name: ty::BoundTyKind::Anon({
|
||||||
let idx = self.idx;
|
let idx = self.idx;
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
idx
|
idx
|
||||||
}),
|
}),
|
||||||
}))
|
})
|
||||||
} else {
|
} else {
|
||||||
t.super_fold_with(self)
|
t.super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,9 +345,9 @@ impl<'tcx> CanonicalVarValues<'tcx> {
|
||||||
var_values: tcx.mk_substs(infos.iter().enumerate().map(
|
var_values: tcx.mk_substs(infos.iter().enumerate().map(
|
||||||
|(i, info)| -> ty::GenericArg<'tcx> {
|
|(i, info)| -> ty::GenericArg<'tcx> {
|
||||||
match info.kind {
|
match info.kind {
|
||||||
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => tcx
|
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => {
|
||||||
.mk_ty(ty::Bound(ty::INNERMOST, ty::BoundVar::from_usize(i).into()))
|
tcx.mk_bound(ty::INNERMOST, ty::BoundVar::from_usize(i).into()).into()
|
||||||
.into(),
|
}
|
||||||
CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
|
CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
|
||||||
let br = ty::BoundRegion {
|
let br = ty::BoundRegion {
|
||||||
var: ty::BoundVar::from_usize(i),
|
var: ty::BoundVar::from_usize(i),
|
||||||
|
|
|
@ -162,7 +162,7 @@ impl<'tcx> Rvalue<'tcx> {
|
||||||
match *self {
|
match *self {
|
||||||
Rvalue::Use(ref operand) => operand.ty(local_decls, tcx),
|
Rvalue::Use(ref operand) => operand.ty(local_decls, tcx),
|
||||||
Rvalue::Repeat(ref operand, count) => {
|
Rvalue::Repeat(ref operand, count) => {
|
||||||
tcx.mk_ty(ty::Array(operand.ty(local_decls, tcx), count))
|
tcx.mk_array_with_const_len(operand.ty(local_decls, tcx), count)
|
||||||
}
|
}
|
||||||
Rvalue::ThreadLocalRef(did) => {
|
Rvalue::ThreadLocalRef(did) => {
|
||||||
let static_ty = tcx.type_of(did);
|
let static_ty = tcx.type_of(did);
|
||||||
|
|
|
@ -1636,6 +1636,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
if *r == kind { r } else { self.mk_region(kind) }
|
if *r == kind { r } else { self.mk_region(kind) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Avoid this in favour of more specific `mk_*` methods, where possible.
|
||||||
#[allow(rustc::usage_of_ty_tykind)]
|
#[allow(rustc::usage_of_ty_tykind)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> {
|
pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> {
|
||||||
|
@ -1787,6 +1788,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.mk_ty(Array(ty, ty::Const::from_usize(self, n)))
|
self.mk_ty(Array(ty, ty::Const::from_usize(self, n)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn mk_array_with_const_len(self, ty: Ty<'tcx>, ct: Const<'tcx>) -> Ty<'tcx> {
|
||||||
|
self.mk_ty(Array(ty, ct))
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_slice(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
pub fn mk_slice(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
self.mk_ty(Slice(ty))
|
self.mk_ty(Slice(ty))
|
||||||
|
@ -1862,7 +1868,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
item_def_id: DefId,
|
item_def_id: DefId,
|
||||||
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
self.mk_ty(Alias(ty::Projection, self.mk_alias_ty(item_def_id, substs)))
|
self.mk_alias(ty::Projection, self.mk_alias_ty(item_def_id, substs))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1970,9 +1976,24 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn mk_bound(self, index: ty::DebruijnIndex, bound_ty: ty::BoundTy) -> Ty<'tcx> {
|
||||||
|
self.mk_ty(Bound(index, bound_ty))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn mk_placeholder(self, placeholder: ty::PlaceholderType) -> Ty<'tcx> {
|
||||||
|
self.mk_ty(Placeholder(placeholder))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn mk_alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> {
|
||||||
|
self.mk_ty(Alias(kind, alias_ty))
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
||||||
self.mk_ty(Alias(ty::Opaque, self.mk_alias_ty(def_id, substs)))
|
self.mk_alias(ty::Opaque, self.mk_alias_ty(def_id, substs))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
|
pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
|
||||||
|
|
|
@ -562,10 +562,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
types: &mut |t: ty::BoundTy| {
|
types: &mut |t: ty::BoundTy| {
|
||||||
self.mk_ty(ty::Bound(
|
self.mk_bound(ty::INNERMOST, ty::BoundTy { var: shift_bv(t.var), kind: t.kind })
|
||||||
ty::INNERMOST,
|
|
||||||
ty::BoundTy { var: shift_bv(t.var), kind: t.kind },
|
|
||||||
))
|
|
||||||
},
|
},
|
||||||
consts: &mut |c, ty: Ty<'tcx>| {
|
consts: &mut |c, ty: Ty<'tcx>| {
|
||||||
self.mk_const(ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)), ty)
|
self.mk_const(ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)), ty)
|
||||||
|
@ -614,7 +611,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
ty::BoundVariableKind::Ty(ty::BoundTyKind::Anon(index as u32))
|
ty::BoundVariableKind::Ty(ty::BoundTyKind::Anon(index as u32))
|
||||||
})
|
})
|
||||||
.expect_ty();
|
.expect_ty();
|
||||||
self.tcx.mk_ty(ty::Bound(ty::INNERMOST, BoundTy { var, kind }))
|
self.tcx.mk_bound(ty::INNERMOST, BoundTy { var, kind })
|
||||||
}
|
}
|
||||||
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx> {
|
||||||
let entry = self.map.entry(bv);
|
let entry = self.map.entry(bv);
|
||||||
|
@ -684,7 +681,7 @@ impl<'tcx> TypeFolder<'tcx> for Shifter<'tcx> {
|
||||||
match *ty.kind() {
|
match *ty.kind() {
|
||||||
ty::Bound(debruijn, bound_ty) if debruijn >= self.current_index => {
|
ty::Bound(debruijn, bound_ty) if debruijn >= self.current_index => {
|
||||||
let debruijn = debruijn.shifted_in(self.amount);
|
let debruijn = debruijn.shifted_in(self.amount);
|
||||||
self.tcx.mk_ty(ty::Bound(debruijn, bound_ty))
|
self.tcx.mk_bound(debruijn, bound_ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ if ty.has_vars_bound_at_or_above(self.current_index) => ty.super_fold_with(self),
|
_ if ty.has_vars_bound_at_or_above(self.current_index) => ty.super_fold_with(self),
|
||||||
|
|
|
@ -502,7 +502,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
||||||
(&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => {
|
(&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => {
|
||||||
let t = relation.relate(a_t, b_t)?;
|
let t = relation.relate(a_t, b_t)?;
|
||||||
match relation.relate(sz_a, sz_b) {
|
match relation.relate(sz_a, sz_b) {
|
||||||
Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
|
Ok(sz) => Ok(tcx.mk_array_with_const_len(t, sz)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Check whether the lengths are both concrete/known values,
|
// Check whether the lengths are both concrete/known values,
|
||||||
// but are unequal, for better diagnostics.
|
// but are unequal, for better diagnostics.
|
||||||
|
|
|
@ -1171,7 +1171,7 @@ impl<'tcx> FallibleTypeFolder<'tcx> for SkipBindersAt<'tcx> {
|
||||||
if index == self.index {
|
if index == self.index {
|
||||||
Err(())
|
Err(())
|
||||||
} else {
|
} else {
|
||||||
Ok(self.tcx().mk_ty(ty::Bound(index.shifted_out(1), bv)))
|
Ok(self.tcx().mk_bound(index.shifted_out(1), bv))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ty.try_super_fold_with(self)
|
ty.try_super_fold_with(self)
|
||||||
|
@ -1260,7 +1260,7 @@ impl<'tcx> AliasTy<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
||||||
tcx.mk_ty(ty::Alias(self.kind(tcx), self))
|
tcx.mk_alias(self.kind(tcx), self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3572,7 +3572,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
{
|
{
|
||||||
type_diffs = vec![
|
type_diffs = vec![
|
||||||
Sorts(ty::error::ExpectedFound {
|
Sorts(ty::error::ExpectedFound {
|
||||||
expected: self.tcx.mk_ty(ty::Alias(ty::Projection, where_pred.skip_binder().projection_ty)),
|
expected: self.tcx.mk_alias(ty::Projection, where_pred.skip_binder().projection_ty),
|
||||||
found,
|
found,
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
|
@ -785,7 +785,7 @@ impl<'tcx> TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> {
|
||||||
let universe = self.universe_for(debruijn);
|
let universe = self.universe_for(debruijn);
|
||||||
let p = ty::PlaceholderType { universe, name: bound_ty.kind };
|
let p = ty::PlaceholderType { universe, name: bound_ty.kind };
|
||||||
self.mapped_types.insert(p, bound_ty);
|
self.mapped_types.insert(p, bound_ty);
|
||||||
self.infcx.tcx.mk_ty(ty::Placeholder(p))
|
self.infcx.tcx.mk_placeholder(p)
|
||||||
}
|
}
|
||||||
_ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self),
|
_ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self),
|
||||||
_ => t,
|
_ => t,
|
||||||
|
@ -915,7 +915,7 @@ impl<'tcx> TypeFolder<'tcx> for PlaceholderReplacer<'_, 'tcx> {
|
||||||
let db = ty::DebruijnIndex::from_usize(
|
let db = ty::DebruijnIndex::from_usize(
|
||||||
self.universe_indices.len() - index + self.current_index.as_usize() - 1,
|
self.universe_indices.len() - index + self.current_index.as_usize() - 1,
|
||||||
);
|
);
|
||||||
self.tcx().mk_ty(ty::Bound(db, *replace_var))
|
self.tcx().mk_bound(db, *replace_var)
|
||||||
}
|
}
|
||||||
None => ty,
|
None => ty,
|
||||||
}
|
}
|
||||||
|
|
|
@ -527,13 +527,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
let kind = ty::BoundTyKind::Param(param.def_id, param.name);
|
let kind = ty::BoundTyKind::Param(param.def_id, param.name);
|
||||||
let bound_var = ty::BoundVariableKind::Ty(kind);
|
let bound_var = ty::BoundVariableKind::Ty(kind);
|
||||||
bound_vars.push(bound_var);
|
bound_vars.push(bound_var);
|
||||||
tcx.mk_ty(ty::Bound(
|
tcx.mk_bound(
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundTy {
|
ty::BoundTy {
|
||||||
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
|
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
|
||||||
kind,
|
kind,
|
||||||
},
|
},
|
||||||
))
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
GenericParamDefKind::Lifetime => {
|
GenericParamDefKind::Lifetime => {
|
||||||
|
|
|
@ -588,10 +588,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||||
_id: chalk_ir::OpaqueTyId<RustInterner<'tcx>>,
|
_id: chalk_ir::OpaqueTyId<RustInterner<'tcx>>,
|
||||||
) -> chalk_ir::Ty<RustInterner<'tcx>> {
|
) -> chalk_ir::Ty<RustInterner<'tcx>> {
|
||||||
// FIXME(chalk): actually get hidden ty
|
// FIXME(chalk): actually get hidden ty
|
||||||
self.interner
|
self.interner.tcx.types.unit.lower_into(self.interner)
|
||||||
.tcx
|
|
||||||
.mk_ty(ty::Tuple(self.interner.tcx.intern_type_list(&[])))
|
|
||||||
.lower_into(self.interner)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn closure_kind(
|
fn closure_kind(
|
||||||
|
@ -721,13 +718,13 @@ impl<'tcx> chalk_ir::UnificationDatabase<RustInterner<'tcx>> for RustIrDatabase<
|
||||||
fn bound_vars_for_item(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> {
|
fn bound_vars_for_item(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> {
|
||||||
InternalSubsts::for_item(tcx, def_id, |param, substs| match param.kind {
|
InternalSubsts::for_item(tcx, def_id, |param, substs| match param.kind {
|
||||||
ty::GenericParamDefKind::Type { .. } => tcx
|
ty::GenericParamDefKind::Type { .. } => tcx
|
||||||
.mk_ty(ty::Bound(
|
.mk_bound(
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundTy {
|
ty::BoundTy {
|
||||||
var: ty::BoundVar::from(param.index),
|
var: ty::BoundVar::from(param.index),
|
||||||
kind: ty::BoundTyKind::Param(param.def_id, param.name),
|
kind: ty::BoundTyKind::Param(param.def_id, param.name),
|
||||||
},
|
},
|
||||||
))
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
|
||||||
ty::GenericParamDefKind::Lifetime => {
|
ty::GenericParamDefKind::Lifetime => {
|
||||||
|
@ -790,10 +787,9 @@ impl<'tcx> ty::TypeFolder<'tcx> for ReplaceOpaqueTyFolder<'tcx> {
|
||||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) = *ty.kind() {
|
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) = *ty.kind() {
|
||||||
if def_id == self.opaque_ty_id.0 && substs == self.identity_substs {
|
if def_id == self.opaque_ty_id.0 && substs == self.identity_substs {
|
||||||
return self.tcx.mk_ty(ty::Bound(
|
return self
|
||||||
self.binder_index,
|
.tcx
|
||||||
ty::BoundTy::from(ty::BoundVar::from_u32(0)),
|
.mk_bound(self.binder_index, ty::BoundTy::from(ty::BoundVar::from_u32(0)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty
|
ty
|
||||||
|
|
|
@ -677,11 +677,11 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
|
||||||
// shifted in by one so that they are still escaping.
|
// shifted in by one so that they are still escaping.
|
||||||
let predicates = ty::fold::shift_vars(interner.tcx, self, 1);
|
let predicates = ty::fold::shift_vars(interner.tcx, self, 1);
|
||||||
|
|
||||||
let self_ty = interner.tcx.mk_ty(ty::Bound(
|
let self_ty = interner.tcx.mk_bound(
|
||||||
// This is going to be wrapped in a binder
|
// This is going to be wrapped in a binder
|
||||||
ty::DebruijnIndex::from_usize(1),
|
ty::DebruijnIndex::from_usize(1),
|
||||||
ty::BoundTy { var: ty::BoundVar::from_usize(0), kind: ty::BoundTyKind::Anon(0) },
|
ty::BoundTy { var: ty::BoundVar::from_usize(0), kind: ty::BoundTyKind::Anon(0) },
|
||||||
));
|
);
|
||||||
let where_clauses = predicates.into_iter().map(|predicate| {
|
let where_clauses = predicates.into_iter().map(|predicate| {
|
||||||
let (predicate, binders, _named_regions) =
|
let (predicate, binders, _named_regions) =
|
||||||
collect_bound_vars(interner, interner.tcx, predicate);
|
collect_bound_vars(interner, interner.tcx, predicate);
|
||||||
|
@ -1077,18 +1077,18 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
|
||||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
match *t.kind() {
|
match *t.kind() {
|
||||||
ty::Param(param) => match self.list.iter().position(|r| r == ¶m) {
|
ty::Param(param) => match self.list.iter().position(|r| r == ¶m) {
|
||||||
Some(idx) => self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
|
Some(idx) => self.tcx.mk_placeholder(ty::PlaceholderType {
|
||||||
universe: ty::UniverseIndex::from_usize(0),
|
universe: ty::UniverseIndex::from_usize(0),
|
||||||
name: ty::BoundTyKind::Anon(idx as u32),
|
name: ty::BoundTyKind::Anon(idx as u32),
|
||||||
})),
|
}),
|
||||||
None => {
|
None => {
|
||||||
self.list.push(param);
|
self.list.push(param);
|
||||||
let idx = self.list.len() - 1 + self.next_ty_placeholder;
|
let idx = self.list.len() - 1 + self.next_ty_placeholder;
|
||||||
self.params.insert(idx as u32, param);
|
self.params.insert(idx as u32, param);
|
||||||
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
|
self.tcx.mk_placeholder(ty::PlaceholderType {
|
||||||
universe: ty::UniverseIndex::from_usize(0),
|
universe: ty::UniverseIndex::from_usize(0),
|
||||||
name: ty::BoundTyKind::Anon(idx as u32),
|
name: ty::BoundTyKind::Anon(idx as u32),
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => t.super_fold_with(self),
|
_ => t.super_fold_with(self),
|
||||||
|
@ -1147,7 +1147,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseParamsSubstitutor<'tcx> {
|
||||||
match *t.kind() {
|
match *t.kind() {
|
||||||
ty::Placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::ROOT, name }) => {
|
ty::Placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::ROOT, name }) => {
|
||||||
match self.params.get(&name.expect_anon()) {
|
match self.params.get(&name.expect_anon()) {
|
||||||
Some(param) => self.tcx.mk_ty(ty::Param(*param)),
|
Some(&ty::ParamTy { index, name }) => self.tcx.mk_ty_param(index, name),
|
||||||
None => t,
|
None => t,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -516,27 +516,27 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
|
||||||
// FIXME: Only simple types are supported here, see if we can support
|
// FIXME: Only simple types are supported here, see if we can support
|
||||||
// other types such as Tuple, Array, Slice, etc.
|
// other types such as Tuple, Array, Slice, etc.
|
||||||
// See https://github.com/rust-lang/rust/issues/90703#issuecomment-1004263455
|
// See https://github.com/rust-lang/rust/issues/90703#issuecomment-1004263455
|
||||||
Some(tcx.mk_ty(match prim {
|
Some(match prim {
|
||||||
Bool => ty::Bool,
|
Bool => tcx.types.bool,
|
||||||
Str => ty::Str,
|
Str => tcx.types.str_,
|
||||||
Char => ty::Char,
|
Char => tcx.types.char,
|
||||||
Never => ty::Never,
|
Never => tcx.types.never,
|
||||||
I8 => ty::Int(ty::IntTy::I8),
|
I8 => tcx.types.i8,
|
||||||
I16 => ty::Int(ty::IntTy::I16),
|
I16 => tcx.types.i16,
|
||||||
I32 => ty::Int(ty::IntTy::I32),
|
I32 => tcx.types.i32,
|
||||||
I64 => ty::Int(ty::IntTy::I64),
|
I64 => tcx.types.i64,
|
||||||
I128 => ty::Int(ty::IntTy::I128),
|
I128 => tcx.types.i128,
|
||||||
Isize => ty::Int(ty::IntTy::Isize),
|
Isize => tcx.types.isize,
|
||||||
F32 => ty::Float(ty::FloatTy::F32),
|
F32 => tcx.types.f32,
|
||||||
F64 => ty::Float(ty::FloatTy::F64),
|
F64 => tcx.types.f64,
|
||||||
U8 => ty::Uint(ty::UintTy::U8),
|
U8 => tcx.types.u8,
|
||||||
U16 => ty::Uint(ty::UintTy::U16),
|
U16 => tcx.types.u16,
|
||||||
U32 => ty::Uint(ty::UintTy::U32),
|
U32 => tcx.types.u32,
|
||||||
U64 => ty::Uint(ty::UintTy::U64),
|
U64 => tcx.types.u64,
|
||||||
U128 => ty::Uint(ty::UintTy::U128),
|
U128 => tcx.types.u128,
|
||||||
Usize => ty::Uint(ty::UintTy::Usize),
|
Usize => tcx.types.usize,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve an associated item, returning its containing page's `Res`
|
/// Resolve an associated item, returning its containing page's `Res`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue