1
Fork 0

Auto merge of #113377 - BoxyUwU:move_ty_ctors_to_ty, r=compiler-errors

Move `TyCtxt::mk_x` to `Ty::new_x` where applicable

Part of rust-lang/compiler-team#616

turns out there's a lot of places we construct `Ty` this is a ridiculously huge PR :S

r? `@oli-obk`
This commit is contained in:
bors 2023-07-06 08:10:42 +00:00
commit 4dd1719b34
165 changed files with 1388 additions and 1187 deletions

View file

@ -1050,7 +1050,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Some(def_id) => type_known_to_meet_bound_modulo_regions( Some(def_id) => type_known_to_meet_bound_modulo_regions(
&self.infcx, &self.infcx,
self.param_env, self.param_env,
tcx.mk_imm_ref(tcx.lifetimes.re_erased, ty), Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, ty),
def_id, def_id,
), ),
_ => false, _ => false,

View file

@ -508,7 +508,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let generic_arg = substs[param_index as usize]; let generic_arg = substs[param_index as usize];
let identity_substs = let identity_substs =
InternalSubsts::identity_for_item(self.infcx.tcx, adt.did()); InternalSubsts::identity_for_item(self.infcx.tcx, adt.did());
let base_ty = self.infcx.tcx.mk_adt(*adt, identity_substs); let base_ty = Ty::new_adt(self.infcx.tcx, *adt, identity_substs);
let base_generic_arg = identity_substs[param_index as usize]; let base_generic_arg = identity_substs[param_index as usize];
let adt_desc = adt.descr(); let adt_desc = adt.descr();

View file

@ -1139,7 +1139,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
_ => arg.fold_with(self), _ => arg.fold_with(self),
} }
}); });
tcx.mk_opaque(def_id, tcx.mk_substs_from_iter(substs)) Ty::new_opaque(tcx, def_id, tcx.mk_substs_from_iter(substs))
} }
} }

View file

@ -158,7 +158,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
) )
.emit() .emit()
}); });
prev.ty = infcx.tcx.ty_error(guar); prev.ty = Ty::new_error(infcx.tcx, guar);
} }
// Pick a better span if there is one. // Pick a better span if there is one.
// FIXME(oli-obk): collect multiple spans for better diagnostics down the road. // FIXME(oli-obk): collect multiple spans for better diagnostics down the road.
@ -248,13 +248,13 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
instantiated_ty: OpaqueHiddenType<'tcx>, instantiated_ty: OpaqueHiddenType<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
if let Some(e) = self.tainted_by_errors() { if let Some(e) = self.tainted_by_errors() {
return self.tcx.ty_error(e); return Ty::new_error(self.tcx, e);
} }
if let Err(guar) = if let Err(guar) =
check_opaque_type_parameter_valid(self.tcx, opaque_type_key, instantiated_ty.span) check_opaque_type_parameter_valid(self.tcx, opaque_type_key, instantiated_ty.span)
{ {
return self.tcx.ty_error(guar); return Ty::new_error(self.tcx, guar);
} }
let definition_ty = instantiated_ty let definition_ty = instantiated_ty
@ -271,7 +271,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
definition_ty, definition_ty,
) { ) {
Ok(hidden_ty) => hidden_ty, Ok(hidden_ty) => hidden_ty,
Err(guar) => self.tcx.ty_error(guar), Err(guar) => Ty::new_error(self.tcx, guar),
} }
} }
} }
@ -313,7 +313,7 @@ fn check_opaque_type_well_formed<'tcx>(
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without // Require that the hidden type actually fulfills all the bounds of the opaque type, even without
// the bounds that the function supplies. // the bounds that the function supplies.
let opaque_ty = tcx.mk_opaque(def_id.to_def_id(), identity_substs); let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), identity_substs);
ocx.eq(&ObligationCause::misc(definition_span, def_id), param_env, opaque_ty, definition_ty) ocx.eq(&ObligationCause::misc(definition_span, def_id), param_env, opaque_ty, definition_ty)
.map_err(|err| { .map_err(|err| {
infcx infcx

View file

@ -245,7 +245,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
.and(type_op::normalize::Normalize::new(ty)) .and(type_op::normalize::Normalize::new(ty))
.fully_perform(self.infcx, span) .fully_perform(self.infcx, span)
.unwrap_or_else(|guar| TypeOpOutput { .unwrap_or_else(|guar| TypeOpOutput {
output: self.infcx.tcx.ty_error(guar), output: Ty::new_error(self.infcx.tcx, guar),
constraints: None, constraints: None,
error_info: None, error_info: None,
}); });

View file

@ -237,7 +237,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
decl.hidden_type.span, decl.hidden_type.span,
format!("could not resolve {:#?}", hidden_type.ty.kind()), format!("could not resolve {:#?}", hidden_type.ty.kind()),
); );
hidden_type.ty = infcx.tcx.ty_error(reported); hidden_type.ty = Ty::new_error(infcx.tcx, reported);
} }
(opaque_type_key, hidden_type) (opaque_type_key, hidden_type)
@ -520,7 +520,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
for elem in place.projection.iter() { for elem in place.projection.iter() {
if place_ty.variant_index.is_none() { if place_ty.variant_index.is_none() {
if let Err(guar) = place_ty.ty.error_reported() { if let Err(guar) = place_ty.ty.error_reported() {
return PlaceTy::from_ty(self.tcx().ty_error(guar)); return PlaceTy::from_ty(Ty::new_error(self.tcx(), guar));
} }
} }
place_ty = self.sanitize_projection(place_ty, elem, place, location, context); place_ty = self.sanitize_projection(place_ty, elem, place, location, context);
@ -656,7 +656,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
PlaceTy::from_ty(match base_ty.kind() { PlaceTy::from_ty(match base_ty.kind() {
ty::Array(inner, _) => { ty::Array(inner, _) => {
assert!(!from_end, "array subslices should not use from_end"); assert!(!from_end, "array subslices should not use from_end");
tcx.mk_array(*inner, to - from) Ty::new_array(tcx, *inner, to - from)
} }
ty::Slice(..) => { ty::Slice(..) => {
assert!(from_end, "slice subslices should use from_end"); assert!(from_end, "slice subslices should use from_end");
@ -749,7 +749,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
} }
fn error(&mut self) -> Ty<'tcx> { fn error(&mut self) -> Ty<'tcx> {
self.tcx().ty_error_misc() Ty::new_misc_error(self.tcx())
} }
fn get_ambient_variance(&self, context: PlaceContext) -> ty::Variance { fn get_ambient_variance(&self, context: PlaceContext) -> ty::Variance {
@ -1918,7 +1918,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// and hence may contain unnormalized results. // and hence may contain unnormalized results.
let fn_sig = self.normalize(fn_sig, location); let fn_sig = self.normalize(fn_sig, location);
let ty_fn_ptr_from = tcx.mk_fn_ptr(fn_sig); let ty_fn_ptr_from = Ty::new_fn_ptr(tcx, fn_sig);
if let Err(terr) = self.eq_types( if let Err(terr) = self.eq_types(
*ty, *ty,
@ -1942,7 +1942,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
ty::Closure(_, substs) => substs.as_closure().sig(), ty::Closure(_, substs) => substs.as_closure().sig(),
_ => bug!(), _ => bug!(),
}; };
let ty_fn_ptr_from = tcx.mk_fn_ptr(tcx.signature_unclosure(sig, *unsafety)); let ty_fn_ptr_from =
Ty::new_fn_ptr(tcx, tcx.signature_unclosure(sig, *unsafety));
if let Err(terr) = self.eq_types( if let Err(terr) = self.eq_types(
*ty, *ty,

View file

@ -685,7 +685,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
assert_eq!(self.mir_def.to_def_id(), def_id); assert_eq!(self.mir_def.to_def_id(), def_id);
let resume_ty = substs.as_generator().resume_ty(); let resume_ty = substs.as_generator().resume_ty();
let output = substs.as_generator().return_ty(); let output = substs.as_generator().return_ty();
let generator_ty = tcx.mk_generator(def_id, substs, movability); let generator_ty = Ty::new_generator(tcx, def_id, substs, movability);
let inputs_and_output = let inputs_and_output =
self.infcx.tcx.mk_type_list(&[generator_ty, resume_ty, output]); self.infcx.tcx.mk_type_list(&[generator_ty, resume_ty, output]);
ty::Binder::dummy(inputs_and_output) ty::Binder::dummy(inputs_and_output)

View file

@ -665,7 +665,8 @@ pub(crate) fn codegen_drop<'tcx>(
let arg_value = drop_place.place_ref( let arg_value = drop_place.place_ref(
fx, fx,
fx.layout_of(fx.tcx.mk_ref( fx.layout_of(Ty::new_ref(
fx.tcx,
fx.tcx.lifetimes.re_erased, fx.tcx.lifetimes.re_erased,
TypeAndMut { ty, mutbl: crate::rustc_hir::Mutability::Mut }, TypeAndMut { ty, mutbl: crate::rustc_hir::Mutability::Mut },
)), )),

View file

@ -746,7 +746,7 @@ fn codegen_stmt<'tcx>(
} }
Rvalue::ShallowInitBox(ref operand, content_ty) => { Rvalue::ShallowInitBox(ref operand, content_ty) => {
let content_ty = fx.monomorphize(content_ty); let content_ty = fx.monomorphize(content_ty);
let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty)); let box_layout = fx.layout_of(Ty::new_box(fx.tcx, content_ty));
let operand = codegen_operand(fx, operand); let operand = codegen_operand(fx, operand);
let operand = operand.load_scalar(fx); let operand = operand.load_scalar(fx);
lval.write_cvalue(fx, CValue::by_val(operand, box_layout)); lval.write_cvalue(fx, CValue::by_val(operand, box_layout));
@ -887,7 +887,7 @@ pub(crate) fn codegen_place<'tcx>(
let ptr = cplace.to_ptr(); let ptr = cplace.to_ptr();
cplace = CPlace::for_ptr( cplace = CPlace::for_ptr(
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * (from as i64)), ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * (from as i64)),
fx.layout_of(fx.tcx.mk_array(*elem_ty, to - from)), fx.layout_of(Ty::new_array(fx.tcx, *elem_ty, to - from)),
); );
} }
ty::Slice(elem_ty) => { ty::Slice(elem_ty) => {

View file

@ -92,7 +92,7 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
match bin_op { match bin_op {
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => unreachable!(), BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => unreachable!(),
BinOp::Mul if is_signed => { BinOp::Mul if is_signed => {
let out_ty = fx.tcx.mk_tup(&[lhs.layout().ty, fx.tcx.types.bool]); let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32)); let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32));
let lhs = lhs.load_scalar(fx); let lhs = lhs.load_scalar(fx);
let rhs = rhs.load_scalar(fx); let rhs = rhs.load_scalar(fx);
@ -112,7 +112,7 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
Some(CValue::by_val_pair(res, oflow, fx.layout_of(out_ty))) Some(CValue::by_val_pair(res, oflow, fx.layout_of(out_ty)))
} }
BinOp::Add | BinOp::Sub | BinOp::Mul => { BinOp::Add | BinOp::Sub | BinOp::Mul => {
let out_ty = fx.tcx.mk_tup(&[lhs.layout().ty, fx.tcx.types.bool]); let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty)); let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
let param_types = vec![ let param_types = vec![
AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn), AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),

View file

@ -99,7 +99,7 @@ fn clif_pair_type_from_ty<'tcx>(
/// Is a pointer to this type a fat ptr? /// Is a pointer to this type a fat ptr?
pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
let ptr_ty = tcx.mk_ptr(TypeAndMut { ty, mutbl: rustc_hir::Mutability::Not }); let ptr_ty = Ty::new_ptr(tcx, TypeAndMut { ty, mutbl: rustc_hir::Mutability::Not });
match &tcx.layout_of(ParamEnv::reveal_all().and(ptr_ty)).unwrap().abi { match &tcx.layout_of(ParamEnv::reveal_all().and(ptr_ty)).unwrap().abi {
Abi::Scalar(_) => false, Abi::Scalar(_) => false,
Abi::ScalarPair(_, _) => true, Abi::ScalarPair(_, _) => true,

View file

@ -386,7 +386,7 @@ fn llvm_add_sub<'tcx>(
// carry0 | carry1 -> carry or borrow respectively // carry0 | carry1 -> carry or borrow respectively
let cb_out = fx.bcx.ins().bor(cb0, cb1); let cb_out = fx.bcx.ins().bor(cb0, cb1);
let layout = fx.layout_of(fx.tcx.mk_tup(&[fx.tcx.types.u8, fx.tcx.types.u64])); let layout = fx.layout_of(Ty::new_tup(fx.tcx, &[fx.tcx.types.u8, fx.tcx.types.u64]));
let val = CValue::by_val_pair(cb_out, c, layout); let val = CValue::by_val_pair(cb_out, c, layout);
ret.write_cvalue(fx, val); ret.write_cvalue(fx, val);
} }

View file

@ -270,7 +270,7 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
_ => bug!("binop {:?} on checked int/uint lhs: {:?} rhs: {:?}", bin_op, in_lhs, in_rhs), _ => bug!("binop {:?} on checked int/uint lhs: {:?} rhs: {:?}", bin_op, in_lhs, in_rhs),
}; };
let out_layout = fx.layout_of(fx.tcx.mk_tup(&[in_lhs.layout().ty, fx.tcx.types.bool])); let out_layout = fx.layout_of(Ty::new_tup(fx.tcx, &[in_lhs.layout().ty, fx.tcx.types.bool]));
CValue::by_val_pair(res, has_overflow, out_layout) CValue::by_val_pair(res, has_overflow, out_layout)
} }

View file

@ -1147,19 +1147,19 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(cx: &'a CodegenCx<'gcc, 'tcx>, codegen: &mut
// Define the type up front for the signature of the rust_try function. // Define the type up front for the signature of the rust_try function.
let tcx = cx.tcx; let tcx = cx.tcx;
let i8p = tcx.mk_mut_ptr(tcx.types.i8); let i8p = Ty::new_mut_ptr(tcx,tcx.types.i8);
// `unsafe fn(*mut i8) -> ()` // `unsafe fn(*mut i8) -> ()`
let try_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig( let try_fn_ty = Ty::new_fn_ptr(tcx,ty::Binder::dummy(tcx.mk_fn_sig(
iter::once(i8p), iter::once(i8p),
tcx.mk_unit(), Ty::new_unit(tcx,),
false, false,
rustc_hir::Unsafety::Unsafe, rustc_hir::Unsafety::Unsafe,
Abi::Rust, Abi::Rust,
))); )));
// `unsafe fn(*mut i8, *mut i8) -> ()` // `unsafe fn(*mut i8, *mut i8) -> ()`
let catch_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig( let catch_fn_ty = Ty::new_fn_ptr(tcx,ty::Binder::dummy(tcx.mk_fn_sig(
[i8p, i8p].iter().cloned(), [i8p, i8p].iter().cloned(),
tcx.mk_unit(), Ty::new_unit(tcx,),
false, false,
rustc_hir::Unsafety::Unsafe, rustc_hir::Unsafety::Unsafe,
Abi::Rust, Abi::Rust,

View file

@ -283,7 +283,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
// only wide pointer boxes are handled as pointers // only wide pointer boxes are handled as pointers
// thin pointer boxes with scalar allocators are handled by the general logic below // thin pointer boxes with scalar allocators are handled by the general logic below
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => { ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
let ptr_ty = cx.tcx.mk_mut_ptr(self.ty.boxed_ty()); let ptr_ty = Ty::new_mut_ptr(cx.tcx,self.ty.boxed_ty());
return cx.layout_of(ptr_ty).scalar_pair_element_gcc_type(cx, index, immediate); return cx.layout_of(ptr_ty).scalar_pair_element_gcc_type(cx, index, immediate);
} }
_ => {} _ => {}

View file

@ -351,7 +351,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
continue; continue;
} }
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => { PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
let ptr_ty = cx.tcx.mk_mut_ptr(arg.layout.ty); let ptr_ty = Ty::new_mut_ptr(cx.tcx, arg.layout.ty);
let ptr_layout = cx.layout_of(ptr_ty); let ptr_layout = cx.layout_of(ptr_ty);
llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 0, true)); llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 0, true));
llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 1, true)); llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 1, true));

View file

@ -24,6 +24,7 @@ use rustc_middle::ty;
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt}; use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt};
use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::Instance; use rustc_middle::ty::Instance;
use rustc_middle::ty::Ty;
use std::cell::RefCell; use std::cell::RefCell;
use std::ffi::CString; use std::ffi::CString;
@ -262,8 +263,8 @@ fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance<
tcx.symbol_name(instance).name, tcx.symbol_name(instance).name,
cx.fn_abi_of_fn_ptr( cx.fn_abi_of_fn_ptr(
ty::Binder::dummy(tcx.mk_fn_sig( ty::Binder::dummy(tcx.mk_fn_sig(
[tcx.mk_unit()], [Ty::new_unit(tcx)],
tcx.mk_unit(), Ty::new_unit(tcx),
false, false,
hir::Unsafety::Unsafe, hir::Unsafety::Unsafe,
Abi::Rust, Abi::Rust,

View file

@ -168,7 +168,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
// a (fat) pointer. Make sure it is not called for e.g. `Box<T, NonZSTAllocator>`. // a (fat) pointer. Make sure it is not called for e.g. `Box<T, NonZSTAllocator>`.
debug_assert_eq!( debug_assert_eq!(
cx.size_and_align_of(ptr_type), cx.size_and_align_of(ptr_type),
cx.size_and_align_of(cx.tcx.mk_mut_ptr(pointee_type)) cx.size_and_align_of(Ty::new_mut_ptr(cx.tcx, pointee_type))
); );
let pointee_type_di_node = type_di_node(cx, pointee_type); let pointee_type_di_node = type_di_node(cx, pointee_type);
@ -223,8 +223,11 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
// at all and instead emit regular struct debuginfo for it. We just // at all and instead emit regular struct debuginfo for it. We just
// need to make sure that we don't break existing debuginfo consumers // need to make sure that we don't break existing debuginfo consumers
// by doing that (at least not without a warning period). // by doing that (at least not without a warning period).
let layout_type = let layout_type = if ptr_type.is_box() {
if ptr_type.is_box() { cx.tcx.mk_mut_ptr(pointee_type) } else { ptr_type }; Ty::new_mut_ptr(cx.tcx, pointee_type)
} else {
ptr_type
};
let layout = cx.layout_of(layout_type); let layout = cx.layout_of(layout_type);
let addr_field = layout.field(cx, abi::FAT_PTR_ADDR); let addr_field = layout.field(cx, abi::FAT_PTR_ADDR);
@ -1298,7 +1301,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
// All function pointers are described as opaque pointers. This could be improved in the future // All function pointers are described as opaque pointers. This could be improved in the future
// by describing them as actual function pointers. // by describing them as actual function pointers.
let void_pointer_ty = tcx.mk_imm_ptr(tcx.types.unit); let void_pointer_ty = Ty::new_imm_ptr(tcx, tcx.types.unit);
let void_pointer_type_di_node = type_di_node(cx, void_pointer_ty); let void_pointer_type_di_node = type_di_node(cx, void_pointer_ty);
let usize_di_node = type_di_node(cx, tcx.types.usize); let usize_di_node = type_di_node(cx, tcx.types.usize);
let (pointer_size, pointer_align) = cx.size_and_align_of(void_pointer_ty); let (pointer_size, pointer_align) = cx.size_and_align_of(void_pointer_ty);

View file

@ -454,7 +454,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
ty::Array(ct, _) ty::Array(ct, _)
if (*ct == cx.tcx.types.u8) || cx.layout_of(*ct).is_zst() => if (*ct == cx.tcx.types.u8) || cx.layout_of(*ct).is_zst() =>
{ {
cx.tcx.mk_imm_ptr(*ct) Ty::new_imm_ptr(cx.tcx, *ct)
} }
_ => t, _ => t,
}; };

View file

@ -82,8 +82,8 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
ty::Foreign(_) => { ty::Foreign(_) => {
// Assert that pointers to foreign types really are thin: // Assert that pointers to foreign types really are thin:
debug_assert_eq!( debug_assert_eq!(
cx.size_of(cx.tcx.mk_imm_ptr(pointee_tail_ty)), cx.size_of(Ty::new_imm_ptr(cx.tcx, pointee_tail_ty)),
cx.size_of(cx.tcx.mk_imm_ptr(cx.tcx.types.u8)) cx.size_of(Ty::new_imm_ptr(cx.tcx, cx.tcx.types.u8))
); );
None None
} }

View file

@ -873,23 +873,29 @@ fn get_rust_try_fn<'ll, 'tcx>(
// Define the type up front for the signature of the rust_try function. // Define the type up front for the signature of the rust_try function.
let tcx = cx.tcx; let tcx = cx.tcx;
let i8p = tcx.mk_mut_ptr(tcx.types.i8); let i8p = Ty::new_mut_ptr(tcx, tcx.types.i8);
// `unsafe fn(*mut i8) -> ()` // `unsafe fn(*mut i8) -> ()`
let try_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig( let try_fn_ty = Ty::new_fn_ptr(
tcx,
ty::Binder::dummy(tcx.mk_fn_sig(
[i8p], [i8p],
tcx.mk_unit(), Ty::new_unit(tcx),
false, false,
hir::Unsafety::Unsafe, hir::Unsafety::Unsafe,
Abi::Rust, Abi::Rust,
))); )),
);
// `unsafe fn(*mut i8, *mut i8) -> ()` // `unsafe fn(*mut i8, *mut i8) -> ()`
let catch_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig( let catch_fn_ty = Ty::new_fn_ptr(
tcx,
ty::Binder::dummy(tcx.mk_fn_sig(
[i8p, i8p], [i8p, i8p],
tcx.mk_unit(), Ty::new_unit(tcx),
false, false,
hir::Unsafety::Unsafe, hir::Unsafety::Unsafe,
Abi::Rust, Abi::Rust,
))); )),
);
// `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32` // `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig( let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig(
[try_fn_ty, i8p, catch_fn_ty], [try_fn_ty, i8p, catch_fn_ty],

View file

@ -337,12 +337,13 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
// only wide pointer boxes are handled as pointers // only wide pointer boxes are handled as pointers
// thin pointer boxes with scalar allocators are handled by the general logic below // thin pointer boxes with scalar allocators are handled by the general logic below
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => { ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
let ptr_ty = cx.tcx.mk_mut_ptr(self.ty.boxed_ty()); let ptr_ty = Ty::new_mut_ptr(cx.tcx, self.ty.boxed_ty());
return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate); return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate);
} }
// `dyn* Trait` has the same ABI as `*mut dyn Trait` // `dyn* Trait` has the same ABI as `*mut dyn Trait`
ty::Dynamic(bounds, region, ty::DynStar) => { ty::Dynamic(bounds, region, ty::DynStar) => {
let ptr_ty = cx.tcx.mk_mut_ptr(cx.tcx.mk_dynamic(bounds, region, ty::Dyn)); let ptr_ty =
Ty::new_mut_ptr(cx.tcx, Ty::new_dynamic(cx.tcx, bounds, region, ty::Dyn));
return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate); return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate);
} }
_ => {} _ => {}

View file

@ -73,7 +73,7 @@ fn emit_ptr_va_arg<'ll, 'tcx>(
let layout = bx.cx.layout_of(target_ty); let layout = bx.cx.layout_of(target_ty);
let (llty, size, align) = if indirect { let (llty, size, align) = if indirect {
( (
bx.cx.layout_of(bx.cx.tcx.mk_imm_ptr(target_ty)).llvm_type(bx.cx), bx.cx.layout_of(Ty::new_imm_ptr(bx.cx.tcx, target_ty)).llvm_type(bx.cx),
bx.cx.data_layout().pointer_size, bx.cx.data_layout().pointer_size,
bx.cx.data_layout().pointer_align, bx.cx.data_layout().pointer_align,
) )

View file

@ -199,7 +199,7 @@ fn vtable_ptr_ty<'tcx, Cx: CodegenMethods<'tcx>>(
cx.scalar_pair_element_backend_type( cx.scalar_pair_element_backend_type(
cx.layout_of(match kind { cx.layout_of(match kind {
// vtable is the second field of `*mut dyn Trait` // vtable is the second field of `*mut dyn Trait`
ty::Dyn => cx.tcx().mk_mut_ptr(target), ty::Dyn => Ty::new_mut_ptr(cx.tcx(), target),
// vtable is the second field of `dyn* Trait` // vtable is the second field of `dyn* Trait`
ty::DynStar => target, ty::DynStar => target,
}), }),

View file

@ -1505,9 +1505,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
if let Some(slot) = self.personality_slot { if let Some(slot) = self.personality_slot {
slot slot
} else { } else {
let layout = cx.layout_of( let layout = cx.layout_of(Ty::new_tup(
cx.tcx().mk_tup(&[cx.tcx().mk_mut_ptr(cx.tcx().types.u8), cx.tcx().types.i32]), cx.tcx(),
); &[Ty::new_mut_ptr(cx.tcx(), cx.tcx().types.u8), cx.tcx().types.i32],
));
let slot = PlaceRef::alloca(bx, layout); let slot = PlaceRef::alloca(bx, layout);
self.personality_slot = Some(slot); self.personality_slot = Some(slot);
slot slot

View file

@ -5,6 +5,7 @@ use rustc_middle::mir;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf}; use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
use rustc_middle::ty::Ty;
use rustc_session::config::DebugInfo; use rustc_session::config::DebugInfo;
use rustc_span::symbol::{kw, Symbol}; use rustc_span::symbol::{kw, Symbol};
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
@ -421,9 +422,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let create_alloca = |bx: &mut Bx, place: PlaceRef<'tcx, Bx::Value>, refcount| { let create_alloca = |bx: &mut Bx, place: PlaceRef<'tcx, Bx::Value>, refcount| {
// 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 let ptr_ty = Ty::new_ptr(
.tcx() bx.tcx(),
.mk_ptr(ty::TypeAndMut { mutbl: mir::Mutability::Mut, ty: place.layout.ty }); 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, &format!("{}.ref{}.dbg.spill", var.name, refcount)); bx.set_var_name(alloca.llval, &format!("{}.ref{}.dbg.spill", var.name, refcount));
@ -525,8 +527,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}; };
for _ in 0..var.references { for _ in 0..var.references {
var_ty = var_ty = Ty::new_ptr(
bx.tcx().mk_ptr(ty::TypeAndMut { mutbl: mir::Mutability::Mut, ty: var_ty }); bx.tcx(),
ty::TypeAndMut { mutbl: mir::Mutability::Mut, ty: var_ty },
);
} }
self.cx.create_dbg_var(var.name, var_ty, dbg_scope, var_kind, span) self.cx.create_dbg_var(var.name, var_ty, dbg_scope, var_kind, span)

View file

@ -61,7 +61,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
layout: TyAndLayout<'tcx>, layout: TyAndLayout<'tcx>,
) -> Self { ) -> Self {
assert!(layout.is_unsized(), "tried to allocate indirect place for sized values"); assert!(layout.is_unsized(), "tried to allocate indirect place for sized values");
let ptr_ty = bx.cx().tcx().mk_mut_ptr(layout.ty); let ptr_ty = Ty::new_mut_ptr(bx.cx().tcx(), layout.ty);
let ptr_layout = bx.cx().layout_of(ptr_ty); let ptr_layout = bx.cx().layout_of(ptr_ty);
Self::alloca(bx, ptr_layout) Self::alloca(bx, ptr_layout)
} }

View file

@ -581,7 +581,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::Rvalue::Ref(_, bk, place) => { mir::Rvalue::Ref(_, bk, place) => {
let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| { let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
tcx.mk_ref( Ty::new_ref(
tcx,
tcx.lifetimes.re_erased, tcx.lifetimes.re_erased,
ty::TypeAndMut { ty, mutbl: bk.to_mutbl_lossy() }, ty::TypeAndMut { ty, mutbl: bk.to_mutbl_lossy() },
) )
@ -592,7 +593,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::Rvalue::CopyForDeref(place) => self.codegen_operand(bx, &Operand::Copy(place)), mir::Rvalue::CopyForDeref(place) => self.codegen_operand(bx, &Operand::Copy(place)),
mir::Rvalue::AddressOf(mutability, place) => { mir::Rvalue::AddressOf(mutability, place) => {
let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| { let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability }) Ty::new_ptr(tcx, ty::TypeAndMut { ty, mutbl: mutability })
}; };
self.codegen_place_to_pointer(bx, place, mk_ptr) self.codegen_place_to_pointer(bx, place, mk_ptr)
} }
@ -644,7 +645,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
lhs.layout.ty, lhs.layout.ty,
); );
let val_ty = op.ty(bx.tcx(), lhs.layout.ty, rhs.layout.ty); let val_ty = op.ty(bx.tcx(), lhs.layout.ty, rhs.layout.ty);
let operand_ty = bx.tcx().mk_tup(&[val_ty, bx.tcx().types.bool]); let operand_ty = Ty::new_tup(bx.tcx(), &[val_ty, bx.tcx().types.bool]);
OperandRef { val: result, layout: bx.cx().layout_of(operand_ty) } OperandRef { val: result, layout: bx.cx().layout_of(operand_ty) }
} }
@ -734,7 +735,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let lloperand = operand.immediate(); let lloperand = operand.immediate();
let content_ty = self.monomorphize(content_ty); let content_ty = self.monomorphize(content_ty);
let box_layout = bx.cx().layout_of(bx.tcx().mk_box(content_ty)); let box_layout = bx.cx().layout_of(Ty::new_box(bx.tcx(), content_ty));
let llty_ptr = bx.cx().backend_type(box_layout); let llty_ptr = bx.cx().backend_type(box_layout);
let val = bx.pointercast(lloperand, llty_ptr); let val = bx.pointercast(lloperand, llty_ptr);

View file

@ -170,7 +170,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
sym::pref_align_of | sym::variant_count => self.tcx.types.usize, sym::pref_align_of | sym::variant_count => self.tcx.types.usize,
sym::needs_drop => self.tcx.types.bool, sym::needs_drop => self.tcx.types.bool,
sym::type_id => self.tcx.types.u128, sym::type_id => self.tcx.types.u128,
sym::type_name => self.tcx.mk_static_str(), sym::type_name => Ty::new_static_str(self.tcx.tcx),
_ => bug!(), _ => bug!(),
}; };
let val = self.ctfe_query(None, |tcx| { let val = self.ctfe_query(None, |tcx| {

View file

@ -22,7 +22,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
let (val, overflowed, ty) = self.overflowing_binary_op(op, &left, &right)?; let (val, overflowed, ty) = self.overflowing_binary_op(op, &left, &right)?;
debug_assert_eq!( debug_assert_eq!(
self.tcx.mk_tup(&[ty, self.tcx.types.bool]), Ty::new_tup(self.tcx.tcx, &[ty, self.tcx.types.bool]),
dest.layout.ty, dest.layout.ty,
"type mismatch for result of {:?}", "type mismatch for result of {:?}",
op, op,

View file

@ -9,6 +9,7 @@ use rustc_index::IndexSlice;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::ty::Ty;
use rustc_target::abi::{self, Abi, Align, FieldIdx, HasDataLayout, Size, FIRST_VARIANT}; use rustc_target::abi::{self, Abi, Align, FieldIdx, HasDataLayout, Size, FIRST_VARIANT};
use super::{ use super::{
@ -395,7 +396,7 @@ where
// (Transmuting is okay since this is an in-memory place. We also double-check the size // (Transmuting is okay since this is an in-memory place. We also double-check the size
// stays the same.) // stays the same.)
let (len, e_ty) = mplace.layout.ty.simd_size_and_type(*self.tcx); let (len, e_ty) = mplace.layout.ty.simd_size_and_type(*self.tcx);
let array = self.tcx.mk_array(e_ty, len); let array = Ty::new_array(self.tcx.tcx, e_ty, len);
let layout = self.layout_of(array)?; let layout = self.layout_of(array)?;
assert_eq!(layout.size, mplace.layout.size); assert_eq!(layout.size, mplace.layout.size);
Ok((MPlaceTy { layout, ..*mplace }, len)) Ok((MPlaceTy { layout, ..*mplace }, len))
@ -775,7 +776,8 @@ where
let meta = Scalar::from_target_usize(u64::try_from(str.len()).unwrap(), self); let meta = Scalar::from_target_usize(u64::try_from(str.len()).unwrap(), self);
let mplace = MemPlace { ptr: ptr.into(), meta: MemPlaceMeta::Meta(meta) }; let mplace = MemPlace { ptr: ptr.into(), meta: MemPlaceMeta::Meta(meta) };
let ty = self.tcx.mk_ref( let ty = Ty::new_ref(
self.tcx.tcx,
self.tcx.lifetimes.re_static, self.tcx.lifetimes.re_static,
ty::TypeAndMut { ty: self.tcx.types.str_, mutbl }, ty::TypeAndMut { ty: self.tcx.types.str_, mutbl },
); );

View file

@ -12,6 +12,7 @@ use either::{Left, Right};
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::Ty;
use rustc_target::abi::{self, Abi, VariantIdx}; use rustc_target::abi::{self, Abi, VariantIdx};
use super::{ use super::{
@ -317,7 +318,9 @@ where
let (meta, ty) = match base.layout.ty.kind() { let (meta, ty) = match base.layout.ty.kind() {
// It is not nice to match on the type, but that seems to be the only way to // It is not nice to match on the type, but that seems to be the only way to
// implement this. // implement this.
ty::Array(inner, _) => (MemPlaceMeta::None, self.tcx.mk_array(*inner, inner_len)), ty::Array(inner, _) => {
(MemPlaceMeta::None, Ty::new_array(self.tcx.tcx, *inner, inner_len))
}
ty::Slice(..) => { ty::Slice(..) => {
let len = Scalar::from_target_usize(inner_len, self); let len = Scalar::from_target_usize(inner_len, self);
(MemPlaceMeta::Meta(len), base.layout.ty) (MemPlaceMeta::Meta(len), base.layout.ty)

View file

@ -650,7 +650,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// Adjust receiver argument. Layout can be any (thin) ptr. // Adjust receiver argument. Layout can be any (thin) ptr.
args[0] = ImmTy::from_immediate( args[0] = ImmTy::from_immediate(
Scalar::from_maybe_pointer(adjusted_receiver, self).into(), Scalar::from_maybe_pointer(adjusted_receiver, self).into(),
self.layout_of(self.tcx.mk_mut_ptr(dyn_ty))?, self.layout_of(Ty::new_mut_ptr(self.tcx.tcx, dyn_ty))?,
) )
.into(); .into();
trace!("Patched receiver operand to {:#?}", args[0]); trace!("Patched receiver operand to {:#?}", args[0]);
@ -703,7 +703,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let arg = ImmTy::from_immediate( let arg = ImmTy::from_immediate(
place.to_ref(self), place.to_ref(self),
self.layout_of(self.tcx.mk_mut_ptr(place.layout.ty))?, self.layout_of(Ty::new_mut_ptr(self.tcx.tcx, place.layout.ty))?,
); );
let ret = MPlaceTy::fake_alloc_zst(self.layout_of(self.tcx.types.unit)?); let ret = MPlaceTy::fake_alloc_zst(self.layout_of(self.tcx.types.unit)?);

View file

@ -223,7 +223,7 @@ impl Qualif for CustomEq {
def: AdtDef<'tcx>, def: AdtDef<'tcx>,
substs: SubstsRef<'tcx>, substs: SubstsRef<'tcx>,
) -> bool { ) -> bool {
let ty = cx.tcx.mk_adt(def, substs); let ty = Ty::new_adt(cx.tcx, def, substs);
!ty.is_structural_eq_shallow(cx.tcx) !ty.is_structural_eq_shallow(cx.tcx)
} }
} }

View file

@ -17,7 +17,7 @@ use rustc_middle::mir;
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::{self, List, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, List, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::Span; use rustc_span::Span;
use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
@ -867,7 +867,8 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
let ty = local_decls[place.local].ty; let ty = local_decls[place.local].ty;
let span = statement.source_info.span; let span = statement.source_info.span;
let ref_ty = tcx.mk_ref( let ref_ty = Ty::new_ref(
tcx,
tcx.lifetimes.re_erased, tcx.lifetimes.re_erased,
ty::TypeAndMut { ty, mutbl: borrow_kind.to_mutbl_lossy() }, ty::TypeAndMut { ty, mutbl: borrow_kind.to_mutbl_lossy() },
); );

View file

@ -363,7 +363,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
); );
emitted_bad_param_err = true; emitted_bad_param_err = true;
} }
tcx.mk_bound( Ty::new_bound(
tcx,
ty::INNERMOST, ty::INNERMOST,
ty::BoundTy { ty::BoundTy {
var: ty::BoundVar::from_usize(num_bound_vars), var: ty::BoundVar::from_usize(num_bound_vars),
@ -527,7 +528,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
} }
let reported = err.emit(); let reported = err.emit();
term = match def_kind { term = match def_kind {
hir::def::DefKind::AssocTy => tcx.ty_error(reported).into(), hir::def::DefKind::AssocTy => Ty::new_error(tcx, reported).into(),
hir::def::DefKind::AssocConst => ty::Const::new_error( hir::def::DefKind::AssocConst => ty::Const::new_error(
tcx, tcx,
reported, reported,
@ -558,7 +559,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
// type bound into a trait predicate, since we only want to add predicates // type bound into a trait predicate, since we only want to add predicates
// for the `Self` type. // for the `Self` type.
if !only_self_bounds.0 { if !only_self_bounds.0 {
let param_ty = tcx.mk_alias(ty::Projection, projection_ty.skip_binder()); let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());
self.add_bounds( self.add_bounds(
param_ty, param_ty,
ast_bounds.iter(), ast_bounds.iter(),

View file

@ -357,7 +357,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let projection_ty = pred.skip_binder().projection_ty; let projection_ty = pred.skip_binder().projection_ty;
let substs_with_infer_self = tcx.mk_substs_from_iter( let substs_with_infer_self = tcx.mk_substs_from_iter(
std::iter::once(tcx.mk_ty_var(ty::TyVid::from_u32(0)).into()) std::iter::once(Ty::new_var(tcx, ty::TyVid::from_u32(0)).into())
.chain(projection_ty.substs.iter().skip(1)), .chain(projection_ty.substs.iter().skip(1)),
); );

View file

@ -443,7 +443,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} }
if let (hir::TyKind::Infer, false) = (&ty.kind, self.astconv.allow_ty_infer()) { if let (hir::TyKind::Infer, false) = (&ty.kind, self.astconv.allow_ty_infer()) {
self.inferred_params.push(ty.span); self.inferred_params.push(ty.span);
tcx.ty_error_misc().into() Ty::new_misc_error(tcx).into()
} else { } else {
self.astconv.ast_ty_to_ty(ty).into() self.astconv.ast_ty_to_ty(ty).into()
} }
@ -512,14 +512,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
_ => false, _ => false,
}) { }) {
// Avoid ICE #86756 when type error recovery goes awry. // Avoid ICE #86756 when type error recovery goes awry.
return tcx.ty_error_misc().into(); return Ty::new_misc_error(tcx).into();
} }
tcx.at(self.span).type_of(param.def_id).subst(tcx, substs).into() tcx.at(self.span).type_of(param.def_id).subst(tcx, substs).into()
} else if infer_args { } else if infer_args {
self.astconv.ty_infer(Some(param), self.span).into() self.astconv.ty_infer(Some(param), self.span).into()
} else { } else {
// We've already errored above about the mismatch. // We've already errored above about the mismatch.
tcx.ty_error_misc().into() Ty::new_misc_error(tcx).into()
} }
} }
GenericParamDefKind::Const { has_default } => { GenericParamDefKind::Const { has_default } => {
@ -912,7 +912,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// referencing a single opaque type) get encoded as a type alias that normalization will // referencing a single opaque type) get encoded as a type alias that normalization will
// then actually instantiate the where bounds of. // then actually instantiate the where bounds of.
let alias_ty = self.tcx().mk_alias_ty(did, substs); let alias_ty = self.tcx().mk_alias_ty(did, substs);
self.tcx().mk_alias(ty::Weak, alias_ty) Ty::new_alias(self.tcx(), ty::Weak, alias_ty)
} else { } else {
ty.subst(self.tcx(), substs) ty.subst(self.tcx(), substs)
} }
@ -1573,10 +1573,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
match *ty.kind() { match *ty.kind() {
ty::Bound(_, bv) => self.tcx.mk_placeholder(ty::PlaceholderType { ty::Bound(_, bv) => Ty::new_placeholder(
universe: self.universe, self.tcx,
bound: bv, ty::PlaceholderType { universe: self.universe, bound: bv },
}), ),
_ => ty.super_fold_with(self), _ => ty.super_fold_with(self),
} }
} }
@ -1665,7 +1665,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.chain(substs.into_iter().skip(parent_substs.len())), .chain(substs.into_iter().skip(parent_substs.len())),
); );
let ty = tcx.mk_alias(ty::Inherent, tcx.mk_alias_ty(assoc_item, substs)); let ty = Ty::new_alias(tcx, ty::Inherent, tcx.mk_alias_ty(assoc_item, substs));
return Ok(Some((ty, assoc_item))); return Ok(Some((ty, assoc_item)));
} }
@ -1850,7 +1850,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&[path_str], &[path_str],
item_segment.ident.name, item_segment.ident.name,
); );
return tcx.ty_error(reported) return Ty::new_error(tcx,reported)
}; };
debug!("qpath_to_ty: self_type={:?}", self_ty); debug!("qpath_to_ty: self_type={:?}", self_ty);
@ -1873,7 +1873,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!("qpath_to_ty: trait_ref={:?}", trait_ref); debug!("qpath_to_ty: trait_ref={:?}", trait_ref);
tcx.mk_projection(item_def_id, item_substs) Ty::new_projection(tcx, item_def_id, item_substs)
} }
pub fn prohibit_generics<'a>( pub fn prohibit_generics<'a>(
@ -2136,7 +2136,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
err.note("`impl Trait` types can't have type parameters"); err.note("`impl Trait` types can't have type parameters");
}); });
let substs = self.ast_path_substs_for_ty(span, did, item_segment.0); let substs = self.ast_path_substs_for_ty(span, did, item_segment.0);
tcx.mk_opaque(did, substs) Ty::new_opaque(tcx, did, substs)
} }
Res::Def( Res::Def(
DefKind::Enum DefKind::Enum
@ -2188,16 +2188,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
var: ty::BoundVar::from_u32(index), var: ty::BoundVar::from_u32(index),
kind: ty::BoundTyKind::Param(def_id, name), kind: ty::BoundTyKind::Param(def_id, name),
}; };
tcx.mk_bound(debruijn, br) Ty::new_bound(tcx, debruijn, br)
} }
Some(rbv::ResolvedArg::EarlyBound(_)) => { Some(rbv::ResolvedArg::EarlyBound(_)) => {
let def_id = def_id.expect_local(); let def_id = def_id.expect_local();
let item_def_id = tcx.hir().ty_param_owner(def_id); let item_def_id = tcx.hir().ty_param_owner(def_id);
let generics = tcx.generics_of(item_def_id); let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&def_id.to_def_id()]; let index = generics.param_def_id_to_index[&def_id.to_def_id()];
tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id)) Ty::new_param(tcx, index, tcx.hir().ty_param_name(def_id))
} }
Some(rbv::ResolvedArg::Error(guar)) => tcx.ty_error(guar), Some(rbv::ResolvedArg::Error(guar)) => Ty::new_error(tcx, guar),
arg => bug!("unexpected bound var resolution for {hir_id:?}: {arg:?}"), arg => bug!("unexpected bound var resolution for {hir_id:?}: {arg:?}"),
} }
} }
@ -2309,7 +2309,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
{ {
err.span_note(impl_.self_ty.span, "not a concrete type"); err.span_note(impl_.self_ty.span, "not a concrete type");
} }
tcx.ty_error(err.emit()) Ty::new_error(tcx, err.emit())
} else { } else {
ty ty
} }
@ -2350,9 +2350,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
match prim_ty { match prim_ty {
hir::PrimTy::Bool => tcx.types.bool, hir::PrimTy::Bool => tcx.types.bool,
hir::PrimTy::Char => tcx.types.char, hir::PrimTy::Char => tcx.types.char,
hir::PrimTy::Int(it) => tcx.mk_mach_int(ty::int_ty(it)), hir::PrimTy::Int(it) => Ty::new_int(tcx, ty::int_ty(it)),
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(ty::uint_ty(uit)), hir::PrimTy::Uint(uit) => Ty::new_uint(tcx, ty::uint_ty(uit)),
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ty::float_ty(ft)), hir::PrimTy::Float(ft) => Ty::new_float(tcx, ty::float_ty(ft)),
hir::PrimTy::Str => tcx.types.str_, hir::PrimTy::Str => tcx.types.str_,
} }
} }
@ -2362,7 +2362,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.sess .sess
.delay_span_bug(path.span, "path with `Res::Err` but no error emitted"); .delay_span_bug(path.span, "path with `Res::Err` but no error emitted");
self.set_tainted_by_errors(e); self.set_tainted_by_errors(e);
self.tcx().ty_error(e) Ty::new_error(self.tcx(), e)
} }
_ => span_bug!(span, "unexpected resolution: {:?}", path.res), _ => span_bug!(span, "unexpected resolution: {:?}", path.res),
} }
@ -2387,31 +2387,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let tcx = self.tcx(); let tcx = self.tcx();
let result_ty = match &ast_ty.kind { let result_ty = match &ast_ty.kind {
hir::TyKind::Slice(ty) => tcx.mk_slice(self.ast_ty_to_ty(ty)), hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.ast_ty_to_ty(ty)),
hir::TyKind::Ptr(mt) => { hir::TyKind::Ptr(mt) => {
tcx.mk_ptr(ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl }) Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl })
} }
hir::TyKind::Ref(region, mt) => { hir::TyKind::Ref(region, mt) => {
let r = self.ast_region_to_region(region, None); let r = self.ast_region_to_region(region, None);
debug!(?r); debug!(?r);
let t = self.ast_ty_to_ty_inner(mt.ty, true, false); let t = self.ast_ty_to_ty_inner(mt.ty, true, false);
tcx.mk_ref(r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl }) Ty::new_ref(tcx, r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl })
} }
hir::TyKind::Never => tcx.types.never, hir::TyKind::Never => tcx.types.never,
hir::TyKind::Tup(fields) => { hir::TyKind::Tup(fields) => {
tcx.mk_tup_from_iter(fields.iter().map(|t| self.ast_ty_to_ty(t))) Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.ast_ty_to_ty(t)))
} }
hir::TyKind::BareFn(bf) => { hir::TyKind::BareFn(bf) => {
require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, ast_ty.span); require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, ast_ty.span);
tcx.mk_fn_ptr(self.ty_of_fn( Ty::new_fn_ptr(
ast_ty.hir_id, tcx,
bf.unsafety, self.ty_of_fn(ast_ty.hir_id, bf.unsafety, bf.abi, bf.decl, None, Some(ast_ty)),
bf.abi, )
bf.decl,
None,
Some(ast_ty),
))
} }
hir::TyKind::TraitObject(bounds, lifetime, repr) => { hir::TyKind::TraitObject(bounds, lifetime, repr) => {
self.maybe_lint_bare_trait(ast_ty, in_path); self.maybe_lint_bare_trait(ast_ty, in_path);
@ -2458,7 +2454,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let ty = self.ast_ty_to_ty_inner(qself, false, true); let ty = self.ast_ty_to_ty_inner(qself, false, true);
self.associated_path_to_ty(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false) self.associated_path_to_ty(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false)
.map(|(ty, _, _)| ty) .map(|(ty, _, _)| ty)
.unwrap_or_else(|guar| tcx.ty_error(guar)) .unwrap_or_else(|guar| Ty::new_error(tcx, guar))
} }
&hir::TyKind::Path(hir::QPath::LangItem(lang_item, span, _)) => { &hir::TyKind::Path(hir::QPath::LangItem(lang_item, span, _)) => {
let def_id = tcx.require_lang_item(lang_item, Some(span)); let def_id = tcx.require_lang_item(lang_item, Some(span));
@ -2482,7 +2478,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} }
}; };
tcx.mk_array_with_const_len(self.ast_ty_to_ty(ty), length) Ty::new_array_with_const_len(tcx, self.ast_ty_to_ty(ty), length)
} }
hir::TyKind::Typeof(e) => { hir::TyKind::Typeof(e) => {
let ty_erased = tcx.type_of(e.def_id).subst_identity(); let ty_erased = tcx.type_of(e.def_id).subst_identity();
@ -2506,7 +2502,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// handled specially and will not descend into this routine. // handled specially and will not descend into this routine.
self.ty_infer(None, ast_ty.span) self.ty_infer(None, ast_ty.span)
} }
hir::TyKind::Err(guar) => tcx.ty_error(*guar), hir::TyKind::Err(guar) => Ty::new_error(tcx, *guar),
}; };
self.record_ty(ast_ty.hir_id, result_ty, ast_ty.span); self.record_ty(ast_ty.hir_id, result_ty, ast_ty.span);
@ -2543,7 +2539,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}); });
debug!("impl_trait_ty_to_ty: substs={:?}", substs); debug!("impl_trait_ty_to_ty: substs={:?}", substs);
if in_trait { tcx.mk_projection(def_id, substs) } else { tcx.mk_opaque(def_id, substs) } if in_trait {
Ty::new_projection(tcx, def_id, substs)
} else {
Ty::new_opaque(tcx, def_id, substs)
}
} }
pub fn ty_of_arg(&self, ty: &hir::Ty<'_>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> { pub fn ty_of_arg(&self, ty: &hir::Ty<'_>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {
@ -2612,7 +2612,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.ast_ty_to_ty(output) self.ast_ty_to_ty(output)
} }
} }
hir::FnRetTy::DefaultReturn(..) => tcx.mk_unit(), hir::FnRetTy::DefaultReturn(..) => Ty::new_unit(tcx,),
}; };
debug!(?output_ty); debug!(?output_ty);

View file

@ -131,7 +131,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.map(|trait_ref| tcx.def_span(trait_ref)); .map(|trait_ref| tcx.def_span(trait_ref));
let reported = let reported =
tcx.sess.emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span }); tcx.sess.emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span });
return tcx.ty_error(reported); return Ty::new_error(tcx, reported);
} }
// Check that there are no gross object safety violations; // Check that there are no gross object safety violations;
@ -148,7 +148,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&object_safety_violations, &object_safety_violations,
) )
.emit(); .emit();
return tcx.ty_error(reported); return Ty::new_error(tcx, reported);
} }
} }
@ -271,10 +271,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if arg == dummy_self.into() { if arg == dummy_self.into() {
let param = &generics.params[index]; let param = &generics.params[index];
missing_type_params.push(param.name); missing_type_params.push(param.name);
return tcx.ty_error_misc().into(); return Ty::new_misc_error(tcx).into();
} else if arg.walk().any(|arg| arg == dummy_self.into()) { } else if arg.walk().any(|arg| arg == dummy_self.into()) {
references_self = true; references_self = true;
return tcx.ty_error_misc().into(); return Ty::new_misc_error(tcx).into();
} }
arg arg
}) })
@ -342,7 +342,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.iter() .iter()
.map(|arg| { .map(|arg| {
if arg.walk().any(|arg| arg == dummy_self.into()) { if arg.walk().any(|arg| arg == dummy_self.into()) {
return tcx.ty_error(guar).into(); return Ty::new_error(tcx, guar).into();
} }
arg arg
}) })
@ -401,7 +401,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}; };
debug!("region_bound: {:?}", region_bound); debug!("region_bound: {:?}", region_bound);
let ty = tcx.mk_dynamic(existential_predicates, region_bound, representation); let ty = Ty::new_dynamic(tcx, existential_predicates, region_bound, representation);
debug!("trait_object_type: {:?}", ty); debug!("trait_object_type: {:?}", ty);
ty ty
} }

View file

@ -148,8 +148,11 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
return None; return None;
} }
let (normalized_ty, obligations) = let (normalized_ty, obligations) = self.structurally_normalize(Ty::new_projection(
self.structurally_normalize(tcx.mk_projection(tcx.lang_items().deref_target()?, [ty]))?; tcx,
tcx.lang_items().deref_target()?,
[ty],
))?;
debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations); debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations);
self.state.obligations.extend(obligations); self.state.obligations.extend(obligations);

View file

@ -308,9 +308,9 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
{ {
let substs = InternalSubsts::identity_for_item(tcx, def_id); let substs = InternalSubsts::identity_for_item(tcx, def_id);
let opaque_identity_ty = if in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() { let opaque_identity_ty = if in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
tcx.mk_projection(def_id.to_def_id(), substs) Ty::new_projection(tcx, def_id.to_def_id(), substs)
} else { } else {
tcx.mk_opaque(def_id.to_def_id(), substs) Ty::new_opaque(tcx, def_id.to_def_id(), substs)
}; };
let mut visitor = ProhibitOpaqueVisitor { let mut visitor = ProhibitOpaqueVisitor {
opaque_identity_ty, opaque_identity_ty,
@ -410,7 +410,7 @@ fn check_opaque_meets_bounds<'tcx>(
let ocx = ObligationCtxt::new(&infcx); let ocx = ObligationCtxt::new(&infcx);
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let opaque_ty = tcx.mk_opaque(def_id.to_def_id(), substs); let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), substs);
// `ReErased` regions appear in the "parent_substs" of closures/generators. // `ReErased` regions appear in the "parent_substs" of closures/generators.
// We're ignoring them here and replacing them with fresh region variables. // We're ignoring them here and replacing them with fresh region variables.

View file

@ -271,7 +271,7 @@ fn compare_method_predicate_entailment<'tcx>(
infer::HigherRankedType, infer::HigherRankedType,
tcx.fn_sig(impl_m.def_id).subst_identity(), tcx.fn_sig(impl_m.def_id).subst_identity(),
); );
let unnormalized_impl_fty = tcx.mk_fn_ptr(ty::Binder::dummy(unnormalized_impl_sig)); let unnormalized_impl_fty = Ty::new_fn_ptr(tcx, ty::Binder::dummy(unnormalized_impl_sig));
let norm_cause = ObligationCause::misc(impl_m_span, impl_m_def_id); let norm_cause = ObligationCause::misc(impl_m_span, impl_m_def_id);
let impl_sig = ocx.normalize(&norm_cause, param_env, unnormalized_impl_sig); let impl_sig = ocx.normalize(&norm_cause, param_env, unnormalized_impl_sig);
@ -288,7 +288,7 @@ fn compare_method_predicate_entailment<'tcx>(
// We also have to add the normalized trait signature // We also have to add the normalized trait signature
// as we don't normalize during implied bounds computation. // as we don't normalize during implied bounds computation.
wf_tys.extend(trait_sig.inputs_and_output.iter()); wf_tys.extend(trait_sig.inputs_and_output.iter());
let trait_fty = tcx.mk_fn_ptr(ty::Binder::dummy(trait_sig)); let trait_fty = Ty::new_fn_ptr(tcx, ty::Binder::dummy(trait_sig));
debug!("compare_impl_method: trait_fty={:?}", trait_fty); debug!("compare_impl_method: trait_fty={:?}", trait_fty);
@ -803,7 +803,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
return_span, return_span,
}) { }) {
Ok(ty) => ty, Ok(ty) => ty,
Err(guar) => tcx.ty_error(guar), Err(guar) => Ty::new_error(tcx, guar),
}; };
collected_tys.insert(def_id, ty::EarlyBinder::bind(ty)); collected_tys.insert(def_id, ty::EarlyBinder::bind(ty));
} }
@ -812,7 +812,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
return_span, return_span,
format!("could not fully resolve: {ty} => {err:?}"), format!("could not fully resolve: {ty} => {err:?}"),
); );
collected_tys.insert(def_id, ty::EarlyBinder::bind(tcx.ty_error(reported))); collected_tys.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
} }
} }
} }
@ -916,7 +916,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
_ => arg.try_fold_with(self)?, _ => arg.try_fold_with(self)?,
}); });
} }
Ok(self.tcx.mk_opaque(def_id, self.tcx.mk_substs(&mapped_substs))) Ok(Ty::new_opaque(self.tcx, def_id, self.tcx.mk_substs(&mapped_substs)))
} else { } else {
t.try_super_fold_with(self) t.try_super_fold_with(self)
} }
@ -2027,7 +2027,8 @@ 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_bound( Ty::new_bound(
tcx,
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 },
) )

View file

@ -11,7 +11,7 @@ use hir::def_id::DefId;
use rustc_errors::{struct_span_err, DiagnosticMessage}; use rustc_errors::{struct_span_err, DiagnosticMessage};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::symbol::{kw, sym, Symbol};
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
@ -53,14 +53,14 @@ fn equate_intrinsic_type<'tcx>(
&& gen_count_ok(own_counts.types, n_tps, "type") && gen_count_ok(own_counts.types, n_tps, "type")
&& gen_count_ok(own_counts.consts, 0, "const") && gen_count_ok(own_counts.consts, 0, "const")
{ {
let fty = tcx.mk_fn_ptr(sig); let fty = Ty::new_fn_ptr(tcx, sig);
let it_def_id = it.owner_id.def_id; let it_def_id = it.owner_id.def_id;
let cause = ObligationCause::new(it.span, it_def_id, ObligationCauseCode::IntrinsicType); let cause = ObligationCause::new(it.span, it_def_id, ObligationCauseCode::IntrinsicType);
require_same_types( require_same_types(
tcx, tcx,
&cause, &cause,
ty::ParamEnv::empty(), // FIXME: do all intrinsics have an empty param env? ty::ParamEnv::empty(), // FIXME: do all intrinsics have an empty param env?
tcx.mk_fn_ptr(tcx.fn_sig(it.owner_id).subst_identity()), Ty::new_fn_ptr(tcx, tcx.fn_sig(it.owner_id).subst_identity()),
fty, fty,
); );
} }
@ -134,7 +134,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`, /// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
/// and in `library/core/src/intrinsics.rs`. /// and in `library/core/src/intrinsics.rs`.
pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
let param = |n| tcx.mk_ty_param(n, Symbol::intern(&format!("P{}", n))); let param = |n| Ty::new_param(tcx, n, Symbol::intern(&format!("P{}", n)));
let intrinsic_id = it.owner_id.to_def_id(); let intrinsic_id = it.owner_id.to_def_id();
let intrinsic_name = tcx.item_name(intrinsic_id); let intrinsic_name = tcx.item_name(intrinsic_id);
let name_str = intrinsic_name.as_str(); let name_str = intrinsic_name.as_str();
@ -156,7 +156,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv }, ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv },
); );
let va_list_ty = tcx.type_of(did).subst(tcx, &[region.into()]); let va_list_ty = tcx.type_of(did).subst(tcx, &[region.into()]);
(tcx.mk_ref(env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty) (Ty::new_ref(tcx, env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty)
}) })
}; };
@ -168,15 +168,15 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
let (n_tps, inputs, output) = match split[1] { let (n_tps, inputs, output) = match split[1] {
"cxchg" | "cxchgweak" => ( "cxchg" | "cxchgweak" => (
1, 1,
vec![tcx.mk_mut_ptr(param(0)), param(0), param(0)], vec![Ty::new_mut_ptr(tcx, param(0)), param(0), param(0)],
tcx.mk_tup(&[param(0), tcx.types.bool]), Ty::new_tup(tcx, &[param(0), tcx.types.bool]),
), ),
"load" => (1, vec![tcx.mk_imm_ptr(param(0))], param(0)), "load" => (1, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
"store" => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()), "store" => (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx)),
"xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" | "min" | "umax" "xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" | "min" | "umax"
| "umin" => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], param(0)), | "umin" => (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], param(0)),
"fence" | "singlethreadfence" => (0, Vec::new(), tcx.mk_unit()), "fence" | "singlethreadfence" => (0, Vec::new(), Ty::new_unit(tcx)),
op => { op => {
tcx.sess.emit_err(UnrecognizedAtomicOperation { span: it.span, op }); tcx.sess.emit_err(UnrecognizedAtomicOperation { span: it.span, op });
return; return;
@ -188,19 +188,19 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
let (n_tps, inputs, output) = match intrinsic_name { let (n_tps, inputs, output) = match intrinsic_name {
sym::abort => (0, Vec::new(), tcx.types.never), sym::abort => (0, Vec::new(), tcx.types.never),
sym::unreachable => (0, Vec::new(), tcx.types.never), sym::unreachable => (0, Vec::new(), tcx.types.never),
sym::breakpoint => (0, Vec::new(), tcx.mk_unit()), sym::breakpoint => (0, Vec::new(), Ty::new_unit(tcx)),
sym::size_of | sym::pref_align_of | sym::min_align_of | sym::variant_count => { sym::size_of | sym::pref_align_of | sym::min_align_of | sym::variant_count => {
(1, Vec::new(), tcx.types.usize) (1, Vec::new(), tcx.types.usize)
} }
sym::size_of_val | sym::min_align_of_val => { sym::size_of_val | sym::min_align_of_val => {
(1, vec![tcx.mk_imm_ptr(param(0))], tcx.types.usize) (1, vec![Ty::new_imm_ptr(tcx, param(0))], tcx.types.usize)
} }
sym::rustc_peek => (1, vec![param(0)], param(0)), sym::rustc_peek => (1, vec![param(0)], param(0)),
sym::caller_location => (0, vec![], tcx.caller_location_ty()), sym::caller_location => (0, vec![], tcx.caller_location_ty()),
sym::assert_inhabited sym::assert_inhabited
| sym::assert_zero_valid | sym::assert_zero_valid
| sym::assert_mem_uninitialized_valid => (1, Vec::new(), tcx.mk_unit()), | sym::assert_mem_uninitialized_valid => (1, Vec::new(), Ty::new_unit(tcx)),
sym::forget => (1, vec![param(0)], tcx.mk_unit()), sym::forget => (1, vec![param(0)], Ty::new_unit(tcx)),
sym::transmute | sym::transmute_unchecked => (2, vec![param(0)], param(1)), sym::transmute | sym::transmute_unchecked => (2, vec![param(0)], param(1)),
sym::prefetch_read_data sym::prefetch_read_data
| sym::prefetch_write_data | sym::prefetch_write_data
@ -208,75 +208,79 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
| sym::prefetch_write_instruction => ( | sym::prefetch_write_instruction => (
1, 1,
vec![ vec![
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
tcx.types.i32, tcx.types.i32,
], ],
tcx.mk_unit(), Ty::new_unit(tcx),
), ),
sym::drop_in_place => (1, vec![tcx.mk_mut_ptr(param(0))], tcx.mk_unit()), sym::drop_in_place => (1, vec![Ty::new_mut_ptr(tcx, param(0))], Ty::new_unit(tcx)),
sym::needs_drop => (1, Vec::new(), tcx.types.bool), sym::needs_drop => (1, Vec::new(), tcx.types.bool),
sym::type_name => (1, Vec::new(), tcx.mk_static_str()), sym::type_name => (1, Vec::new(), Ty::new_static_str(tcx)),
sym::type_id => (1, Vec::new(), tcx.types.u128), sym::type_id => (1, Vec::new(), tcx.types.u128),
sym::offset => (2, vec![param(0), param(1)], param(0)), sym::offset => (2, vec![param(0), param(1)], param(0)),
sym::arith_offset => ( sym::arith_offset => (
1, 1,
vec![ vec![
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
tcx.types.isize, tcx.types.isize,
], ],
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
), ),
sym::option_payload_ptr => { sym::option_payload_ptr => {
let option_def_id = tcx.require_lang_item(hir::LangItem::Option, None); let option_def_id = tcx.require_lang_item(hir::LangItem::Option, None);
let p0 = param(0); let p0 = param(0);
( (
1, 1,
vec![tcx.mk_ptr(ty::TypeAndMut { vec![Ty::new_ptr(
ty: tcx.mk_adt( tcx,
ty::TypeAndMut {
ty: Ty::new_adt(
tcx,
tcx.adt_def(option_def_id), tcx.adt_def(option_def_id),
tcx.mk_substs_from_iter([ty::GenericArg::from(p0)].into_iter()), tcx.mk_substs_from_iter([ty::GenericArg::from(p0)].into_iter()),
), ),
mutbl: hir::Mutability::Not, mutbl: hir::Mutability::Not,
})], },
tcx.mk_ptr(ty::TypeAndMut { ty: p0, mutbl: hir::Mutability::Not }), )],
Ty::new_ptr(tcx, ty::TypeAndMut { ty: p0, mutbl: hir::Mutability::Not }),
) )
} }
sym::ptr_mask => ( sym::ptr_mask => (
1, 1,
vec![ vec![
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
tcx.types.usize, tcx.types.usize,
], ],
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
), ),
sym::copy | sym::copy_nonoverlapping => ( sym::copy | sym::copy_nonoverlapping => (
1, 1,
vec![ vec![
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }), Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
tcx.types.usize, tcx.types.usize,
], ],
tcx.mk_unit(), Ty::new_unit(tcx),
), ),
sym::volatile_copy_memory | sym::volatile_copy_nonoverlapping_memory => ( sym::volatile_copy_memory | sym::volatile_copy_nonoverlapping_memory => (
1, 1,
vec![ vec![
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }), Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
tcx.types.usize, tcx.types.usize,
], ],
tcx.mk_unit(), Ty::new_unit(tcx),
), ),
sym::write_bytes | sym::volatile_set_memory => ( sym::write_bytes | sym::volatile_set_memory => (
1, 1,
vec![ vec![
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }), Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
tcx.types.u8, tcx.types.u8,
tcx.types.usize, tcx.types.usize,
], ],
tcx.mk_unit(), Ty::new_unit(tcx),
), ),
sym::sqrtf32 => (0, vec![tcx.types.f32], tcx.types.f32), sym::sqrtf32 => (0, vec![tcx.types.f32], tcx.types.f32),
sym::sqrtf64 => (0, vec![tcx.types.f64], tcx.types.f64), sym::sqrtf64 => (0, vec![tcx.types.f64], tcx.types.f64),
@ -324,10 +328,10 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
sym::roundevenf64 => (0, vec![tcx.types.f64], tcx.types.f64), sym::roundevenf64 => (0, vec![tcx.types.f64], tcx.types.f64),
sym::volatile_load | sym::unaligned_volatile_load => { sym::volatile_load | sym::unaligned_volatile_load => {
(1, vec![tcx.mk_imm_ptr(param(0))], param(0)) (1, vec![Ty::new_imm_ptr(tcx, param(0))], param(0))
} }
sym::volatile_store | sym::unaligned_volatile_store => { sym::volatile_store | sym::unaligned_volatile_store => {
(1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()) (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
} }
sym::ctpop sym::ctpop
@ -339,28 +343,34 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
| sym::bitreverse => (1, vec![param(0)], param(0)), | sym::bitreverse => (1, vec![param(0)], param(0)),
sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => { sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => {
(1, vec![param(0), param(0)], tcx.mk_tup(&[param(0), tcx.types.bool])) (1, vec![param(0), param(0)], Ty::new_tup(tcx, &[param(0), tcx.types.bool]))
} }
sym::ptr_guaranteed_cmp => { sym::ptr_guaranteed_cmp => (
(1, vec![tcx.mk_imm_ptr(param(0)), tcx.mk_imm_ptr(param(0))], tcx.types.u8) 1,
} vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
tcx.types.u8,
),
sym::const_allocate => { sym::const_allocate => {
(0, vec![tcx.types.usize, tcx.types.usize], tcx.mk_mut_ptr(tcx.types.u8)) (0, vec![tcx.types.usize, tcx.types.usize], Ty::new_mut_ptr(tcx, tcx.types.u8))
} }
sym::const_deallocate => ( sym::const_deallocate => (
0, 0,
vec![tcx.mk_mut_ptr(tcx.types.u8), tcx.types.usize, tcx.types.usize], vec![Ty::new_mut_ptr(tcx, tcx.types.u8), tcx.types.usize, tcx.types.usize],
tcx.mk_unit(), Ty::new_unit(tcx),
), ),
sym::ptr_offset_from => { sym::ptr_offset_from => (
(1, vec![tcx.mk_imm_ptr(param(0)), tcx.mk_imm_ptr(param(0))], tcx.types.isize) 1,
} vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
sym::ptr_offset_from_unsigned => { tcx.types.isize,
(1, vec![tcx.mk_imm_ptr(param(0)), tcx.mk_imm_ptr(param(0))], tcx.types.usize) ),
} sym::ptr_offset_from_unsigned => (
1,
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
tcx.types.usize,
),
sym::unchecked_div | sym::unchecked_rem | sym::exact_div => { sym::unchecked_div | sym::unchecked_rem | sym::exact_div => {
(1, vec![param(0), param(0)], param(0)) (1, vec![param(0), param(0)], param(0))
} }
@ -379,12 +389,14 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
} }
sym::float_to_int_unchecked => (2, vec![param(0)], param(1)), sym::float_to_int_unchecked => (2, vec![param(0)], param(1)),
sym::assume => (0, vec![tcx.types.bool], tcx.mk_unit()), sym::assume => (0, vec![tcx.types.bool], Ty::new_unit(tcx)),
sym::likely => (0, vec![tcx.types.bool], tcx.types.bool), sym::likely => (0, vec![tcx.types.bool], tcx.types.bool),
sym::unlikely => (0, vec![tcx.types.bool], tcx.types.bool), sym::unlikely => (0, vec![tcx.types.bool], tcx.types.bool),
sym::read_via_copy => (1, vec![tcx.mk_imm_ptr(param(0))], param(0)), sym::read_via_copy => (1, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
sym::write_via_move => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()), sym::write_via_move => {
(1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
}
sym::discriminant_value => { sym::discriminant_value => {
let assoc_items = tcx.associated_item_def_ids( let assoc_items = tcx.associated_item_def_ids(
@ -395,48 +407,47 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) }; let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
( (
1, 1,
vec![ vec![Ty::new_imm_ref(
tcx.mk_imm_ref( tcx,
ty::Region::new_late_bound(tcx, ty::INNERMOST, br), ty::Region::new_late_bound(tcx, ty::INNERMOST, br),
param(0), param(0),
), )],
], Ty::new_projection(tcx, discriminant_def_id, tcx.mk_substs(&[param(0).into()])),
tcx.mk_projection(discriminant_def_id, tcx.mk_substs(&[param(0).into()])),
) )
} }
kw::Try => { kw::Try => {
let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8); let mut_u8 = Ty::new_mut_ptr(tcx, tcx.types.u8);
let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig( let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
[mut_u8], [mut_u8],
tcx.mk_unit(), Ty::new_unit(tcx),
false, false,
hir::Unsafety::Normal, hir::Unsafety::Normal,
Abi::Rust, Abi::Rust,
)); ));
let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig( let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
[mut_u8, mut_u8], [mut_u8, mut_u8],
tcx.mk_unit(), Ty::new_unit(tcx),
false, false,
hir::Unsafety::Normal, hir::Unsafety::Normal,
Abi::Rust, Abi::Rust,
)); ));
( (
0, 0,
vec![tcx.mk_fn_ptr(try_fn_ty), mut_u8, tcx.mk_fn_ptr(catch_fn_ty)], vec![Ty::new_fn_ptr(tcx, try_fn_ty), mut_u8, Ty::new_fn_ptr(tcx, catch_fn_ty)],
tcx.types.i32, tcx.types.i32,
) )
} }
sym::va_start | sym::va_end => match mk_va_list_ty(hir::Mutability::Mut) { sym::va_start | sym::va_end => match mk_va_list_ty(hir::Mutability::Mut) {
Some((va_list_ref_ty, _)) => (0, vec![va_list_ref_ty], tcx.mk_unit()), Some((va_list_ref_ty, _)) => (0, vec![va_list_ref_ty], Ty::new_unit(tcx)),
None => bug!("`va_list` language item needed for C-variadic intrinsics"), None => bug!("`va_list` language item needed for C-variadic intrinsics"),
}, },
sym::va_copy => match mk_va_list_ty(hir::Mutability::Not) { sym::va_copy => match mk_va_list_ty(hir::Mutability::Not) {
Some((va_list_ref_ty, va_list_ty)) => { Some((va_list_ref_ty, va_list_ty)) => {
let va_list_ptr_ty = tcx.mk_mut_ptr(va_list_ty); let va_list_ptr_ty = Ty::new_mut_ptr(tcx, va_list_ty);
(0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.mk_unit()) (0, vec![va_list_ptr_ty, va_list_ref_ty], Ty::new_unit(tcx))
} }
None => bug!("`va_list` language item needed for C-variadic intrinsics"), None => bug!("`va_list` language item needed for C-variadic intrinsics"),
}, },
@ -446,12 +457,17 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
None => bug!("`va_list` language item needed for C-variadic intrinsics"), None => bug!("`va_list` language item needed for C-variadic intrinsics"),
}, },
sym::nontemporal_store => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()), sym::nontemporal_store => {
(1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
}
sym::raw_eq => { sym::raw_eq => {
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) }; let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
let param_ty = let param_ty = Ty::new_imm_ref(
tcx.mk_imm_ref(ty::Region::new_late_bound(tcx, ty::INNERMOST, br), param(0)); tcx,
ty::Region::new_late_bound(tcx, ty::INNERMOST, br),
param(0),
);
(1, vec![param_ty; 2], tcx.types.bool) (1, vec![param_ty; 2], tcx.types.bool)
} }
@ -460,7 +476,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
sym::const_eval_select => (4, vec![param(0), param(1), param(2)], param(3)), sym::const_eval_select => (4, vec![param(0), param(1), param(2)], param(3)),
sym::vtable_size | sym::vtable_align => { sym::vtable_size | sym::vtable_align => {
(0, vec![tcx.mk_imm_ptr(tcx.mk_unit())], tcx.types.usize) (0, vec![Ty::new_imm_ptr(tcx, Ty::new_unit(tcx))], tcx.types.usize)
} }
other => { other => {
@ -479,7 +495,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
let param = |n| { let param = |n| {
let name = Symbol::intern(&format!("P{}", n)); let name = Symbol::intern(&format!("P{}", n));
tcx.mk_ty_param(n, name) Ty::new_param(tcx, n, name)
}; };
let name = it.ident.name; let name = it.ident.name;
@ -521,7 +537,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
sym::simd_fpowi => (1, vec![param(0), tcx.types.i32], param(0)), sym::simd_fpowi => (1, vec![param(0), tcx.types.i32], param(0)),
sym::simd_fma => (1, vec![param(0), param(0), param(0)], param(0)), sym::simd_fma => (1, vec![param(0), param(0), param(0)], param(0)),
sym::simd_gather => (3, vec![param(0), param(1), param(2)], param(0)), sym::simd_gather => (3, vec![param(0), param(1), param(2)], param(0)),
sym::simd_scatter => (3, vec![param(0), param(1), param(2)], tcx.mk_unit()), sym::simd_scatter => (3, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
sym::simd_insert => (2, vec![param(0), tcx.types.u32, param(1)], param(0)), sym::simd_insert => (2, vec![param(0), tcx.types.u32, param(1)], param(0)),
sym::simd_extract => (2, vec![param(0), tcx.types.u32], param(1)), sym::simd_extract => (2, vec![param(0), tcx.types.u32], param(1)),
sym::simd_cast sym::simd_cast
@ -550,7 +566,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
name if name.as_str().starts_with("simd_shuffle") => { name if name.as_str().starts_with("simd_shuffle") => {
match name.as_str()["simd_shuffle".len()..].parse() { match name.as_str()["simd_shuffle".len()..].parse() {
Ok(n) => { Ok(n) => {
let params = vec![param(0), param(0), tcx.mk_array(tcx.types.u32, n)]; let params = vec![param(0), param(0), Ty::new_array(tcx, tcx.types.u32, n)];
(2, params, param(1)) (2, params, param(1))
} }
Err(_) => { Err(_) => {

View file

@ -561,7 +561,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'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.mk_ty_param(ty_param.index, ty_param.name); let ty_param = Ty::new_param(tcx, ty_param.index, 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);

View file

@ -336,15 +336,17 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> Coe
infcx.sub_regions(infer::RelateObjectBound(span), r_b, r_a); infcx.sub_regions(infer::RelateObjectBound(span), r_b, r_a);
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a }; let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
let mt_b = ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b }; let mt_b = ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b };
check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ref(r_b, ty)) check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ref(tcx, r_b, ty))
} }
(&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(mt_b)) => { (&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(mt_b)) => {
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a }; let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ptr(ty)) check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ptr(tcx, ty))
} }
(&ty::RawPtr(mt_a), &ty::RawPtr(mt_b)) => check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ptr(ty)), (&ty::RawPtr(mt_a), &ty::RawPtr(mt_b)) => {
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ptr(tcx, ty))
}
(&ty::Adt(def_a, substs_a), &ty::Adt(def_b, substs_b)) (&ty::Adt(def_a, substs_a), &ty::Adt(def_b, substs_b))
if def_a.is_struct() && def_b.is_struct() => if def_a.is_struct() && def_b.is_struct() =>

View file

@ -343,7 +343,7 @@ fn emit_orphan_check_error<'tcx>(
// That way if we had `Vec<MyType>`, we will properly attribute the // That way if we had `Vec<MyType>`, we will properly attribute the
// problem to `Vec<T>` and avoid confusing the user if they were to see // problem to `Vec<T>` and avoid confusing the user if they were to see
// `MyType` in the error. // `MyType` in the error.
ty::Adt(def, _) => tcx.mk_adt(*def, ty::List::empty()), ty::Adt(def, _) => Ty::new_adt(tcx, *def, ty::List::empty()),
_ => ty, _ => ty,
}; };
let msg = |ty: &str, postfix: &str| { let msg = |ty: &str, postfix: &str| {
@ -605,7 +605,9 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty:
} }
let self_ty_root = match self_ty.kind() { let self_ty_root = match self_ty.kind() {
ty::Adt(def, _) => tcx.mk_adt(*def, InternalSubsts::identity_for_item(tcx, def.did())), ty::Adt(def, _) => {
Ty::new_adt(tcx, *def, InternalSubsts::identity_for_item(tcx, def.did()))
}
_ => unimplemented!("unexpected self ty {:?}", self_ty), _ => unimplemented!("unexpected self ty {:?}", self_ty),
}; };

View file

@ -380,7 +380,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
} }
fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> { fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
self.tcx().ty_error_with_message(span, "bad placeholder type") Ty::new_error_with_message(self.tcx(), span, "bad placeholder type")
} }
fn ct_infer(&self, ty: Ty<'tcx>, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> { fn ct_infer(&self, ty: Ty<'tcx>, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
@ -407,7 +407,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
item_segment, item_segment,
trait_ref.substs, trait_ref.substs,
); );
self.tcx().mk_projection(item_def_id, item_substs) Ty::new_projection(self.tcx(), item_def_id, item_substs)
} else { } else {
// There are no late-bound regions; we can just ignore the binder. // There are no late-bound regions; we can just ignore the binder.
let (mut mpart_sugg, mut inferred_sugg) = (None, None); let (mut mpart_sugg, mut inferred_sugg) = (None, None);
@ -471,14 +471,15 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
} }
_ => {} _ => {}
} }
self.tcx().ty_error(self.tcx().sess.emit_err( Ty::new_error(
errors::AssociatedTypeTraitUninferredGenericParams { self.tcx(),
self.tcx().sess.emit_err(errors::AssociatedTypeTraitUninferredGenericParams {
span, span,
inferred_sugg, inferred_sugg,
bound, bound,
mpart_sugg, mpart_sugg,
}, }),
)) )
} }
} }
@ -1239,7 +1240,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
} else { } else {
ty::Binder::dummy(tcx.mk_fn_sig( ty::Binder::dummy(tcx.mk_fn_sig(
fn_sig.inputs().iter().copied(), fn_sig.inputs().iter().copied(),
tcx.ty_error(guar), Ty::new_error(tcx, guar),
fn_sig.c_variadic, fn_sig.c_variadic,
fn_sig.unsafety, fn_sig.unsafety,
fn_sig.abi, fn_sig.abi,
@ -1332,7 +1333,7 @@ fn suggest_impl_trait<'tcx>(
let item_ty = ocx.normalize( let item_ty = ocx.normalize(
&ObligationCause::misc(span, def_id), &ObligationCause::misc(span, def_id),
param_env, param_env,
tcx.mk_projection(assoc_item_def_id, substs), Ty::new_projection(tcx, assoc_item_def_id, substs),
); );
// FIXME(compiler-errors): We may benefit from resolving regions here. // FIXME(compiler-errors): We may benefit from resolving regions here.
if ocx.select_where_possible().is_empty() if ocx.select_where_possible().is_empty()

View file

@ -20,7 +20,8 @@ fn associated_type_bounds<'tcx>(
ast_bounds: &'tcx [hir::GenericBound<'tcx>], ast_bounds: &'tcx [hir::GenericBound<'tcx>],
span: Span, span: Span,
) -> &'tcx [(ty::Clause<'tcx>, Span)] { ) -> &'tcx [(ty::Clause<'tcx>, Span)] {
let item_ty = tcx.mk_projection( let item_ty = Ty::new_projection(
tcx,
assoc_item_def_id.to_def_id(), assoc_item_def_id.to_def_id(),
InternalSubsts::identity_for_item(tcx, assoc_item_def_id), InternalSubsts::identity_for_item(tcx, assoc_item_def_id),
); );
@ -91,7 +92,8 @@ pub(super) fn explicit_item_bounds(
tcx, tcx,
opaque_def_id.expect_local(), opaque_def_id.expect_local(),
opaque_ty.bounds, opaque_ty.bounds,
tcx.mk_projection( Ty::new_projection(
tcx,
def_id.to_def_id(), def_id.to_def_id(),
ty::InternalSubsts::identity_for_item(tcx, def_id), ty::InternalSubsts::identity_for_item(tcx, def_id),
), ),
@ -117,9 +119,9 @@ pub(super) fn explicit_item_bounds(
}) => { }) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id); let substs = InternalSubsts::identity_for_item(tcx, def_id);
let item_ty = if *in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() { let item_ty = if *in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
tcx.mk_projection(def_id.to_def_id(), substs) Ty::new_projection(tcx, def_id.to_def_id(), substs)
} else { } else {
tcx.mk_opaque(def_id.to_def_id(), substs) Ty::new_opaque(tcx, def_id.to_def_id(), substs)
}; };
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span) opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
} }

View file

@ -719,6 +719,7 @@ pub(super) fn type_param_predicates(
(item_def_id, def_id, assoc_name): (LocalDefId, LocalDefId, Ident), (item_def_id, def_id, assoc_name): (LocalDefId, LocalDefId, Ident),
) -> ty::GenericPredicates<'_> { ) -> ty::GenericPredicates<'_> {
use rustc_hir::*; use rustc_hir::*;
use rustc_middle::ty::Ty;
// In the AST, bounds can derive from two places. Either // In the AST, bounds can derive from two places. Either
// written inline like `<T: Foo>` or in a where-clause like // written inline like `<T: Foo>` or in a where-clause like
@ -728,7 +729,7 @@ pub(super) fn type_param_predicates(
let param_owner = tcx.hir().ty_param_owner(def_id); let param_owner = tcx.hir().ty_param_owner(def_id);
let generics = tcx.generics_of(param_owner); let generics = tcx.generics_of(param_owner);
let index = generics.param_def_id_to_index[&def_id.to_def_id()]; let index = generics.param_def_id_to_index[&def_id.to_def_id()];
let ty = tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id)); let ty = Ty::new_param(tcx, index, tcx.hir().ty_param_name(def_id));
// Don't look for bounds where the type parameter isn't in scope. // Don't look for bounds where the type parameter isn't in scope.
let parent = if item_def_id == param_owner { let parent = if item_def_id == param_owner {

View file

@ -16,6 +16,7 @@ mod opaque;
fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> { fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
use hir::*; use hir::*;
use rustc_middle::ty::Ty;
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let Node::AnonConst(_) = tcx.hir().get(hir_id) else { panic!() }; let Node::AnonConst(_) = tcx.hir().get(hir_id) else { panic!() };
@ -25,13 +26,13 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
let (generics, arg_idx) = match parent_node { let (generics, arg_idx) = match parent_node {
// Easy case: arrays repeat expressions. // Easy case: arrays repeat expressions.
Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. }) Node::Ty(&hir::Ty { kind: TyKind::Array(_, ref constant), .. })
| Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. }) | Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. })
if constant.hir_id() == hir_id => if constant.hir_id() == hir_id =>
{ {
return tcx.types.usize return tcx.types.usize
} }
Node::Ty(&Ty { kind: TyKind::Typeof(ref e), .. }) if e.hir_id == hir_id => { Node::Ty(&hir::Ty { kind: TyKind::Typeof(ref e), .. }) if e.hir_id == hir_id => {
return tcx.typeck(def_id).node_type(e.hir_id) return tcx.typeck(def_id).node_type(e.hir_id)
} }
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. }) Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
@ -67,7 +68,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
) => ) =>
{ {
let Some(trait_def_id) = trait_ref.trait_def_id() else { let Some(trait_def_id) = trait_ref.trait_def_id() else {
return tcx.ty_error_with_message(tcx.def_span(def_id), "Could not find trait"); return Ty::new_error_with_message(tcx,tcx.def_span(def_id), "Could not find trait");
}; };
let assoc_items = tcx.associated_items(trait_def_id); let assoc_items = tcx.associated_items(trait_def_id);
let assoc_item = assoc_items.find_by_name_and_kind( let assoc_item = assoc_items.find_by_name_and_kind(
@ -79,7 +80,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
.expect("const parameter types cannot be generic") .expect("const parameter types cannot be generic")
} else { } else {
// FIXME(associated_const_equality): add a useful error message here. // FIXME(associated_const_equality): add a useful error message here.
tcx.ty_error_with_message(tcx.def_span(def_id), "Could not find associated const on trait") Ty::new_error_with_message(tcx,tcx.def_span(def_id), "Could not find associated const on trait")
} }
} }
@ -99,7 +100,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
// arm would handle this. // arm would handle this.
// //
// I believe this match arm is only needed for GAT but I am not 100% sure - BoxyUwU // I believe this match arm is only needed for GAT but I am not 100% sure - BoxyUwU
Node::Ty(hir_ty @ Ty { kind: TyKind::Path(QPath::TypeRelative(_, segment)), .. }) => { Node::Ty(hir_ty @ hir::Ty { kind: TyKind::Path(QPath::TypeRelative(_, segment)), .. }) => {
// Find the Item containing the associated type so we can create an ItemCtxt. // Find the Item containing the associated type so we can create an ItemCtxt.
// Using the ItemCtxt convert the HIR for the unresolved assoc type into a // Using the ItemCtxt convert the HIR for the unresolved assoc type into a
// ty which is a fully resolved projection. // ty which is a fully resolved projection.
@ -137,7 +138,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
(generics, arg_index) (generics, arg_index)
} else { } else {
// I dont think it's possible to reach this but I'm not 100% sure - BoxyUwU // I dont think it's possible to reach this but I'm not 100% sure - BoxyUwU
return tcx.ty_error_with_message( return Ty::new_error_with_message(tcx,
tcx.def_span(def_id), tcx.def_span(def_id),
"unexpected non-GAT usage of an anon const", "unexpected non-GAT usage of an anon const",
); );
@ -154,7 +155,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
// As there is no relevant param for `def_id`, we simply return // As there is no relevant param for `def_id`, we simply return
// `None` here. // `None` here.
let Some(type_dependent_def) = tables.type_dependent_def_id(parent_node_id) else { let Some(type_dependent_def) = tables.type_dependent_def_id(parent_node_id) else {
return tcx.ty_error_with_message( return Ty::new_error_with_message(tcx,
tcx.def_span(def_id), tcx.def_span(def_id),
format!("unable to find type-dependent def for {:?}", parent_node_id), format!("unable to find type-dependent def for {:?}", parent_node_id),
); );
@ -174,12 +175,12 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
(tcx.generics_of(type_dependent_def), idx) (tcx.generics_of(type_dependent_def), idx)
} }
Node::Ty(&Ty { kind: TyKind::Path(_), .. }) Node::Ty(&hir::Ty { kind: TyKind::Path(_), .. })
| Node::Expr(&Expr { kind: ExprKind::Path(_) | ExprKind::Struct(..), .. }) | Node::Expr(&Expr { kind: ExprKind::Path(_) | ExprKind::Struct(..), .. })
| Node::TraitRef(..) | Node::TraitRef(..)
| Node::Pat(_) => { | Node::Pat(_) => {
let path = match parent_node { let path = match parent_node {
Node::Ty(&Ty { kind: TyKind::Path(QPath::Resolved(_, path)), .. }) Node::Ty(&hir::Ty { kind: TyKind::Path(QPath::Resolved(_, path)), .. })
| Node::TraitRef(&TraitRef { path, .. }) => &*path, | Node::TraitRef(&TraitRef { path, .. }) => &*path,
Node::Expr(&Expr { Node::Expr(&Expr {
kind: kind:
@ -195,14 +196,14 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
if let Some(path) = get_path_containing_arg_in_pat(pat, hir_id) { if let Some(path) = get_path_containing_arg_in_pat(pat, hir_id) {
path path
} else { } else {
return tcx.ty_error_with_message( return Ty::new_error_with_message(tcx,
tcx.def_span(def_id), tcx.def_span(def_id),
format!("unable to find const parent for {} in pat {:?}", hir_id, pat), format!("unable to find const parent for {} in pat {:?}", hir_id, pat),
); );
} }
} }
_ => { _ => {
return tcx.ty_error_with_message( return Ty::new_error_with_message(tcx,
tcx.def_span(def_id), tcx.def_span(def_id),
format!("unexpected const parent path {:?}", parent_node), format!("unexpected const parent path {:?}", parent_node),
); );
@ -224,7 +225,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
.position(|ct| ct.hir_id == hir_id) .position(|ct| ct.hir_id == hir_id)
.map(|idx| (idx, seg))) .map(|idx| (idx, seg)))
}) else { }) else {
return tcx.ty_error_with_message( return Ty::new_error_with_message(tcx,
tcx.def_span(def_id), tcx.def_span(def_id),
"no arg matching AnonConst in path", "no arg matching AnonConst in path",
); );
@ -233,7 +234,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
let generics = match tcx.res_generics_def_id(segment.res) { let generics = match tcx.res_generics_def_id(segment.res) {
Some(def_id) => tcx.generics_of(def_id), Some(def_id) => tcx.generics_of(def_id),
None => { None => {
return tcx.ty_error_with_message( return Ty::new_error_with_message(tcx,
tcx.def_span(def_id), tcx.def_span(def_id),
format!("unexpected anon const res {:?} in path: {:?}", segment.res, path), format!("unexpected anon const res {:?} in path: {:?}", segment.res, path),
); );
@ -243,7 +244,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
(generics, arg_index) (generics, arg_index)
} }
_ => return tcx.ty_error_with_message( _ => return Ty::new_error_with_message(tcx,
tcx.def_span(def_id), tcx.def_span(def_id),
format!("unexpected const parent in type_of(): {parent_node:?}"), format!("unexpected const parent in type_of(): {parent_node:?}"),
), ),
@ -269,7 +270,8 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
{ {
tcx.type_of(param_def_id).no_bound_vars().expect("const parameter types cannot be generic") tcx.type_of(param_def_id).no_bound_vars().expect("const parameter types cannot be generic")
} else { } else {
return tcx.ty_error_with_message( return Ty::new_error_with_message(
tcx,
tcx.def_span(def_id), tcx.def_span(def_id),
format!("const generic parameter not found in {generics:?} at position {arg_idx:?}"), format!("const generic parameter not found in {generics:?} at position {arg_idx:?}"),
); );
@ -305,6 +307,9 @@ fn get_path_containing_arg_in_pat<'hir>(
} }
pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty<'_>> { pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty<'_>> {
use rustc_hir::*;
use rustc_middle::ty::Ty;
// If we are computing `type_of` the synthesized associated type for an RPITIT in the impl // If we are computing `type_of` the synthesized associated type for an RPITIT in the impl
// side, use `collect_return_position_impl_trait_in_trait_tys` to infer the value of the // side, use `collect_return_position_impl_trait_in_trait_tys` to infer the value of the
// associated type in the impl. // associated type in the impl.
@ -317,7 +322,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
return map[&assoc_item.trait_item_def_id.unwrap()]; return map[&assoc_item.trait_item_def_id.unwrap()];
} }
Err(_) => { Err(_) => {
return ty::EarlyBinder::bind(tcx.ty_error_with_message( return ty::EarlyBinder::bind(Ty::new_error_with_message(
tcx,
DUMMY_SP, DUMMY_SP,
"Could not collect return position impl trait in trait tys", "Could not collect return position impl trait in trait tys",
)); ));
@ -325,8 +331,6 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
} }
} }
use rustc_hir::*;
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let icx = ItemCtxt::new(tcx, def_id); let icx = ItemCtxt::new(tcx, def_id);
@ -335,7 +339,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
Node::TraitItem(item) => match item.kind { Node::TraitItem(item) => match item.kind {
TraitItemKind::Fn(..) => { TraitItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id); let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id.to_def_id(), substs) Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
} }
TraitItemKind::Const(ty, body_id) => body_id TraitItemKind::Const(ty, body_id) => body_id
.and_then(|body_id| { .and_then(|body_id| {
@ -360,7 +364,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
Node::ImplItem(item) => match item.kind { Node::ImplItem(item) => match item.kind {
ImplItemKind::Fn(..) => { ImplItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id); let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id.to_def_id(), substs) Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
} }
ImplItemKind::Const(ty, body_id) => { ImplItemKind::Const(ty, body_id) => {
if is_suggestable_infer_ty(ty) { if is_suggestable_infer_ty(ty) {
@ -417,18 +421,18 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
span: spans.into(), span: spans.into(),
note: (), note: (),
}); });
tcx.ty_error(guar) Ty::new_error(tcx, guar)
} }
_ => icx.to_ty(*self_ty), _ => icx.to_ty(*self_ty),
}, },
ItemKind::Fn(..) => { ItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id); let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id.to_def_id(), substs) Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
} }
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => { ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => {
let def = tcx.adt_def(def_id); let def = tcx.adt_def(def_id);
let substs = InternalSubsts::identity_for_item(tcx, def_id); let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_adt(def, substs) Ty::new_adt(tcx, def, substs)
} }
ItemKind::OpaqueTy(OpaqueTy { ItemKind::OpaqueTy(OpaqueTy {
origin: hir::OpaqueTyOrigin::TyAlias { .. }, origin: hir::OpaqueTyOrigin::TyAlias { .. },
@ -469,10 +473,10 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
Node::ForeignItem(foreign_item) => match foreign_item.kind { Node::ForeignItem(foreign_item) => match foreign_item.kind {
ForeignItemKind::Fn(..) => { ForeignItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id); let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id.to_def_id(), substs) Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
} }
ForeignItemKind::Static(t, _) => icx.to_ty(t), ForeignItemKind::Static(t, _) => icx.to_ty(t),
ForeignItemKind::Type => tcx.mk_foreign(def_id.to_def_id()), ForeignItemKind::Type => Ty::new_foreign(tcx, def_id.to_def_id()),
}, },
Node::Ctor(def) | Node::Variant(Variant { data: def, .. }) => match def { Node::Ctor(def) | Node::Variant(Variant { data: def, .. }) => match def {
@ -481,7 +485,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
} }
VariantData::Tuple(..) => { VariantData::Tuple(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id); let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id.to_def_id(), substs) Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
} }
}, },

View file

@ -84,7 +84,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
_ => "item", _ => "item",
}, },
}); });
tcx.ty_error(reported) Ty::new_error(tcx, reported)
} }
} }
@ -128,7 +128,8 @@ impl TaitConstraintLocator<'_> {
// ``` // ```
let tables = self.tcx.typeck(item_def_id); let tables = self.tcx.typeck(item_def_id);
if let Some(guar) = tables.tainted_by_errors { if let Some(guar) = tables.tainted_by_errors {
self.found = Some(ty::OpaqueHiddenType { span: DUMMY_SP, ty: self.tcx.ty_error(guar) }); self.found =
Some(ty::OpaqueHiddenType { span: DUMMY_SP, ty: Ty::new_error(self.tcx, guar) });
return; return;
} }
@ -162,7 +163,7 @@ impl TaitConstraintLocator<'_> {
if let Some(prev) = &mut self.found { if let Some(prev) = &mut self.found {
if concrete_type.ty != prev.ty && !(concrete_type, prev.ty).references_error() { if concrete_type.ty != prev.ty && !(concrete_type, prev.ty).references_error() {
let guar = prev.report_mismatch(&concrete_type, self.def_id, self.tcx).emit(); let guar = prev.report_mismatch(&concrete_type, self.def_id, self.tcx).emit();
prev.ty = self.tcx.ty_error(guar); prev.ty = Ty::new_error(self.tcx, guar);
} }
} else { } else {
self.found = Some(concrete_type); self.found = Some(concrete_type);
@ -258,7 +259,7 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
if let Some(guar) = tables.tainted_by_errors { if let Some(guar) = tables.tainted_by_errors {
// Some error in the owner fn prevented us from populating // Some error in the owner fn prevented us from populating
// the `concrete_opaque_types` table. // the `concrete_opaque_types` table.
tcx.ty_error(guar) Ty::new_error(tcx, guar)
} else { } else {
// Fall back to the RPIT we inferred during HIR typeck // Fall back to the RPIT we inferred during HIR typeck
if let Some(hir_opaque_ty) = hir_opaque_ty { if let Some(hir_opaque_ty) = hir_opaque_ty {
@ -270,7 +271,7 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
// so we can just make the hidden type be `!`. // so we can just make the hidden type be `!`.
// For backwards compatibility reasons, we fall back to // For backwards compatibility reasons, we fall back to
// `()` until we the diverging default is changed. // `()` until we the diverging default is changed.
tcx.mk_diverging_default() Ty::new_diverging_default(tcx)
} }
} }
} }

View file

@ -319,16 +319,19 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
expected_return_type = main_fnsig.output(); expected_return_type = main_fnsig.output();
} else { } else {
// standard () main return type // standard () main return type
expected_return_type = ty::Binder::dummy(tcx.mk_unit()); expected_return_type = ty::Binder::dummy(Ty::new_unit(tcx));
} }
if error { if error {
return; return;
} }
let se_ty = tcx.mk_fn_ptr(expected_return_type.map_bound(|expected_return_type| { let se_ty = Ty::new_fn_ptr(
tcx,
expected_return_type.map_bound(|expected_return_type| {
tcx.mk_fn_sig([], expected_return_type, false, hir::Unsafety::Normal, Abi::Rust) tcx.mk_fn_sig([], expected_return_type, false, hir::Unsafety::Normal, Abi::Rust)
})); }),
);
require_same_types( require_same_types(
tcx, tcx,
@ -339,7 +342,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
), ),
param_env, param_env,
se_ty, se_ty,
tcx.mk_fn_ptr(main_fnsig), Ty::new_fn_ptr(tcx, main_fnsig),
); );
} }
fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) { fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
@ -397,13 +400,16 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
} }
} }
let se_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig( let se_ty = Ty::new_fn_ptr(
[tcx.types.isize, tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))], tcx,
ty::Binder::dummy(tcx.mk_fn_sig(
[tcx.types.isize, Ty::new_imm_ptr(tcx, Ty::new_imm_ptr(tcx, tcx.types.u8))],
tcx.types.isize, tcx.types.isize,
false, false,
hir::Unsafety::Normal, hir::Unsafety::Normal,
Abi::Rust, Abi::Rust,
))); )),
);
require_same_types( require_same_types(
tcx, tcx,
@ -414,7 +420,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
), ),
ty::ParamEnv::empty(), // start should not have any where bounds. ty::ParamEnv::empty(), // start should not have any where bounds.
se_ty, se_ty,
tcx.mk_fn_ptr(tcx.fn_sig(start_def_id).subst_identity()), Ty::new_fn_ptr(tcx, tcx.fn_sig(start_def_id).subst_identity()),
); );
} }
_ => { _ => {

View file

@ -65,7 +65,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// us to give better error messages (pointing to a usually better // us to give better error messages (pointing to a usually better
// arm for inconsistent arms or to the whole match when a `()` type // arm for inconsistent arms or to the whole match when a `()` type
// is required). // is required).
Expectation::ExpectHasType(ety) if ety != self.tcx.mk_unit() => ety, Expectation::ExpectHasType(ety) if ety != Ty::new_unit(self.tcx) => ety,
_ => self.next_ty_var(TypeVariableOrigin { _ => self.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::MiscVariable, kind: TypeVariableOriginKind::MiscVariable,
span: expr.span, span: expr.span,

View file

@ -233,12 +233,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let Some(trait_def_id) = opt_trait_def_id else { continue }; let Some(trait_def_id) = opt_trait_def_id else { continue };
let opt_input_type = opt_arg_exprs.map(|arg_exprs| { let opt_input_type = opt_arg_exprs.map(|arg_exprs| {
self.tcx.mk_tup_from_iter(arg_exprs.iter().map(|e| { Ty::new_tup_from_iter(
self.tcx,
arg_exprs.iter().map(|e| {
self.next_ty_var(TypeVariableOrigin { self.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeInference, kind: TypeVariableOriginKind::TypeInference,
span: e.span, span: e.span,
}) })
})) }),
)
}); });
if let Some(ok) = self.lookup_method_in_trait( if let Some(ok) = self.lookup_method_in_trait(
@ -435,7 +438,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let err = self.report_invalid_callee(call_expr, callee_expr, callee_ty, arg_exprs); let err = self.report_invalid_callee(call_expr, callee_expr, callee_ty, arg_exprs);
return self.tcx.ty_error(err); return Ty::new_error(self.tcx, err);
} }
}; };

View file

@ -393,7 +393,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
&& fcx && fcx
.try_coerce( .try_coerce(
self.expr, self.expr,
fcx.tcx.mk_ref( Ty::new_ref(fcx.tcx,
fcx.tcx.lifetimes.re_erased, fcx.tcx.lifetimes.re_erased,
TypeAndMut { ty: expr_ty, mutbl }, TypeAndMut { ty: expr_ty, mutbl },
), ),
@ -410,7 +410,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
&& fcx && fcx
.try_coerce( .try_coerce(
self.expr, self.expr,
fcx.tcx.mk_ref( Ty::new_ref(fcx.tcx,
expr_reg, expr_reg,
TypeAndMut { ty: expr_ty, mutbl: Mutability::Mut }, TypeAndMut { ty: expr_ty, mutbl: Mutability::Mut },
), ),
@ -428,7 +428,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
&& fcx && fcx
.try_coerce( .try_coerce(
self.expr, self.expr,
fcx.tcx.mk_ref(reg, TypeAndMut { ty: self.expr_ty, mutbl }), Ty::new_ref(fcx.tcx,reg, TypeAndMut { ty: self.expr_ty, mutbl }),
self.cast_ty, self.cast_ty,
AllowTwoPhase::No, AllowTwoPhase::No,
None, None,
@ -441,7 +441,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
&& fcx && fcx
.try_coerce( .try_coerce(
self.expr, self.expr,
fcx.tcx.mk_ref( Ty::new_ref(fcx.tcx,
fcx.tcx.lifetimes.re_erased, fcx.tcx.lifetimes.re_erased,
TypeAndMut { ty: self.expr_ty, mutbl }, TypeAndMut { ty: self.expr_ty, mutbl },
), ),
@ -765,7 +765,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
let res = fcx.try_coerce( let res = fcx.try_coerce(
self.expr, self.expr,
self.expr_ty, self.expr_ty,
fcx.tcx.mk_fn_ptr(f), Ty::new_fn_ptr(fcx.tcx, f),
AllowTwoPhase::No, AllowTwoPhase::No,
None, None,
); );
@ -957,7 +957,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
// from a region pointer to a vector. // from a region pointer to a vector.
// Coerce to a raw pointer so that we generate AddressOf in MIR. // Coerce to a raw pointer so that we generate AddressOf in MIR.
let array_ptr_type = fcx.tcx.mk_ptr(m_expr); let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr);
fcx.try_coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None) fcx.try_coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None)
.unwrap_or_else(|_| { .unwrap_or_else(|_| {
bug!( bug!(

View file

@ -62,11 +62,11 @@ pub(super) fn check_fn<'a, 'tcx>(
fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType); fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType);
yield_ty yield_ty
} else { } else {
tcx.mk_unit() Ty::new_unit(tcx,)
}; };
// Resume type defaults to `()` if the generator has no argument. // Resume type defaults to `()` if the generator has no argument.
let resume_ty = fn_sig.inputs().get(0).copied().unwrap_or_else(|| tcx.mk_unit()); let resume_ty = fn_sig.inputs().get(0).copied().unwrap_or_else(|| Ty::new_unit(tcx,));
fcx.resume_yield_tys = Some((resume_ty, yield_ty)); fcx.resume_yield_tys = Some((resume_ty, yield_ty));
} }
@ -256,10 +256,10 @@ 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_ty = tcx.mk_ty_param(fn_generic.index, fn_generic.name); let generic_ty = Ty::new_param(tcx, fn_generic.index, fn_generic.name);
let expected_fn_sig = let expected_fn_sig =
tcx.mk_fn_sig([], generic_ty, false, hir::Unsafety::Normal, Abi::Rust); tcx.mk_fn_sig([], generic_ty, false, hir::Unsafety::Normal, Abi::Rust);
let expected_ty = tcx.mk_fn_ptr(Binder::dummy(expected_fn_sig)); let expected_ty = Ty::new_fn_ptr(tcx, Binder::dummy(expected_fn_sig));
// we emit the same error to suggest changing the arg no matter what's wrong with the arg // we emit the same error to suggest changing the arg no matter what's wrong with the arg
let emit_main_fn_arg_err = || { let emit_main_fn_arg_err = || {
@ -316,9 +316,9 @@ fn check_lang_start_fn<'tcx>(
if !argv_is_okay { if !argv_is_okay {
let inner_ptr_ty = let inner_ptr_ty =
tcx.mk_ptr(ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: tcx.types.u8 }); Ty::new_ptr(tcx, ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: tcx.types.u8 });
let expected_ty = let expected_ty =
tcx.mk_ptr(ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: inner_ptr_ty }); Ty::new_ptr(tcx, ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: inner_ptr_ty });
tcx.sess.emit_err(LangStartIncorrectParam { tcx.sess.emit_err(LangStartIncorrectParam {
param_span: decl.inputs[2].span, param_span: decl.inputs[2].span,
param_num: 3, param_num: 3,

View file

@ -117,7 +117,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}, },
); );
return self.tcx.mk_generator( return Ty::new_generator(
self.tcx,
expr_def_id.to_def_id(), expr_def_id.to_def_id(),
generator_substs.substs, generator_substs.substs,
movability, movability,
@ -128,7 +129,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// the `closures` table. // the `closures` table.
let sig = bound_sig.map_bound(|sig| { let sig = bound_sig.map_bound(|sig| {
self.tcx.mk_fn_sig( self.tcx.mk_fn_sig(
[self.tcx.mk_tup(sig.inputs())], [Ty::new_tup(self.tcx, sig.inputs())],
sig.output(), sig.output(),
sig.c_variadic, sig.c_variadic,
sig.unsafety, sig.unsafety,
@ -155,12 +156,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::ClosureSubstsParts { ty::ClosureSubstsParts {
parent_substs, parent_substs,
closure_kind_ty, closure_kind_ty,
closure_sig_as_fn_ptr_ty: self.tcx.mk_fn_ptr(sig), closure_sig_as_fn_ptr_ty: Ty::new_fn_ptr(self.tcx, sig),
tupled_upvars_ty, tupled_upvars_ty,
}, },
); );
self.tcx.mk_closure(expr_def_id.to_def_id(), closure_substs.substs) Ty::new_closure(self.tcx, expr_def_id.to_def_id(), closure_substs.substs)
} }
/// Given the expected type, figures out what it can about this closure we /// Given the expected type, figures out what it can about this closure we
@ -190,7 +191,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(sig, kind) (sig, kind)
} }
ty::Infer(ty::TyVar(vid)) => self.deduce_closure_signature_from_predicates( ty::Infer(ty::TyVar(vid)) => self.deduce_closure_signature_from_predicates(
self.tcx.mk_ty_var(self.root_var(vid)), Ty::new_var(self.tcx, self.root_var(vid)),
self.obligations_for_self_ty(vid).map(|obl| (obl.predicate, obl.cause.span)), self.obligations_for_self_ty(vid).map(|obl| (obl.predicate, obl.cause.span)),
), ),
ty::FnPtr(sig) => { ty::FnPtr(sig) => {
@ -806,7 +807,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
guar: ErrorGuaranteed, guar: ErrorGuaranteed,
) -> ty::PolyFnSig<'tcx> { ) -> ty::PolyFnSig<'tcx> {
let astconv: &dyn AstConv<'_> = self; let astconv: &dyn AstConv<'_> = self;
let err_ty = self.tcx.ty_error(guar); let err_ty = Ty::new_error(self.tcx, guar);
let supplied_arguments = decl.inputs.iter().map(|a| { let supplied_arguments = decl.inputs.iter().map(|a| {
// Convert the types that the user supplied (if any), but ignore them. // Convert the types that the user supplied (if any), but ignore them.

View file

@ -192,7 +192,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
let _ = self.commit_if_ok(|_| { let _ = self.commit_if_ok(|_| {
self.at(&self.cause, self.param_env).eq(DefineOpaqueTypes::Yes, a, b) self.at(&self.cause, self.param_env).eq(DefineOpaqueTypes::Yes, a, b)
}); });
return success(vec![], self.fcx.tcx.ty_error(guar), vec![]); return success(vec![], Ty::new_error(self.fcx.tcx, guar), vec![]);
} }
// Coercing from `!` to any type is allowed: // Coercing from `!` to any type is allowed:
@ -440,7 +440,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
} }
r_borrow_var.unwrap() r_borrow_var.unwrap()
}; };
let derefd_ty_a = self.tcx.mk_ref( let derefd_ty_a = Ty::new_ref(
self.tcx,
r, r,
TypeAndMut { TypeAndMut {
ty: referent_ty, ty: referent_ty,
@ -558,9 +559,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
Adjustment { kind: Adjust::Deref(None), target: ty_a }, Adjustment { kind: Adjust::Deref(None), target: ty_a },
Adjustment { Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)), kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)),
target: self target: Ty::new_ref(
.tcx self.tcx,
.mk_ref(r_borrow, ty::TypeAndMut { mutbl: mutbl_b, ty: ty_a }), r_borrow,
ty::TypeAndMut { mutbl: mutbl_b, ty: ty_a },
),
}, },
)) ))
} }
@ -571,7 +574,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
Adjustment { kind: Adjust::Deref(None), target: ty_a }, Adjustment { kind: Adjust::Deref(None), target: ty_a },
Adjustment { Adjustment {
kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)), kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)),
target: self.tcx.mk_ptr(ty::TypeAndMut { mutbl: mt_b, ty: ty_a }), target: Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: mt_b, ty: ty_a }),
}, },
)) ))
} }
@ -883,7 +886,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
self.at(&self.cause, self.param_env).normalize(a_sig); self.at(&self.cause, self.param_env).normalize(a_sig);
obligations.extend(o1); obligations.extend(o1);
let a_fn_pointer = self.tcx.mk_fn_ptr(a_sig); let a_fn_pointer = Ty::new_fn_ptr(self.tcx, a_sig);
let InferOk { value, obligations: o2 } = self.coerce_from_safe_fn( let InferOk { value, obligations: o2 } = self.coerce_from_safe_fn(
a_fn_pointer, a_fn_pointer,
a_sig, a_sig,
@ -945,7 +948,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
let closure_sig = substs_a.as_closure().sig(); let closure_sig = substs_a.as_closure().sig();
let unsafety = fn_ty.unsafety(); let unsafety = fn_ty.unsafety();
let pointer_ty = let pointer_ty =
self.tcx.mk_fn_ptr(self.tcx.signature_unclosure(closure_sig, unsafety)); Ty::new_fn_ptr(self.tcx, self.tcx.signature_unclosure(closure_sig, unsafety));
debug!("coerce_closure_to_fn(a={:?}, b={:?}, pty={:?})", a, b, pointer_ty); debug!("coerce_closure_to_fn(a={:?}, b={:?}, pty={:?})", a, b, pointer_ty);
self.unify_and( self.unify_and(
pointer_ty, pointer_ty,
@ -973,7 +976,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
coerce_mutbls(mt_a.mutbl, mutbl_b)?; coerce_mutbls(mt_a.mutbl, mutbl_b)?;
// Check that the types which they point at are compatible. // Check that the types which they point at are compatible.
let a_unsafe = self.tcx.mk_ptr(ty::TypeAndMut { mutbl: mutbl_b, ty: mt_a.ty }); let a_unsafe = Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: mutbl_b, ty: mt_a.ty });
// Although references and unsafe ptrs have the same // Although references and unsafe ptrs have the same
// representation, we still register an Adjust::DerefRef so that // representation, we still register an Adjust::DerefRef so that
// regionck knows that the region for `a` must be valid here. // regionck knows that the region for `a` must be valid here.
@ -1015,7 +1018,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (adjustments, _) = self.register_infer_ok_obligations(ok); let (adjustments, _) = self.register_infer_ok_obligations(ok);
self.apply_adjustments(expr, adjustments); self.apply_adjustments(expr, adjustments);
Ok(if let Err(guar) = expr_ty.error_reported() { self.tcx.ty_error(guar) } else { target }) Ok(if let Err(guar) = expr_ty.error_reported() {
Ty::new_error(self.tcx, guar)
} else {
target
})
} }
/// Same as `try_coerce()`, but without side-effects. /// Same as `try_coerce()`, but without side-effects.
@ -1179,7 +1186,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.map(|ok| self.register_infer_ok_obligations(ok))?; .map(|ok| self.register_infer_ok_obligations(ok))?;
// Reify both sides and return the reified fn pointer type. // Reify both sides and return the reified fn pointer type.
let fn_ptr = self.tcx.mk_fn_ptr(sig); let fn_ptr = Ty::new_fn_ptr(self.tcx, sig);
let prev_adjustment = match prev_ty.kind() { let prev_adjustment = match prev_ty.kind() {
ty::Closure(..) => Adjust::Pointer(PointerCast::ClosureFnPointer(a_sig.unsafety())), ty::Closure(..) => Adjust::Pointer(PointerCast::ClosureFnPointer(a_sig.unsafety())),
ty::FnDef(..) => Adjust::Pointer(PointerCast::ReifyFnPointer), ty::FnDef(..) => Adjust::Pointer(PointerCast::ReifyFnPointer),
@ -1430,7 +1437,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
fcx, fcx,
cause, cause,
None, None,
fcx.tcx.mk_unit(), Ty::new_unit(fcx.tcx),
Some(augment_error), Some(augment_error),
label_unit_as_expected, label_unit_as_expected,
) )
@ -1461,7 +1468,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
// If we see any error types, just propagate that error // If we see any error types, just propagate that error
// upwards. // upwards.
if let Err(guar) = (expression_ty, self.merged_ty()).error_reported() { if let Err(guar) = (expression_ty, self.merged_ty()).error_reported() {
self.final_ty = Some(fcx.tcx.ty_error(guar)); self.final_ty = Some(Ty::new_error(fcx.tcx, guar));
return; return;
} }
@ -1649,7 +1656,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
let reported = err.emit_unless(unsized_return); let reported = err.emit_unless(unsized_return);
self.final_ty = Some(fcx.tcx.ty_error(reported)); self.final_ty = Some(Ty::new_error(fcx.tcx, reported));
} }
} }
} }

View file

@ -1366,10 +1366,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// ``` // ```
let ref_ty = match mutability { let ref_ty = match mutability {
hir::Mutability::Mut => { hir::Mutability::Mut => {
self.tcx.mk_mut_ref(self.tcx.lifetimes.re_static, checked_ty) Ty::new_mut_ref(self.tcx,self.tcx.lifetimes.re_static, checked_ty)
} }
hir::Mutability::Not => { hir::Mutability::Not => {
self.tcx.mk_imm_ref(self.tcx.lifetimes.re_static, checked_ty) Ty::new_imm_ref(self.tcx,self.tcx.lifetimes.re_static, checked_ty)
} }
}; };
if self.can_coerce(ref_ty, expected) { if self.can_coerce(ref_ty, expected) {

View file

@ -94,7 +94,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] { return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
target.to_owned() target.to_owned()
} else { } else {
self.tcx().ty_error(reported) Ty::new_error(self.tcx(), reported)
}; };
} }
@ -321,7 +321,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
tcx.types.never tcx.types.never
} else { } else {
// There was an error; make type-check fail. // There was an error; make type-check fail.
tcx.ty_error_misc() Ty::new_misc_error(tcx)
} }
} }
ExprKind::Ret(ref expr_opt) => self.check_expr_return(expr_opt.as_deref(), expr), ExprKind::Ret(ref expr_opt) => self.check_expr_return(expr_opt.as_deref(), expr),
@ -361,7 +361,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ExprKind::Field(base, field) => self.check_field(expr, &base, field, expected), ExprKind::Field(base, field) => self.check_field(expr, &base, field, expected),
ExprKind::Index(base, idx) => self.check_expr_index(base, idx, expr), ExprKind::Index(base, idx) => self.check_expr_index(base, idx, expr),
ExprKind::Yield(value, ref src) => self.check_expr_yield(value, expr, src), ExprKind::Yield(value, ref src) => self.check_expr_yield(value, expr, src),
hir::ExprKind::Err(guar) => tcx.ty_error(guar), hir::ExprKind::Err(guar) => Ty::new_error(tcx, guar),
} }
} }
@ -399,7 +399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{ {
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp)); err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
} }
oprnd_t = tcx.ty_error(err.emit()); oprnd_t = Ty::new_error(tcx, err.emit());
} }
} }
hir::UnOp::Not => { hir::UnOp::Not => {
@ -449,10 +449,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let tm = ty::TypeAndMut { ty, mutbl }; let tm = ty::TypeAndMut { ty, mutbl };
match kind { match kind {
_ if tm.ty.references_error() => self.tcx.ty_error_misc(), _ if tm.ty.references_error() => Ty::new_misc_error(self.tcx),
hir::BorrowKind::Raw => { hir::BorrowKind::Raw => {
self.check_named_place_expr(oprnd); self.check_named_place_expr(oprnd);
self.tcx.mk_ptr(tm) Ty::new_ptr(self.tcx, tm)
} }
hir::BorrowKind::Ref => { hir::BorrowKind::Ref => {
// Note: at this point, we cannot say what the best lifetime // Note: at this point, we cannot say what the best lifetime
@ -470,7 +470,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// whose address was taken can actually be made to live as long // whose address was taken can actually be made to live as long
// as it needs to live. // as it needs to live.
let region = self.next_region_var(infer::AddrOfRegion(expr.span)); let region = self.next_region_var(infer::AddrOfRegion(expr.span));
self.tcx.mk_ref(region, tm) Ty::new_ref(self.tcx, region, tm)
} }
} }
} }
@ -528,11 +528,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let e = let e =
self.tcx.sess.delay_span_bug(qpath.span(), "`Res::Err` but no error emitted"); self.tcx.sess.delay_span_bug(qpath.span(), "`Res::Err` but no error emitted");
self.set_tainted_by_errors(e); self.set_tainted_by_errors(e);
tcx.ty_error(e) Ty::new_error(tcx, e)
} }
Res::Def(DefKind::Variant, _) => { Res::Def(DefKind::Variant, _) => {
let e = report_unexpected_variant_res(tcx, res, qpath, expr.span, "E0533", "value"); let e = report_unexpected_variant_res(tcx, res, qpath, expr.span, "E0533", "value");
tcx.ty_error(e) Ty::new_error(tcx, e)
} }
_ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0, _ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0,
}; };
@ -620,7 +620,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(ctxt) => ctxt.coerce.as_ref().map(|coerce| coerce.expected_ty()), Some(ctxt) => ctxt.coerce.as_ref().map(|coerce| coerce.expected_ty()),
None => { None => {
// Avoid ICE when `break` is inside a closure (#65383). // Avoid ICE when `break` is inside a closure (#65383).
return tcx.ty_error_with_message( return Ty::new_error_with_message(
tcx,
expr.span, expr.span,
"break was outside loop, but no error was emitted", "break was outside loop, but no error was emitted",
); );
@ -631,7 +632,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If the loop context is not a `loop { }`, then break with // If the loop context is not a `loop { }`, then break with
// a value is illegal, and `opt_coerce_to` will be `None`. // a value is illegal, and `opt_coerce_to` will be `None`.
// Just set expectation to error in that case. // Just set expectation to error in that case.
let coerce_to = opt_coerce_to.unwrap_or_else(|| tcx.ty_error_misc()); let coerce_to = opt_coerce_to.unwrap_or_else(|| Ty::new_misc_error(tcx));
// Recurse without `enclosing_breakables` borrowed. // Recurse without `enclosing_breakables` borrowed.
e_ty = self.check_expr_with_hint(e, coerce_to); e_ty = self.check_expr_with_hint(e, coerce_to);
@ -639,7 +640,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else { } else {
// Otherwise, this is a break *without* a value. That's // Otherwise, this is a break *without* a value. That's
// always legal, and is equivalent to `break ()`. // always legal, and is equivalent to `break ()`.
e_ty = tcx.mk_unit(); e_ty = Ty::new_unit(tcx);
cause = self.misc(expr.span); cause = self.misc(expr.span);
} }
@ -649,7 +650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut enclosing_breakables = self.enclosing_breakables.borrow_mut(); let mut enclosing_breakables = self.enclosing_breakables.borrow_mut();
let Some(ctxt) = enclosing_breakables.opt_find_breakable(target_id) else { let Some(ctxt) = enclosing_breakables.opt_find_breakable(target_id) else {
// Avoid ICE when `break` is inside a closure (#65383). // Avoid ICE when `break` is inside a closure (#65383).
return tcx.ty_error_with_message( return Ty::new_error_with_message(tcx,
expr.span, expr.span,
"break was outside loop, but no error was emitted", "break was outside loop, but no error was emitted",
); );
@ -707,7 +708,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// this can only happen if the `break` was not // this can only happen if the `break` was not
// inside a loop at all, which is caught by the // inside a loop at all, which is caught by the
// loop-checking pass. // loop-checking pass.
let err = self.tcx.ty_error_with_message( let err = Ty::new_error_with_message(
self.tcx,
expr.span, expr.span,
"break was outside loop, but no error was emitted", "break was outside loop, but no error was emitted",
); );
@ -1072,7 +1074,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
let result_ty = coerce.complete(self); let result_ty = coerce.complete(self);
if let Err(guar) = cond_ty.error_reported() { self.tcx.ty_error(guar) } else { result_ty } if let Err(guar) = cond_ty.error_reported() {
Ty::new_error(self.tcx, guar)
} else {
result_ty
}
} }
/// Type check assignment expression `expr` of form `lhs = rhs`. /// Type check assignment expression `expr` of form `lhs = rhs`.
@ -1090,7 +1096,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// The expected type is `bool` but this will result in `()` so we can reasonably // The expected type is `bool` but this will result in `()` so we can reasonably
// say that the user intended to write `lhs == rhs` instead of `lhs = rhs`. // say that the user intended to write `lhs == rhs` instead of `lhs = rhs`.
// The likely cause of this is `if foo = bar { .. }`. // The likely cause of this is `if foo = bar { .. }`.
let actual_ty = self.tcx.mk_unit(); let actual_ty = Ty::new_unit(self.tcx);
let mut err = self.demand_suptype_diag(expr.span, expected_ty, actual_ty).unwrap(); let mut err = self.demand_suptype_diag(expr.span, expected_ty, actual_ty).unwrap();
let lhs_ty = self.check_expr(&lhs); let lhs_ty = self.check_expr(&lhs);
let rhs_ty = self.check_expr(&rhs); let rhs_ty = self.check_expr(&rhs);
@ -1148,7 +1154,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If the assignment expression itself is ill-formed, don't // If the assignment expression itself is ill-formed, don't
// bother emitting another error // bother emitting another error
let reported = err.emit_unless(lhs_ty.references_error() || rhs_ty.references_error()); let reported = err.emit_unless(lhs_ty.references_error() || rhs_ty.references_error());
return self.tcx.ty_error(reported); return Ty::new_error(self.tcx, reported);
} }
let lhs_ty = self.check_expr_with_needs(&lhs, Needs::MutPlace); let lhs_ty = self.check_expr_with_needs(&lhs, Needs::MutPlace);
@ -1195,9 +1201,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.require_type_is_sized(lhs_ty, lhs.span, traits::AssignmentLhsSized); self.require_type_is_sized(lhs_ty, lhs.span, traits::AssignmentLhsSized);
if let Err(guar) = (lhs_ty, rhs_ty).error_reported() { if let Err(guar) = (lhs_ty, rhs_ty).error_reported() {
self.tcx.ty_error(guar) Ty::new_error(self.tcx, guar)
} else { } else {
self.tcx.mk_unit() Ty::new_unit(self.tcx)
} }
} }
@ -1252,7 +1258,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// [1] // [1]
self.tcx.sess.delay_span_bug(body.span, "no coercion, but loop may not break"); self.tcx.sess.delay_span_bug(body.span, "no coercion, but loop may not break");
} }
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.mk_unit()) ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| Ty::new_unit(self.tcx))
} }
/// Checks a method call. /// Checks a method call.
@ -1316,7 +1322,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Eagerly check for some obvious errors. // Eagerly check for some obvious errors.
if let Err(guar) = (t_expr, t_cast).error_reported() { if let Err(guar) = (t_expr, t_cast).error_reported() {
self.tcx.ty_error(guar) Ty::new_error(self.tcx, guar)
} else { } else {
// Defer other checks until we're done type checking. // Defer other checks until we're done type checking.
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut(); let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
@ -1337,7 +1343,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
deferred_cast_checks.push(cast_check); deferred_cast_checks.push(cast_check);
t_cast t_cast
} }
Err(guar) => self.tcx.ty_error(guar), Err(guar) => Ty::new_error(self.tcx, guar),
} }
} }
} }
@ -1377,7 +1383,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}; };
let array_len = args.len() as u64; let array_len = args.len() as u64;
self.suggest_array_len(expr, array_len); self.suggest_array_len(expr, array_len);
self.tcx.mk_array(element_ty, array_len) Ty::new_array(self.tcx, element_ty, array_len)
} }
fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) { fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) {
@ -1465,18 +1471,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}; };
if let Err(guar) = element_ty.error_reported() { if let Err(guar) = element_ty.error_reported() {
return tcx.ty_error(guar); return Ty::new_error(tcx, guar);
} }
self.check_repeat_element_needs_copy_bound(element, count, element_ty); self.check_repeat_element_needs_copy_bound(element, count, element_ty);
self.register_wf_obligation( self.register_wf_obligation(
tcx.mk_array_with_const_len(t, count).into(), Ty::new_array_with_const_len(tcx, t, count).into(),
expr.span, expr.span,
traits::WellFormed(None), traits::WellFormed(None),
); );
tcx.mk_array_with_const_len(t, count) Ty::new_array_with_const_len(tcx, t, count)
} }
fn check_repeat_element_needs_copy_bound( fn check_repeat_element_needs_copy_bound(
@ -1539,9 +1545,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
_ => self.check_expr_with_expectation(&e, NoExpectation), _ => self.check_expr_with_expectation(&e, NoExpectation),
}); });
let tuple = self.tcx.mk_tup_from_iter(elt_ts_iter); let tuple = Ty::new_tup_from_iter(self.tcx, elt_ts_iter);
if let Err(guar) = tuple.error_reported() { if let Err(guar) = tuple.error_reported() {
self.tcx.ty_error(guar) Ty::new_error(self.tcx, guar)
} else { } else {
self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized); self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized);
tuple tuple
@ -1561,7 +1567,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Ok(data) => data, Ok(data) => data,
Err(guar) => { Err(guar) => {
self.check_struct_fields_on_error(fields, base_expr); self.check_struct_fields_on_error(fields, base_expr);
return self.tcx.ty_error(guar); return Ty::new_error(self.tcx, guar);
} }
}; };
@ -1660,7 +1666,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) )
}; };
tcx.ty_error(guar) Ty::new_error(tcx, guar)
}; };
// Make sure to give a type to the field even if there's // Make sure to give a type to the field even if there's
@ -1772,7 +1778,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// `MyStruct<'a, _, F2, C>`, as opposed to just `_`... // `MyStruct<'a, _, F2, C>`, as opposed to just `_`...
// This is important to allow coercions to happen in // This is important to allow coercions to happen in
// `other_struct` itself. See `coerce-in-base-expr.rs`. // `other_struct` itself. See `coerce-in-base-expr.rs`.
let fresh_base_ty = self.tcx.mk_adt(*adt, fresh_substs); let fresh_base_ty = Ty::new_adt(self.tcx, *adt, fresh_substs);
self.check_expr_has_type_or_error( self.check_expr_has_type_or_error(
base_expr, base_expr,
self.resolve_vars_if_possible(fresh_base_ty), self.resolve_vars_if_possible(fresh_base_ty),
@ -2314,7 +2320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
did, did,
expected.only_has_type(self), expected.only_has_type(self),
); );
return self.tcx().ty_error(guar); return Ty::new_error(self.tcx(), guar);
} }
let guar = if field.name == kw::Empty { let guar = if field.name == kw::Empty {
@ -2400,7 +2406,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.emit() err.emit()
}; };
self.tcx().ty_error(guar) Ty::new_error(self.tcx(), guar)
} }
fn suggest_await_on_field_access( fn suggest_await_on_field_access(
@ -2932,7 +2938,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
let reported = err.emit(); let reported = err.emit();
self.tcx.ty_error(reported) Ty::new_error(self.tcx, reported)
} }
} }
} }
@ -3006,7 +3012,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let element_ty = ocx.normalize( let element_ty = ocx.normalize(
&cause, &cause,
self.param_env, self.param_env,
self.tcx.mk_projection(index_trait_output_def_id, impl_trait_ref.substs), Ty::new_projection(self.tcx, index_trait_output_def_id, impl_trait_ref.substs),
); );
let errors = ocx.select_where_possible(); let errors = ocx.select_where_possible();
@ -3054,14 +3060,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// information. Hence, we check the source of the yield expression here and check its // information. Hence, we check the source of the yield expression here and check its
// value's type against `()` (this check should always hold). // value's type against `()` (this check should always hold).
None if src.is_await() => { None if src.is_await() => {
self.check_expr_coercible_to_type(&value, self.tcx.mk_unit(), None); self.check_expr_coercible_to_type(&value, Ty::new_unit(self.tcx), None);
self.tcx.mk_unit() Ty::new_unit(self.tcx)
} }
_ => { _ => {
self.tcx.sess.emit_err(YieldExprOutsideOfGenerator { span: expr.span }); self.tcx.sess.emit_err(YieldExprOutsideOfGenerator { span: expr.span });
// Avoid expressions without types during writeback (#78653). // Avoid expressions without types during writeback (#78653).
self.check_expr(value); self.check_expr(value);
self.tcx.mk_unit() Ty::new_unit(self.tcx)
} }
} }
} }
@ -3088,11 +3094,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.structurally_resolve_type(expr.span, ty); let ty = self.structurally_resolve_type(expr.span, ty);
match *ty.kind() { match *ty.kind() {
ty::FnDef(..) => { ty::FnDef(..) => {
let fnptr_ty = self.tcx.mk_fn_ptr(ty.fn_sig(self.tcx)); let fnptr_ty = Ty::new_fn_ptr(self.tcx, ty.fn_sig(self.tcx));
self.demand_coerce(expr, ty, fnptr_ty, None, AllowTwoPhase::No); self.demand_coerce(expr, ty, fnptr_ty, None, AllowTwoPhase::No);
} }
ty::Ref(_, base_ty, mutbl) => { ty::Ref(_, base_ty, mutbl) => {
let ptr_ty = self.tcx.mk_ptr(ty::TypeAndMut { ty: base_ty, mutbl }); let ptr_ty = Ty::new_ptr(self.tcx, ty::TypeAndMut { ty: base_ty, mutbl });
self.demand_coerce(expr, ty, ptr_ty, None, AllowTwoPhase::No); self.demand_coerce(expr, ty, ptr_ty, None, AllowTwoPhase::No);
} }
_ => {} _ => {}
@ -3127,7 +3133,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if asm.options.contains(ast::InlineAsmOptions::NORETURN) { if asm.options.contains(ast::InlineAsmOptions::NORETURN) {
self.tcx.types.never self.tcx.types.never
} else { } else {
self.tcx.mk_unit() Ty::new_unit(self.tcx)
} }
} }

View file

@ -104,7 +104,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
// type, `?T` is not considered unsolved, but `?I` is. The // type, `?T` is not considered unsolved, but `?I` is. The
// same is true for float variables.) // same is true for float variables.)
let fallback = match ty.kind() { let fallback = match ty.kind() {
_ if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error(e), _ if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx,e),
ty::Infer(ty::IntVar(_)) => self.tcx.types.i32, ty::Infer(ty::IntVar(_)) => self.tcx.types.i32,
ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64, ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64,
_ => match diverging_fallback.get(&ty) { _ => match diverging_fallback.get(&ty) {
@ -287,7 +287,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
let mut diverging_fallback = FxHashMap::default(); let mut diverging_fallback = FxHashMap::default();
diverging_fallback.reserve(diverging_vids.len()); diverging_fallback.reserve(diverging_vids.len());
for &diverging_vid in &diverging_vids { for &diverging_vid in &diverging_vids {
let diverging_ty = self.tcx.mk_ty_var(diverging_vid); let diverging_ty = Ty::new_var(self.tcx, diverging_vid);
let root_vid = self.root_var(diverging_vid); let root_vid = self.root_var(diverging_vid);
let can_reach_non_diverging = coercion_graph let can_reach_non_diverging = coercion_graph
.depth_first_search(root_vid) .depth_first_search(root_vid)
@ -334,7 +334,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
diverging_fallback.insert(diverging_ty, self.tcx.types.unit); diverging_fallback.insert(diverging_ty, self.tcx.types.unit);
} else { } else {
debug!("fallback to ! - all diverging: {:?}", diverging_vid); debug!("fallback to ! - all diverging: {:?}", diverging_vid);
diverging_fallback.insert(diverging_ty, self.tcx.mk_diverging_default()); diverging_fallback.insert(diverging_ty, Ty::new_diverging_default(self.tcx));
} }
} }

View file

@ -453,7 +453,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> { pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> {
match self.typeck_results.borrow().node_types().get(id) { match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => t, Some(&t) => t,
None if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error(e), None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx,e),
None => { None => {
bug!( bug!(
"no type for node {} in fcx {}", "no type for node {} in fcx {}",
@ -467,7 +467,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn node_ty_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> { pub fn node_ty_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
match self.typeck_results.borrow().node_types().get(id) { match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => Some(t), Some(&t) => Some(t),
None if let Some(e) = self.tainted_by_errors() => Some(self.tcx.ty_error(e)), None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx,e)),
None => None, None => None,
} }
} }
@ -558,7 +558,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx, self.tcx,
self.tcx.typeck_root_def_id(expr_def_id.to_def_id()), self.tcx.typeck_root_def_id(expr_def_id.to_def_id()),
); );
let witness = self.tcx.mk_generator_witness_mir(expr_def_id.to_def_id(), substs); let witness = Ty::new_generator_witness_mir(self.tcx, expr_def_id.to_def_id(), substs);
// Unify `interior` with `witness` and collect all the resulting obligations. // Unify `interior` with `witness` and collect all the resulting obligations.
let span = self.tcx.hir().body(body_id).value.span; let span = self.tcx.hir().body(body_id).value.span;
@ -703,7 +703,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
pub(in super::super) fn err_args(&self, len: usize) -> Vec<Ty<'tcx>> { pub(in super::super) fn err_args(&self, len: usize) -> Vec<Ty<'tcx>> {
let ty_error = self.tcx.ty_error_misc(); let ty_error = Ty::new_misc_error(self.tcx);
vec![ty_error; len] vec![ty_error; len]
} }
@ -1242,7 +1242,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
let reported = err.emit(); let reported = err.emit();
return (tcx.ty_error(reported), res); return (Ty::new_error(tcx, reported), res);
} }
} }
} else { } else {
@ -1485,7 +1485,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Ok(normalized_ty) => normalized_ty, Ok(normalized_ty) => normalized_ty,
Err(errors) => { Err(errors) => {
let guar = self.err_ctxt().report_fulfillment_errors(&errors); let guar = self.err_ctxt().report_fulfillment_errors(&errors);
return self.tcx.ty_error(guar); return Ty::new_error(self.tcx,guar);
} }
} }
} else { } else {
@ -1512,7 +1512,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.emit_inference_failure_err(self.body_id, sp, ty.into(), E0282, true) .emit_inference_failure_err(self.body_id, sp, ty.into(), E0282, true)
.emit() .emit()
}); });
let err = self.tcx.ty_error(e); let err = Ty::new_error(self.tcx, e);
self.demand_suptype(sp, err, ty); self.demand_suptype(sp, err, ty);
err err
} }

View file

@ -73,7 +73,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.typeck_results.borrow().expr_ty_adjusted(expr); let ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
let ty = self.resolve_vars_if_possible(ty); let ty = self.resolve_vars_if_possible(ty);
if ty.has_non_region_infer() { if ty.has_non_region_infer() {
self.tcx.ty_error_misc() Ty::new_misc_error(self.tcx)
} else { } else {
self.tcx.erase_regions(ty) self.tcx.erase_regions(ty)
} }
@ -101,7 +101,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let err_inputs = match tuple_arguments { let err_inputs = match tuple_arguments {
DontTupleArguments => err_inputs, DontTupleArguments => err_inputs,
TupleArguments => vec![self.tcx.mk_tup(&err_inputs)], TupleArguments => vec![Ty::new_tup(self.tcx, &err_inputs)],
}; };
self.check_argument_types( self.check_argument_types(
@ -114,7 +114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
tuple_arguments, tuple_arguments,
method.ok().map(|method| method.def_id), method.ok().map(|method| method.def_id),
); );
return self.tcx.ty_error_misc(); return Ty::new_misc_error(self.tcx);
} }
let method = method.unwrap(); let method = method.unwrap();
@ -424,7 +424,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
variadic_error(tcx.sess, arg.span, arg_ty, "c_uint"); variadic_error(tcx.sess, arg.span, arg_ty, "c_uint");
} }
ty::FnDef(..) => { ty::FnDef(..) => {
let ptr_ty = self.tcx.mk_fn_ptr(arg_ty.fn_sig(self.tcx)); let ptr_ty = Ty::new_fn_ptr(self.tcx, arg_ty.fn_sig(self.tcx));
let ptr_ty = self.resolve_vars_if_possible(ptr_ty); let ptr_ty = self.resolve_vars_if_possible(ptr_ty);
variadic_error(tcx.sess, arg.span, arg_ty, &ptr_ty.to_string()); variadic_error(tcx.sess, arg.span, arg_ty, &ptr_ty.to_string());
} }
@ -539,7 +539,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.typeck_results .typeck_results
.borrow() .borrow()
.expr_ty_adjusted_opt(*expr) .expr_ty_adjusted_opt(*expr)
.unwrap_or_else(|| tcx.ty_error_misc()); .unwrap_or_else(|| Ty::new_misc_error(tcx));
(self.resolve_vars_if_possible(ty), normalize_span(expr.span)) (self.resolve_vars_if_possible(ty), normalize_span(expr.span))
}) })
.collect(); .collect();
@ -648,7 +648,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& provided_arg_tys.len() == formal_and_expected_inputs.len() - 1 + tys.len() && provided_arg_tys.len() == formal_and_expected_inputs.len() - 1 + tys.len()
{ {
// Wrap up the N provided arguments starting at this position in a tuple. // Wrap up the N provided arguments starting at this position in a tuple.
let provided_as_tuple = tcx.mk_tup_from_iter( let provided_as_tuple = Ty::new_tup_from_iter(tcx,
provided_arg_tys.iter().map(|(ty, _)| *ty).skip(mismatch_idx).take(tys.len()), provided_arg_tys.iter().map(|(ty, _)| *ty).skip(mismatch_idx).take(tys.len()),
); );
@ -1309,14 +1309,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
match lit.node { match lit.node {
ast::LitKind::Str(..) => tcx.mk_static_str(), ast::LitKind::Str(..) => Ty::new_static_str(tcx),
ast::LitKind::ByteStr(ref v, _) => { ast::LitKind::ByteStr(ref v, _) => Ty::new_imm_ref(
tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_array(tcx.types.u8, v.len() as u64)) tcx,
} tcx.lifetimes.re_static,
Ty::new_array(tcx, tcx.types.u8, v.len() as u64),
),
ast::LitKind::Byte(_) => tcx.types.u8, ast::LitKind::Byte(_) => tcx.types.u8,
ast::LitKind::Char(_) => tcx.types.char, ast::LitKind::Char(_) => tcx.types.char,
ast::LitKind::Int(_, ast::LitIntType::Signed(t)) => tcx.mk_mach_int(ty::int_ty(t)), ast::LitKind::Int(_, ast::LitIntType::Signed(t)) => Ty::new_int(tcx, ty::int_ty(t)),
ast::LitKind::Int(_, ast::LitIntType::Unsigned(t)) => tcx.mk_mach_uint(ty::uint_ty(t)), ast::LitKind::Int(_, ast::LitIntType::Unsigned(t)) => Ty::new_uint(tcx, ty::uint_ty(t)),
ast::LitKind::Int(_, ast::LitIntType::Unsuffixed) => { ast::LitKind::Int(_, ast::LitIntType::Unsuffixed) => {
let opt_ty = expected.to_option(self).and_then(|ty| match ty.kind() { let opt_ty = expected.to_option(self).and_then(|ty| match ty.kind() {
ty::Int(_) | ty::Uint(_) => Some(ty), ty::Int(_) | ty::Uint(_) => Some(ty),
@ -1328,7 +1330,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
opt_ty.unwrap_or_else(|| self.next_int_var()) opt_ty.unwrap_or_else(|| self.next_int_var())
} }
ast::LitKind::Float(_, ast::LitFloatType::Suffixed(t)) => { ast::LitKind::Float(_, ast::LitFloatType::Suffixed(t)) => {
tcx.mk_mach_float(ty::float_ty(t)) Ty::new_float(tcx, ty::float_ty(t))
} }
ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => { ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => {
let opt_ty = expected.to_option(self).and_then(|ty| match ty.kind() { let opt_ty = expected.to_option(self).and_then(|ty| match ty.kind() {
@ -1338,12 +1340,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
opt_ty.unwrap_or_else(|| self.next_float_var()) opt_ty.unwrap_or_else(|| self.next_float_var())
} }
ast::LitKind::Bool(_) => tcx.types.bool, ast::LitKind::Bool(_) => tcx.types.bool,
ast::LitKind::CStr(_, _) => tcx.mk_imm_ref( ast::LitKind::CStr(_, _) => Ty::new_imm_ref(
tcx,
tcx.lifetimes.re_static, tcx.lifetimes.re_static,
tcx.type_of(tcx.require_lang_item(hir::LangItem::CStr, Some(lit.span))) tcx.type_of(tcx.require_lang_item(hir::LangItem::CStr, Some(lit.span)))
.skip_binder(), .skip_binder(),
), ),
ast::LitKind::Err => tcx.ty_error_misc(), ast::LitKind::Err => Ty::new_misc_error(tcx),
} }
} }
@ -1513,7 +1516,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::StmtKind::Item(_) => {} hir::StmtKind::Item(_) => {}
hir::StmtKind::Expr(ref expr) => { hir::StmtKind::Expr(ref expr) => {
// Check with expected type of `()`. // Check with expected type of `()`.
self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit(), |err| { self.check_expr_has_type_or_error(&expr, Ty::new_unit(self.tcx), |err| {
if expr.can_have_side_effects() { if expr.can_have_side_effects() {
self.suggest_semicolon_at_end(expr.span, err); self.suggest_semicolon_at_end(expr.span, err);
} }
@ -1536,7 +1539,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
pub fn check_block_no_value(&self, blk: &'tcx hir::Block<'tcx>) { pub fn check_block_no_value(&self, blk: &'tcx hir::Block<'tcx>) {
let unit = self.tcx.mk_unit(); let unit = Ty::new_unit(self.tcx);
let ty = self.check_block_with_expected(blk, ExpectHasType(unit)); let ty = self.check_block_with_expected(blk, ExpectHasType(unit));
// if the block produces a `!` value, that can always be // if the block produces a `!` value, that can always be
@ -1649,7 +1652,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
blk.span, blk.span,
blk.hir_id, blk.hir_id,
expected_ty, expected_ty,
self.tcx.mk_unit(), Ty::new_unit(self.tcx),
); );
} }
if !self.consider_removing_semicolon(blk, expected_ty, err) { if !self.consider_removing_semicolon(blk, expected_ty, err) {
@ -1795,7 +1798,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) { ) {
if let Err(guar) = ty.error_reported() { if let Err(guar) = ty.error_reported() {
// Override the types everywhere with `err()` to avoid knock on errors. // Override the types everywhere with `err()` to avoid knock on errors.
let err = self.tcx.ty_error(guar); let err = Ty::new_error(self.tcx, guar);
self.write_ty(hir_id, err); self.write_ty(hir_id, err);
self.write_ty(pat.hir_id, err); self.write_ty(pat.hir_id, err);
self.locals.borrow_mut().insert(hir_id, err); self.locals.borrow_mut().insert(hir_id, err);
@ -1823,8 +1826,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let result = self let result = self
.astconv() .astconv()
.associated_path_to_ty(hir_id, path_span, ty.raw, qself, segment, true); .associated_path_to_ty(hir_id, path_span, ty.raw, qself, segment, true);
let ty = let ty = result
result.map(|(ty, _, _)| ty).unwrap_or_else(|guar| self.tcx().ty_error(guar)); .map(|(ty, _, _)| ty)
.unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar));
let ty = self.handle_raw_ty(path_span, ty); let ty = self.handle_raw_ty(path_span, ty);
let result = result.map(|(_, kind, def_id)| (kind, def_id)); let result = result.map(|(_, kind, def_id)| (kind, def_id));

View file

@ -191,7 +191,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
pub fn next_root_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> { pub fn next_root_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
self.tcx.mk_ty_var(self.next_ty_var_id_in_universe(origin, ty::UniverseIndex::ROOT)) Ty::new_var(self.tcx, self.next_ty_var_id_in_universe(origin, ty::UniverseIndex::ROOT))
} }
} }
@ -295,7 +295,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
trait_ref.substs, trait_ref.substs,
); );
self.tcx().mk_projection(item_def_id, item_substs) Ty::new_projection(self.tcx(), item_def_id, item_substs)
} }
fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>> { fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>> {

View file

@ -426,7 +426,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Given `Result<_, E>`, check our expected ty is `Result<_, &E>` for // Given `Result<_, E>`, check our expected ty is `Result<_, &E>` for
// `as_ref` and `as_deref` compatibility. // `as_ref` and `as_deref` compatibility.
let error_tys_equate_as_ref = error_tys.map_or(true, |(found, expected)| { let error_tys_equate_as_ref = error_tys.map_or(true, |(found, expected)| {
self.can_eq(self.param_env, self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, found), expected) self.can_eq(self.param_env, Ty::new_imm_ref(self.tcx,self.tcx.lifetimes.re_erased, found), expected)
}); });
// FIXME: This could/should be extended to suggest `as_mut` and `as_deref_mut`, // FIXME: This could/should be extended to suggest `as_mut` and `as_deref_mut`,
// but those checks need to be a bit more delicate and the benefit is diminishing. // but those checks need to be a bit more delicate and the benefit is diminishing.
@ -515,7 +515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.tcx.hir().is_inside_const_context(hir_id) || !expected.is_box() || found.is_box() { if self.tcx.hir().is_inside_const_context(hir_id) || !expected.is_box() || found.is_box() {
return false; return false;
} }
if self.can_coerce(self.tcx.mk_box(found), expected) { if self.can_coerce(Ty::new_box(self.tcx, found), expected) {
let suggest_boxing = match found.kind() { let suggest_boxing = match found.kind() {
ty::Tuple(tuple) if tuple.is_empty() => { ty::Tuple(tuple) if tuple.is_empty() => {
SuggestBoxing::Unit { start: span.shrink_to_lo(), end: span } SuggestBoxing::Unit { start: span.shrink_to_lo(), end: span }
@ -595,9 +595,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if pin_did.is_none() || self.tcx.lang_items().owned_box().is_none() { if pin_did.is_none() || self.tcx.lang_items().owned_box().is_none() {
return false; return false;
} }
let box_found = self.tcx.mk_box(found); let box_found = Ty::new_box(self.tcx, found);
let pin_box_found = self.tcx.mk_lang_item(box_found, LangItem::Pin).unwrap(); let pin_box_found = Ty::new_lang_item(self.tcx, box_found, LangItem::Pin).unwrap();
let pin_found = self.tcx.mk_lang_item(found, LangItem::Pin).unwrap(); let pin_found = Ty::new_lang_item(self.tcx, found, LangItem::Pin).unwrap();
match expected.kind() { match expected.kind() {
ty::Adt(def, _) if Some(def.did()) == pin_did => { ty::Adt(def, _) if Some(def.did()) == pin_did => {
if self.can_coerce(pin_box_found, expected) { if self.can_coerce(pin_box_found, expected) {

View file

@ -312,7 +312,8 @@ pub fn resolve_interior<'a, 'tcx>(
// Extract type components to build the witness type. // Extract type components to build the witness type.
let type_list = fcx.tcx.mk_type_list_from_iter(type_causes.iter().map(|cause| cause.ty)); let type_list = fcx.tcx.mk_type_list_from_iter(type_causes.iter().map(|cause| cause.ty));
let bound_vars = fcx.tcx.mk_bound_variable_kinds(&bound_vars); let bound_vars = fcx.tcx.mk_bound_variable_kinds(&bound_vars);
let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars)); let witness =
Ty::new_generator_witness(fcx.tcx, ty::Binder::bind_with_vars(type_list, bound_vars));
drop(typeck_results); drop(typeck_results);
// Store the generator types and spans into the typeck results for this generator. // Store the generator types and spans into the typeck results for this generator.
@ -361,7 +362,8 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
let ty = let ty =
self.interior_visitor.fcx.typeck_results.borrow().node_type(id); self.interior_visitor.fcx.typeck_results.borrow().node_type(id);
let tcx = self.interior_visitor.fcx.tcx; let tcx = self.interior_visitor.fcx.tcx;
let ty = tcx.mk_ref( let ty = Ty::new_ref(
tcx,
// Use `ReErased` as `resolve_interior` is going to replace all the // Use `ReErased` as `resolve_interior` is going to replace all the
// regions anyway. // regions anyway.
tcx.lifetimes.re_erased, tcx.lifetimes.re_erased,

View file

@ -154,7 +154,7 @@ fn typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckResults<'tc
fn diagnostic_only_typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckResults<'tcx> { fn diagnostic_only_typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckResults<'tcx> {
let fallback = move || { let fallback = move || {
let span = tcx.hir().span(tcx.hir().local_def_id_to_hir_id(def_id)); let span = tcx.hir().span(tcx.hir().local_def_id_to_hir_id(def_id));
tcx.ty_error_with_message(span, "diagnostic only typeck table used") Ty::new_error_with_message(tcx, span, "diagnostic only typeck table used")
}; };
typeck_with_fallback(tcx, def_id, fallback) typeck_with_fallback(tcx, def_id, fallback)
} }

View file

@ -277,9 +277,11 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
adjustment::Adjust::Deref(overloaded) => { adjustment::Adjust::Deref(overloaded) => {
// Equivalent to *expr or something similar. // Equivalent to *expr or something similar.
let base = if let Some(deref) = overloaded { let base = if let Some(deref) = overloaded {
let ref_ty = self let ref_ty = Ty::new_ref(
.tcx() self.tcx(),
.mk_ref(deref.region, ty::TypeAndMut { ty: target, mutbl: deref.mutbl }); deref.region,
ty::TypeAndMut { ty: target, mutbl: deref.mutbl },
);
self.cat_rvalue(expr.hir_id, expr.span, ref_ty) self.cat_rvalue(expr.hir_id, expr.span, ref_ty)
} else { } else {
previous()? previous()?
@ -489,7 +491,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
let ty::Ref(region, _, mutbl) = *base_ty.kind() else { let ty::Ref(region, _, mutbl) = *base_ty.kind() else {
span_bug!(expr.span, "cat_overloaded_place: base is not a reference"); span_bug!(expr.span, "cat_overloaded_place: base is not a reference");
}; };
let ref_ty = self.tcx().mk_ref(region, ty::TypeAndMut { ty: place_ty, mutbl }); let ref_ty = Ty::new_ref(self.tcx(), region, ty::TypeAndMut { ty: place_ty, mutbl });
let base = self.cat_rvalue(expr.hir_id, expr.span, ref_ty); let base = self.cat_rvalue(expr.hir_id, expr.span, ref_ty);
self.cat_deref(expr, base) self.cat_deref(expr, base)

View file

@ -143,7 +143,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// a custom error in that case. // a custom error in that case.
if illegal_sized_bound.is_none() { if illegal_sized_bound.is_none() {
self.add_obligations( self.add_obligations(
self.tcx.mk_fn_ptr(method_sig), Ty::new_fn_ptr(self.tcx, method_sig),
all_substs, all_substs,
method_predicates, method_predicates,
pick.item.def_id, pick.item.def_id,
@ -171,7 +171,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// time writing the results into the various typeck results. // time writing the results into the various typeck results.
let mut autoderef = self.autoderef(self.call_expr.span, unadjusted_self_ty); let mut autoderef = self.autoderef(self.call_expr.span, unadjusted_self_ty);
let Some((ty, n)) = autoderef.nth(pick.autoderefs) else { let Some((ty, n)) = autoderef.nth(pick.autoderefs) else {
return self.tcx.ty_error_with_message( return Ty::new_error_with_message(self.tcx,
rustc_span::DUMMY_SP, rustc_span::DUMMY_SP,
format!("failed autoderef {}", pick.autoderefs), format!("failed autoderef {}", pick.autoderefs),
); );
@ -187,7 +187,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// Type we're wrapping in a reference, used later for unsizing // Type we're wrapping in a reference, used later for unsizing
let base_ty = target; let base_ty = target;
target = self.tcx.mk_ref(region, ty::TypeAndMut { mutbl, ty: target }); target = Ty::new_ref(self.tcx, region, ty::TypeAndMut { mutbl, ty: target });
// Method call receivers are the primary use case // Method call receivers are the primary use case
// for two-phase borrows. // for two-phase borrows.
@ -200,16 +200,18 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
if unsize { if unsize {
let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() { let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() {
self.tcx.mk_slice(*elem_ty) Ty::new_slice(self.tcx, *elem_ty)
} else { } else {
bug!( bug!(
"AutorefOrPtrAdjustment's unsize flag should only be set for array ty, found {}", "AutorefOrPtrAdjustment's unsize flag should only be set for array ty, found {}",
base_ty base_ty
) )
}; };
target = self target = Ty::new_ref(
.tcx self.tcx,
.mk_ref(region, ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty }); region,
ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty },
);
adjustments adjustments
.push(Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target }); .push(Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target });
} }
@ -218,7 +220,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
target = match target.kind() { target = match target.kind() {
&ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => { &ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => {
assert!(mutbl.is_mut()); assert!(mutbl.is_mut());
self.tcx.mk_ptr(ty::TypeAndMut { mutbl: hir::Mutability::Not, ty }) Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: hir::Mutability::Not, ty })
} }
other => panic!("Cannot adjust receiver type {:?} to const ptr", other), other => panic!("Cannot adjust receiver type {:?} to const ptr", other),
}; };

View file

@ -205,9 +205,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(span) = result.illegal_sized_bound { if let Some(span) = result.illegal_sized_bound {
let mut needs_mut = false; let mut needs_mut = false;
if let ty::Ref(region, t_type, mutability) = self_ty.kind() { if let ty::Ref(region, t_type, mutability) = self_ty.kind() {
let trait_type = self let trait_type = Ty::new_ref(
.tcx self.tcx,
.mk_ref(*region, ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() }); *region,
ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() },
);
// We probe again to see if there might be a borrow mutability discrepancy. // We probe again to see if there might be a borrow mutability discrepancy.
match self.lookup_probe( match self.lookup_probe(
segment.ident, segment.ident,
@ -464,7 +466,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
)); ));
// Also add an obligation for the method type being well-formed. // Also add an obligation for the method type being well-formed.
let method_ty = tcx.mk_fn_ptr(ty::Binder::dummy(fn_sig)); let method_ty = Ty::new_fn_ptr(tcx, ty::Binder::dummy(fn_sig));
debug!( debug!(
"lookup_in_trait_adjusted: matched method method_ty={:?} obligation={:?}", "lookup_in_trait_adjusted: matched method method_ty={:?} obligation={:?}",
method_ty, obligation method_ty, obligation

View file

@ -465,7 +465,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Error(guar) => guar, ty::Error(guar) => guar,
_ => bug!("unexpected bad final type in method autoderef"), _ => bug!("unexpected bad final type in method autoderef"),
}; };
self.demand_eqtype(span, ty, self.tcx.ty_error(guar)); self.demand_eqtype(span, ty, Ty::new_error(self.tcx, guar));
return Err(MethodError::NoMatch(NoMatchData { return Err(MethodError::NoMatch(NoMatchData {
static_candidates: Vec::new(), static_candidates: Vec::new(),
unsatisfied_predicates: Vec::new(), unsatisfied_predicates: Vec::new(),
@ -551,7 +551,7 @@ fn method_autoderef_steps<'tcx>(
steps.push(CandidateStep { steps.push(CandidateStep {
self_ty: infcx.make_query_response_ignoring_pending_obligations( self_ty: infcx.make_query_response_ignoring_pending_obligations(
inference_vars, inference_vars,
infcx.tcx.mk_slice(*elem_ty), Ty::new_slice(infcx.tcx, *elem_ty),
), ),
autoderefs: dereferences, autoderefs: dereferences,
// this could be from an unsafe deref if we had // this could be from an unsafe deref if we had
@ -1215,7 +1215,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// In general, during probing we erase regions. // In general, during probing we erase regions.
let region = tcx.lifetimes.re_erased; let region = tcx.lifetimes.re_erased;
let autoref_ty = tcx.mk_ref(region, ty::TypeAndMut { ty: self_ty, mutbl }); let autoref_ty = Ty::new_ref(tcx, region, ty::TypeAndMut { ty: self_ty, mutbl });
self.pick_method(autoref_ty, unstable_candidates).map(|r| { self.pick_method(autoref_ty, unstable_candidates).map(|r| {
r.map(|mut pick| { r.map(|mut pick| {
pick.autoderefs = step.autoderefs; pick.autoderefs = step.autoderefs;
@ -1245,7 +1245,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}; };
let const_self_ty = ty::TypeAndMut { ty, mutbl: hir::Mutability::Not }; let const_self_ty = ty::TypeAndMut { ty, mutbl: hir::Mutability::Not };
let const_ptr_ty = self.tcx.mk_ptr(const_self_ty); let const_ptr_ty = Ty::new_ptr(self.tcx, const_self_ty);
self.pick_method(const_ptr_ty, unstable_candidates).map(|r| { self.pick_method(const_ptr_ty, unstable_candidates).map(|r| {
r.map(|mut pick| { r.map(|mut pick| {
pick.autoderefs = step.autoderefs; pick.autoderefs = step.autoderefs;

View file

@ -211,7 +211,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() { if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() {
if needs_mut { if needs_mut {
let trait_type = self.tcx.mk_ref( let trait_type = Ty::new_ref(
self.tcx,
*region, *region,
ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() }, ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() },
); );
@ -647,7 +648,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let projection_ty = pred.skip_binder().projection_ty; let projection_ty = pred.skip_binder().projection_ty;
let substs_with_infer_self = tcx.mk_substs_from_iter( let substs_with_infer_self = tcx.mk_substs_from_iter(
iter::once(tcx.mk_ty_var(ty::TyVid::from_u32(0)).into()) iter::once(Ty::new_var(tcx, ty::TyVid::from_u32(0)).into())
.chain(projection_ty.substs.iter().skip(1)), .chain(projection_ty.substs.iter().skip(1)),
); );
@ -2408,8 +2409,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// just this list. // just this list.
for (rcvr_ty, post) in &[ for (rcvr_ty, post) in &[
(rcvr_ty, ""), (rcvr_ty, ""),
(self.tcx.mk_mut_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&mut "), (Ty::new_mut_ref(self.tcx, self.tcx.lifetimes.re_erased, rcvr_ty), "&mut "),
(self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&"), (Ty::new_imm_ref(self.tcx, self.tcx.lifetimes.re_erased, rcvr_ty), "&"),
] { ] {
match self.lookup_probe_for_diagnostic( match self.lookup_probe_for_diagnostic(
item_name, item_name,
@ -2444,10 +2445,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
for (rcvr_ty, pre) in &[ for (rcvr_ty, pre) in &[
(self.tcx.mk_lang_item(*rcvr_ty, LangItem::OwnedBox), "Box::new"), (Ty::new_lang_item(self.tcx, *rcvr_ty, LangItem::OwnedBox), "Box::new"),
(self.tcx.mk_lang_item(*rcvr_ty, LangItem::Pin), "Pin::new"), (Ty::new_lang_item(self.tcx, *rcvr_ty, LangItem::Pin), "Pin::new"),
(self.tcx.mk_diagnostic_item(*rcvr_ty, sym::Arc), "Arc::new"), (Ty::new_diagnostic_item(self.tcx, *rcvr_ty, sym::Arc), "Arc::new"),
(self.tcx.mk_diagnostic_item(*rcvr_ty, sym::Rc), "Rc::new"), (Ty::new_diagnostic_item(self.tcx, *rcvr_ty, sym::Rc), "Rc::new"),
] { ] {
if let Some(new_rcvr_t) = *rcvr_ty if let Some(new_rcvr_t) = *rcvr_ty
&& let Ok(pick) = self.lookup_probe_for_diagnostic( && let Ok(pick) = self.lookup_probe_for_diagnostic(

View file

@ -38,7 +38,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = let ty =
if !lhs_ty.is_ty_var() && !rhs_ty.is_ty_var() && is_builtin_binop(lhs_ty, rhs_ty, op) { if !lhs_ty.is_ty_var() && !rhs_ty.is_ty_var() && is_builtin_binop(lhs_ty, rhs_ty, op) {
self.enforce_builtin_binop_types(lhs.span, lhs_ty, rhs.span, rhs_ty, op); self.enforce_builtin_binop_types(lhs.span, lhs_ty, rhs.span, rhs_ty, op);
self.tcx.mk_unit() Ty::new_unit(self.tcx)
} else { } else {
return_ty return_ty
}; };
@ -297,7 +297,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
// error types are considered "builtin" // error types are considered "builtin"
Err(_) if lhs_ty.references_error() || rhs_ty.references_error() => { Err(_) if lhs_ty.references_error() || rhs_ty.references_error() => {
self.tcx.ty_error_misc() Ty::new_misc_error(self.tcx)
} }
Err(errors) => { Err(errors) => {
let (_, trait_def_id) = let (_, trait_def_id) =
@ -568,7 +568,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
let reported = err.emit(); let reported = err.emit();
self.tcx.ty_error(reported) Ty::new_error(self.tcx, reported)
} }
}; };
@ -752,7 +752,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
err.emit() err.emit()
}); });
self.tcx.ty_error(guar) Ty::new_error(self.tcx, guar)
} }
} }
} }

View file

@ -403,7 +403,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.borrow_mut() .borrow_mut()
.treat_byte_string_as_slice .treat_byte_string_as_slice
.insert(lt.hir_id.local_id); .insert(lt.hir_id.local_id);
pat_ty = tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_slice(tcx.types.u8)); pat_ty = Ty::new_imm_ref(tcx,tcx.lifetimes.re_static, Ty::new_slice(tcx,tcx.types.u8));
} }
} }
@ -412,7 +412,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let expected = self.resolve_vars_if_possible(expected); let expected = self.resolve_vars_if_possible(expected);
pat_ty = match expected.kind() { pat_ty = match expected.kind() {
ty::Adt(def, _) if Some(def.did()) == tcx.lang_items().string() => expected, ty::Adt(def, _) if Some(def.did()) == tcx.lang_items().string() => expected,
ty::Str => tcx.mk_static_str(), ty::Str => Ty::new_static_str(tcx,),
_ => pat_ty, _ => pat_ty,
}; };
} }
@ -474,7 +474,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// There exists a side that didn't meet our criteria that the end-point // There exists a side that didn't meet our criteria that the end-point
// be of a numeric or char type, as checked in `calc_side` above. // be of a numeric or char type, as checked in `calc_side` above.
let guar = self.emit_err_pat_range(span, lhs, rhs); let guar = self.emit_err_pat_range(span, lhs, rhs);
return self.tcx.ty_error(guar); return Ty::new_error(self.tcx, guar);
} }
// Unify each side with `expected`. // Unify each side with `expected`.
@ -494,7 +494,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
demand_eqtype(&mut rhs, lhs); demand_eqtype(&mut rhs, lhs);
if let (Some((true, ..)), _) | (_, Some((true, ..))) = (lhs, rhs) { if let (Some((true, ..)), _) | (_, Some((true, ..))) = (lhs, rhs) {
return self.tcx.ty_error_misc(); return Ty::new_misc_error(self.tcx);
} }
// Find the unified type and check if it's of numeric or char type again. // Find the unified type and check if it's of numeric or char type again.
@ -510,7 +510,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
*fail = true; *fail = true;
} }
let guar = self.emit_err_pat_range(span, lhs, rhs); let guar = self.emit_err_pat_range(span, lhs, rhs);
return self.tcx.ty_error(guar); return Ty::new_error(self.tcx, guar);
} }
ty ty
} }
@ -848,7 +848,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (variant, pat_ty) = match self.check_struct_path(qpath, pat.hir_id) { let (variant, pat_ty) = match self.check_struct_path(qpath, pat.hir_id) {
Ok(data) => data, Ok(data) => data,
Err(guar) => { Err(guar) => {
let err = self.tcx.ty_error(guar); let err = Ty::new_error(self.tcx, guar);
for field in fields { for field in fields {
let ti = ti; let ti = ti;
self.check_pat(field.pat, err, def_bm, ti); self.check_pat(field.pat, err, def_bm, ti);
@ -864,7 +864,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.check_struct_pat_fields(pat_ty, &pat, variant, fields, has_rest_pat, def_bm, ti) { if self.check_struct_pat_fields(pat_ty, &pat, variant, fields, has_rest_pat, def_bm, ti) {
pat_ty pat_ty
} else { } else {
self.tcx.ty_error_misc() Ty::new_misc_error(self.tcx)
} }
} }
@ -884,12 +884,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Res::Err => { Res::Err => {
let e = tcx.sess.delay_span_bug(qpath.span(), "`Res::Err` but no error emitted"); let e = tcx.sess.delay_span_bug(qpath.span(), "`Res::Err` but no error emitted");
self.set_tainted_by_errors(e); self.set_tainted_by_errors(e);
return tcx.ty_error(e); return Ty::new_error(tcx, e);
} }
Res::Def(DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::Variant, _) => { Res::Def(DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::Variant, _) => {
let expected = "unit struct, unit variant or constant"; let expected = "unit struct, unit variant or constant";
let e = report_unexpected_variant_res(tcx, res, qpath, pat.span, "E0533", expected); let e = report_unexpected_variant_res(tcx, res, qpath, pat.span, "E0533", expected);
return tcx.ty_error(e); return Ty::new_error(tcx, e);
} }
Res::SelfCtor(..) Res::SelfCtor(..)
| Res::Def( | Res::Def(
@ -1032,7 +1032,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
let on_error = |e| { let on_error = |e| {
for pat in subpats { for pat in subpats {
self.check_pat(pat, tcx.ty_error(e), def_bm, ti); self.check_pat(pat, Ty::new_error(tcx, e), def_bm, ti);
} }
}; };
let report_unexpected_res = |res: Res| { let report_unexpected_res = |res: Res| {
@ -1049,7 +1049,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let e = tcx.sess.delay_span_bug(pat.span, "`Res::Err` but no error emitted"); let e = tcx.sess.delay_span_bug(pat.span, "`Res::Err` but no error emitted");
self.set_tainted_by_errors(e); self.set_tainted_by_errors(e);
on_error(e); on_error(e);
return tcx.ty_error(e); return Ty::new_error(tcx, e);
} }
// Type-check the path. // Type-check the path.
@ -1057,7 +1057,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.hir_id); self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.hir_id);
if !pat_ty.is_fn() { if !pat_ty.is_fn() {
let e = report_unexpected_res(res); let e = report_unexpected_res(res);
return tcx.ty_error(e); return Ty::new_error(tcx, e);
} }
let variant = match res { let variant = match res {
@ -1065,11 +1065,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let e = tcx.sess.delay_span_bug(pat.span, "`Res::Err` but no error emitted"); let e = tcx.sess.delay_span_bug(pat.span, "`Res::Err` but no error emitted");
self.set_tainted_by_errors(e); self.set_tainted_by_errors(e);
on_error(e); on_error(e);
return tcx.ty_error(e); return Ty::new_error(tcx, e);
} }
Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) => { Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) => {
let e = report_unexpected_res(res); let e = report_unexpected_res(res);
return tcx.ty_error(e); return Ty::new_error(tcx, e);
} }
Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => tcx.expect_variant_res(res), Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => tcx.expect_variant_res(res),
_ => bug!("unexpected pattern resolution: {:?}", res), _ => bug!("unexpected pattern resolution: {:?}", res),
@ -1112,7 +1112,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let e = let e =
self.e0023(pat.span, res, qpath, subpats, &variant.fields.raw, expected, had_err); self.e0023(pat.span, res, qpath, subpats, &variant.fields.raw, expected, had_err);
on_error(e); on_error(e);
return tcx.ty_error(e); return Ty::new_error(tcx, e);
} }
pat_ty pat_ty
} }
@ -1303,16 +1303,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) )
}); });
let element_tys = tcx.mk_type_list_from_iter(element_tys_iter); let element_tys = tcx.mk_type_list_from_iter(element_tys_iter);
let pat_ty = tcx.mk_tup(element_tys); let pat_ty = Ty::new_tup(tcx, 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
// further errors being emitted when using the bindings. #50333 // further errors being emitted when using the bindings. #50333
let element_tys_iter = (0..max_len).map(|_| tcx.ty_error(reported)); let element_tys_iter = (0..max_len).map(|_| Ty::new_error(tcx, reported));
for (_, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) { for (_, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) {
self.check_pat(elem, tcx.ty_error(reported), def_bm, ti); self.check_pat(elem, Ty::new_error(tcx, reported), def_bm, ti);
} }
tcx.mk_tup_from_iter(element_tys_iter) Ty::new_tup_from_iter(tcx, element_tys_iter)
} else { } else {
for (i, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) { for (i, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) {
self.check_pat(elem, element_tys[i], def_bm, ti); self.check_pat(elem, element_tys[i], def_bm, ti);
@ -1357,7 +1357,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Occupied(occupied) => { Occupied(occupied) => {
no_field_errors = false; no_field_errors = false;
let guar = self.error_field_already_bound(span, field.ident, *occupied.get()); let guar = self.error_field_already_bound(span, field.ident, *occupied.get());
tcx.ty_error(guar) Ty::new_error(tcx, guar)
} }
Vacant(vacant) => { Vacant(vacant) => {
vacant.insert(span); vacant.insert(span);
@ -1371,7 +1371,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.unwrap_or_else(|| { .unwrap_or_else(|| {
inexistent_fields.push(field); inexistent_fields.push(field);
no_field_errors = false; no_field_errors = false;
tcx.ty_error_misc() Ty::new_misc_error(tcx)
}) })
} }
}; };
@ -1951,12 +1951,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
kind: TypeVariableOriginKind::TypeInference, kind: TypeVariableOriginKind::TypeInference,
span: inner.span, span: inner.span,
}); });
let box_ty = tcx.mk_box(inner_ty); let box_ty = Ty::new_box(tcx, inner_ty);
self.demand_eqtype_pat(span, expected, box_ty, ti); self.demand_eqtype_pat(span, expected, box_ty, ti);
(box_ty, inner_ty) (box_ty, inner_ty)
} }
Err(guar) => { Err(guar) => {
let err = tcx.ty_error(guar); let err = Ty::new_error(tcx, guar);
(err, err) (err, err)
} }
}; };
@ -2007,7 +2007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
Err(guar) => { Err(guar) => {
let err = tcx.ty_error(guar); let err = Ty::new_error(tcx, guar);
(err, err) (err, err)
} }
}; };
@ -2019,7 +2019,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn new_ref_ty(&self, span: Span, mutbl: hir::Mutability, ty: Ty<'tcx>) -> Ty<'tcx> { fn new_ref_ty(&self, span: Span, mutbl: hir::Mutability, ty: Ty<'tcx>) -> Ty<'tcx> {
let region = self.next_region_var(infer::PatternRegion(span)); let region = self.next_region_var(infer::PatternRegion(span));
let mt = ty::TypeAndMut { ty, mutbl }; let mt = ty::TypeAndMut { ty, mutbl };
self.tcx.mk_ref(region, mt) Ty::new_ref(self.tcx, region, mt)
} }
/// Type check a slice pattern. /// Type check a slice pattern.
@ -2061,7 +2061,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.error_reported() .error_reported()
.err() .err()
.unwrap_or_else(|| self.error_expected_array_or_slice(span, expected, ti)); .unwrap_or_else(|| self.error_expected_array_or_slice(span, expected, ti));
let err = self.tcx.ty_error(guar); let err = Ty::new_error(self.tcx, guar);
(err, Some(err), err) (err, Some(err), err)
} }
}; };
@ -2108,7 +2108,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else if let Some(pat_len) = len.checked_sub(min_len) { } else if let Some(pat_len) = len.checked_sub(min_len) {
// The variable-length pattern was there, // The variable-length pattern was there,
// so it has an array type with the remaining elements left as its size... // so it has an array type with the remaining elements left as its size...
return (Some(self.tcx.mk_array(element_ty, pat_len)), arr_ty); return (Some(Ty::new_array(self.tcx, element_ty, pat_len)), arr_ty);
} else { } else {
// ...however, in this case, there were no remaining elements. // ...however, in this case, there were no remaining elements.
// That is, the slice pattern requires more than the array type offers. // That is, the slice pattern requires more than the array type offers.
@ -2117,7 +2117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else if slice.is_none() { } else if slice.is_none() {
// We have a pattern with a fixed length, // We have a pattern with a fixed length,
// which we can use to infer the length of the array. // which we can use to infer the length of the array.
let updated_arr_ty = self.tcx.mk_array(element_ty, min_len); let updated_arr_ty = Ty::new_array(self.tcx, element_ty, min_len);
self.demand_eqtype(span, updated_arr_ty, arr_ty); self.demand_eqtype(span, updated_arr_ty, arr_ty);
return (None, updated_arr_ty); return (None, updated_arr_ty);
} else { } else {
@ -2128,7 +2128,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}; };
// If we get here, we must have emitted an error. // If we get here, we must have emitted an error.
(Some(self.tcx.ty_error(guar)), arr_ty) (Some(Ty::new_error(self.tcx, guar)), arr_ty)
} }
fn error_scrutinee_inconsistent_length( fn error_scrutinee_inconsistent_length(

View file

@ -90,7 +90,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
); );
} }
let reported = err.emit(); let reported = err.emit();
Some((self.tcx.ty_error(reported), self.tcx.ty_error(reported))) Some((Ty::new_error(self.tcx, reported), Ty::new_error(self.tcx, reported)))
} }
/// To type-check `base_expr[index_expr]`, we progressively autoderef /// To type-check `base_expr[index_expr]`, we progressively autoderef
@ -138,7 +138,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if unsize { if unsize {
// We only unsize arrays here. // We only unsize arrays here.
if let ty::Array(element_ty, _) = adjusted_ty.kind() { if let ty::Array(element_ty, _) = adjusted_ty.kind() {
self_ty = self.tcx.mk_slice(*element_ty); self_ty = Ty::new_slice(self.tcx, *element_ty);
} else { } else {
continue; continue;
} }
@ -162,7 +162,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() { if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() {
adjustments.push(Adjustment { adjustments.push(Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)), kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)),
target: self.tcx.mk_ref( target: Ty::new_ref(
self.tcx,
*region, *region,
ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: adjusted_ty }, ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: adjusted_ty },
), ),
@ -427,9 +428,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
allow_two_phase_borrow: AllowTwoPhase::No, allow_two_phase_borrow: AllowTwoPhase::No,
}; };
adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)); adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(*region, mutbl));
adjustment.target = self adjustment.target = Ty::new_ref(
.tcx self.tcx,
.mk_ref(*region, ty::TypeAndMut { ty: source, mutbl: mutbl.into() }); *region,
ty::TypeAndMut { ty: source, mutbl: mutbl.into() },
);
} }
source = adjustment.target; source = adjustment.target;
} }

View file

@ -300,7 +300,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Build a tuple (U0..Un) of the final upvar types U0..Un // Build a tuple (U0..Un) of the final upvar types U0..Un
// and unify the upvar tuple type in the closure with it: // and unify the upvar tuple type in the closure with it:
let final_tupled_upvars_type = self.tcx.mk_tup(&final_upvar_tys); let final_tupled_upvars_type = Ty::new_tup(self.tcx, &final_upvar_tys);
self.demand_suptype(span, substs.tupled_upvars_ty(), final_tupled_upvars_type); self.demand_suptype(span, substs.tupled_upvars_ty(), final_tupled_upvars_type);
let fake_reads = delegate let fake_reads = delegate
@ -314,8 +314,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.typeck_results.borrow_mut().closure_size_eval.insert( self.typeck_results.borrow_mut().closure_size_eval.insert(
closure_def_id, closure_def_id,
ClosureSizeProfileData { ClosureSizeProfileData {
before_feature_tys: self.tcx.mk_tup(&before_feature_tys), before_feature_tys: Ty::new_tup(self.tcx, &before_feature_tys),
after_feature_tys: self.tcx.mk_tup(&after_feature_tys), after_feature_tys: Ty::new_tup(self.tcx, &after_feature_tys),
}, },
); );
} }
@ -1665,9 +1665,11 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
) -> Ty<'tcx> { ) -> Ty<'tcx> {
match capture_kind { match capture_kind {
ty::UpvarCapture::ByValue => ty, ty::UpvarCapture::ByValue => ty,
ty::UpvarCapture::ByRef(kind) => { ty::UpvarCapture::ByRef(kind) => Ty::new_ref(
tcx.mk_ref(region.unwrap(), ty::TypeAndMut { ty: ty, mutbl: kind.to_mutbl_lossy() }) tcx,
} region.unwrap(),
ty::TypeAndMut { ty: ty, mutbl: kind.to_mutbl_lossy() },
),
} }
} }

View file

@ -232,7 +232,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
// to access an nonexistent index. We assume that more relevant errors will // to access an nonexistent index. We assume that more relevant errors will
// already have been emitted, so we only gate on this with an ICE if no // already have been emitted, so we only gate on this with an ICE if no
// error has been emitted. (#64638) // error has been emitted. (#64638)
self.fcx.tcx.ty_error_with_message( Ty::new_error_with_message(
self.fcx.tcx,
e.span, e.span,
format!("bad index {:?} for base: `{:?}`", index, base), format!("bad index {:?} for base: `{:?}`", index, base),
) )
@ -823,7 +824,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
debug!("Resolver::fold_ty: input type `{:?}` not fully resolvable", t); debug!("Resolver::fold_ty: input type `{:?}` not fully resolvable", t);
let e = self.report_error(t); let e = self.report_error(t);
self.replaced_with_error = Some(e); self.replaced_with_error = Some(e);
self.fcx.tcx.ty_error(e) Ty::new_error(self.fcx.tcx, e)
} }
} }
} }

View file

@ -382,7 +382,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
// any equated inference vars correctly! // any equated inference vars correctly!
let root_vid = self.infcx.root_var(vid); let root_vid = self.infcx.root_var(vid);
if root_vid != vid { if root_vid != vid {
t = self.infcx.tcx.mk_ty_var(root_vid); t = Ty::new_var(self.infcx.tcx, root_vid);
vid = root_vid; vid = root_vid;
} }
@ -785,7 +785,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.interner().mk_bound(self.binder_index, var.into()) Ty::new_bound(self.tcx, self.binder_index, var.into())
} }
} }

View file

@ -26,7 +26,7 @@ use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, TypeVari
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::GenericArg; use rustc_middle::ty::subst::GenericArg;
use rustc_middle::ty::{self, List, TyCtxt}; use rustc_middle::ty::{self, List, Ty, TyCtxt};
use rustc_span::source_map::Span; use rustc_span::source_map::Span;
pub use rustc_middle::infer::canonical::*; pub use rustc_middle::infer::canonical::*;
@ -128,7 +128,7 @@ impl<'tcx> InferCtxt<'tcx> {
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, bound }) => { CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, bound }) => {
let universe_mapped = universe_map(universe); let universe_mapped = universe_map(universe);
let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, bound }; let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, bound };
self.tcx.mk_placeholder(placeholder_mapped).into() Ty::new_placeholder(self.tcx, placeholder_mapped).into()
} }
CanonicalVarKind::Region(ui) => self CanonicalVarKind::Region(ui) => self

View file

@ -520,7 +520,7 @@ impl<'tcx> InferCtxt<'tcx> {
self.at(cause, param_env) self.at(cause, param_env)
.eq( .eq(
DefineOpaqueTypes::Yes, DefineOpaqueTypes::Yes,
self.tcx.mk_opaque(a.def_id.to_def_id(), a.substs), Ty::new_opaque(self.tcx, a.def_id.to_def_id(), a.substs),
b, b,
)? )?
.obligations, .obligations,

View file

@ -322,8 +322,8 @@ impl<'tcx> InferCtxt<'tcx> {
.unify_var_value(vid, Some(val)) .unify_var_value(vid, Some(val))
.map_err(|e| int_unification_error(vid_is_expected, e))?; .map_err(|e| int_unification_error(vid_is_expected, e))?;
match val { match val {
IntType(v) => Ok(self.tcx.mk_mach_int(v)), IntType(v) => Ok(Ty::new_int(self.tcx, v)),
UintType(v) => Ok(self.tcx.mk_mach_uint(v)), UintType(v) => Ok(Ty::new_uint(self.tcx, v)),
} }
} }
@ -338,7 +338,7 @@ impl<'tcx> InferCtxt<'tcx> {
.float_unification_table() .float_unification_table()
.unify_var_value(vid, Some(ty::FloatVarValue(val))) .unify_var_value(vid, Some(ty::FloatVarValue(val)))
.map_err(|e| float_unification_error(vid_is_expected, e))?; .map_err(|e| float_unification_error(vid_is_expected, e))?;
Ok(self.tcx.mk_mach_float(val)) Ok(Ty::new_float(self.tcx, val))
} }
} }

View file

@ -315,7 +315,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let mut err = tcx.sess.create_err(errors::OpaqueCapturesLifetime { let mut err = tcx.sess.create_err(errors::OpaqueCapturesLifetime {
span, span,
opaque_ty: tcx.mk_opaque(opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs), opaque_ty: Ty::new_opaque(tcx, opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs),
opaque_ty_span: tcx.def_span(opaque_ty_key.def_id), opaque_ty_span: tcx.def_span(opaque_ty_key.def_id),
}); });

View file

@ -288,7 +288,7 @@ pub fn suggest_new_region_bound(
// Get the identity type for this RPIT // Get the identity type for this RPIT
let did = item_id.owner_id.to_def_id(); let did = item_id.owner_id.to_def_id();
let ty = tcx.mk_opaque(did, ty::InternalSubsts::identity_for_item(tcx, did)); let ty = Ty::new_opaque(tcx, did, ty::InternalSubsts::identity_for_item(tcx, did));
if let Some(span) = opaque.bounds.iter().find_map(|arg| match arg { if let Some(span) = opaque.bounds.iter().find_map(|arg| match arg {
GenericBound::Outlives(Lifetime { GenericBound::Outlives(Lifetime {

View file

@ -41,8 +41,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// all of the region highlighting machinery only deals with those. // all of the region highlighting machinery only deals with those.
let guar = self.emit_err( let guar = self.emit_err(
var_origin.span(), var_origin.span(),
self.cx.tcx.mk_fn_ptr(ty::Binder::dummy(expected)), Ty::new_fn_ptr(self.cx.tcx,ty::Binder::dummy(expected)),
self.cx.tcx.mk_fn_ptr(ty::Binder::dummy(found)), Ty::new_fn_ptr(self.cx.tcx,ty::Binder::dummy(found)),
*trait_item_def_id, *trait_item_def_id,
); );
return Some(guar); return Some(guar);

View file

@ -11,7 +11,7 @@ use rustc_errors::{
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::traits::ObligationCauseCode; use rustc_middle::traits::ObligationCauseCode;
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::{self, IsSuggestable, Region}; use rustc_middle::ty::{self, IsSuggestable, Region, Ty};
use rustc_span::symbol::kw; use rustc_span::symbol::kw;
use super::ObligationCauseAsDiagArg; use super::ObligationCauseAsDiagArg;
@ -304,7 +304,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let trait_substs = trait_ref let trait_substs = trait_ref
.subst_identity() .subst_identity()
// Replace the explicit self type with `Self` for better suggestion rendering // Replace the explicit self type with `Self` for better suggestion rendering
.with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper)) .with_self_ty(self.tcx, Ty::new_param(self.tcx, 0, kw::SelfUpper))
.substs; .substs;
let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id) let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id)
.rebase_onto(self.tcx, impl_def_id, trait_substs); .rebase_onto(self.tcx, impl_def_id, trait_substs);

View file

@ -188,7 +188,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
match v { match v {
ty::TyVar(v) => { ty::TyVar(v) => {
let opt_ty = self.infcx.inner.borrow_mut().type_variables().probe(v).known(); let opt_ty = self.infcx.inner.borrow_mut().type_variables().probe(v).known();
Some(self.freshen_ty(opt_ty, ty::TyVar(v), |n| self.infcx.tcx.mk_fresh_ty(n))) Some(self.freshen_ty(opt_ty, ty::TyVar(v), |n| Ty::new_fresh(self.infcx.tcx, n)))
} }
ty::IntVar(v) => Some( ty::IntVar(v) => Some(
@ -200,7 +200,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
.probe_value(v) .probe_value(v)
.map(|v| v.to_type(self.infcx.tcx)), .map(|v| v.to_type(self.infcx.tcx)),
ty::IntVar(v), ty::IntVar(v),
|n| self.infcx.tcx.mk_fresh_int_ty(n), |n| Ty::new_fresh_int(self.infcx.tcx, n),
), ),
), ),
@ -213,7 +213,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
.probe_value(v) .probe_value(v)
.map(|v| v.to_type(self.infcx.tcx)), .map(|v| v.to_type(self.infcx.tcx)),
ty::FloatVar(v), ty::FloatVar(v),
|n| self.infcx.tcx.mk_fresh_float_ty(n), |n| Ty::new_fresh_float(self.infcx.tcx, n),
), ),
), ),

View file

@ -277,7 +277,7 @@ where
let origin = *inner.type_variables().var_origin(vid); let origin = *inner.type_variables().var_origin(vid);
let new_var_id = let new_var_id =
inner.type_variables().new_var(self.for_universe, origin); inner.type_variables().new_var(self.for_universe, origin);
let u = self.tcx().mk_ty_var(new_var_id); let u = Ty::new_var(self.tcx(), new_var_id);
// Record that we replaced `vid` with `new_var_id` as part of a generalization // Record that we replaced `vid` with `new_var_id` as part of a generalization
// operation. This is needed to detect cyclic types. To see why, see the // operation. This is needed to detect cyclic types. To see why, see the

View file

@ -6,7 +6,7 @@ use super::{HigherRankedType, InferCtxt};
use crate::infer::CombinedSnapshot; use crate::infer::CombinedSnapshot;
use rustc_middle::ty::fold::FnMutDelegate; use rustc_middle::ty::fold::FnMutDelegate;
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation}; use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
use rustc_middle::ty::{self, Binder, TyCtxt, TypeFoldable}; use rustc_middle::ty::{self, Binder, Ty, TyCtxt, TypeFoldable};
impl<'a, 'tcx> CombineFields<'a, 'tcx> { impl<'a, 'tcx> CombineFields<'a, 'tcx> {
/// Checks whether `for<..> sub <: for<..> sup` holds. /// Checks whether `for<..> sub <: for<..> sup` holds.
@ -88,10 +88,10 @@ impl<'tcx> InferCtxt<'tcx> {
) )
}, },
types: &mut |bound_ty: ty::BoundTy| { types: &mut |bound_ty: ty::BoundTy| {
self.tcx.mk_placeholder(ty::PlaceholderType { Ty::new_placeholder(
universe: next_universe, self.tcx,
bound: bound_ty, ty::PlaceholderType { universe: next_universe, bound: bound_ty },
}) )
}, },
consts: &mut |bound_var: ty::BoundVar, ty| { consts: &mut |bound_var: ty::BoundVar, ty| {
ty::Const::new_placeholder( ty::Const::new_placeholder(

View file

@ -725,19 +725,19 @@ impl<'tcx> InferCtxt<'tcx> {
.type_variables() .type_variables()
.unsolved_variables() .unsolved_variables()
.into_iter() .into_iter()
.map(|t| self.tcx.mk_ty_var(t)) .map(|t| Ty::new_var(self.tcx, t))
.collect(); .collect();
vars.extend( vars.extend(
(0..inner.int_unification_table().len()) (0..inner.int_unification_table().len())
.map(|i| ty::IntVid { index: i as u32 }) .map(|i| ty::IntVid { index: i as u32 })
.filter(|&vid| inner.int_unification_table().probe_value(vid).is_none()) .filter(|&vid| inner.int_unification_table().probe_value(vid).is_none())
.map(|v| self.tcx.mk_int_var(v)), .map(|v| Ty::new_int_var(self.tcx, v)),
); );
vars.extend( vars.extend(
(0..inner.float_unification_table().len()) (0..inner.float_unification_table().len())
.map(|i| ty::FloatVid { index: i as u32 }) .map(|i| ty::FloatVid { index: i as u32 })
.filter(|&vid| inner.float_unification_table().probe_value(vid).is_none()) .filter(|&vid| inner.float_unification_table().probe_value(vid).is_none())
.map(|v| self.tcx.mk_float_var(v)), .map(|v| Ty::new_float_var(self.tcx, v)),
); );
vars vars
} }
@ -978,7 +978,7 @@ impl<'tcx> InferCtxt<'tcx> {
} }
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> { pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
self.tcx.mk_ty_var(self.next_ty_var_id(origin)) Ty::new_var(self.tcx, self.next_ty_var_id(origin))
} }
pub fn next_ty_var_id_in_universe( pub fn next_ty_var_id_in_universe(
@ -995,7 +995,7 @@ impl<'tcx> InferCtxt<'tcx> {
universe: ty::UniverseIndex, universe: ty::UniverseIndex,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let vid = self.next_ty_var_id_in_universe(origin, universe); let vid = self.next_ty_var_id_in_universe(origin, universe);
self.tcx.mk_ty_var(vid) Ty::new_var(self.tcx, vid)
} }
pub fn next_const_var(&self, ty: Ty<'tcx>, origin: ConstVariableOrigin) -> ty::Const<'tcx> { pub fn next_const_var(&self, ty: Ty<'tcx>, origin: ConstVariableOrigin) -> ty::Const<'tcx> {
@ -1028,7 +1028,7 @@ impl<'tcx> InferCtxt<'tcx> {
} }
pub fn next_int_var(&self) -> Ty<'tcx> { pub fn next_int_var(&self) -> Ty<'tcx> {
self.tcx.mk_int_var(self.next_int_var_id()) Ty::new_int_var(self.tcx, self.next_int_var_id())
} }
fn next_float_var_id(&self) -> FloatVid { fn next_float_var_id(&self) -> FloatVid {
@ -1036,7 +1036,7 @@ impl<'tcx> InferCtxt<'tcx> {
} }
pub fn next_float_var(&self) -> Ty<'tcx> { pub fn next_float_var(&self) -> Ty<'tcx> {
self.tcx.mk_float_var(self.next_float_var_id()) Ty::new_float_var(self.tcx, self.next_float_var_id())
} }
/// Creates a fresh region variable with the next available index. /// Creates a fresh region variable with the next available index.
@ -1116,7 +1116,7 @@ impl<'tcx> InferCtxt<'tcx> {
}, },
); );
self.tcx.mk_ty_var(ty_var_id).into() Ty::new_var(self.tcx, ty_var_id).into()
} }
GenericParamDefKind::Const { .. } => { GenericParamDefKind::Const { .. } => {
let origin = ConstVariableOrigin { let origin = ConstVariableOrigin {
@ -1265,7 +1265,7 @@ impl<'tcx> InferCtxt<'tcx> {
if let Some(value) = inner.int_unification_table().probe_value(vid) { if let Some(value) = inner.int_unification_table().probe_value(vid) {
value.to_type(self.tcx) value.to_type(self.tcx)
} else { } else {
self.tcx.mk_int_var(inner.int_unification_table().find(vid)) Ty::new_int_var(self.tcx, inner.int_unification_table().find(vid))
} }
} }
@ -1276,7 +1276,7 @@ impl<'tcx> InferCtxt<'tcx> {
if let Some(value) = inner.float_unification_table().probe_value(vid) { if let Some(value) = inner.float_unification_table().probe_value(vid) {
value.to_type(self.tcx) value.to_type(self.tcx)
} else { } else {
self.tcx.mk_float_var(inner.float_unification_table().find(vid)) Ty::new_float_var(self.tcx, inner.float_unification_table().find(vid))
} }
} }
@ -1945,13 +1945,16 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
self.idx += 1; self.idx += 1;
idx idx
}; };
self.tcx.mk_placeholder(ty::PlaceholderType { Ty::new_placeholder(
self.tcx,
ty::PlaceholderType {
universe: ty::UniverseIndex::ROOT, universe: ty::UniverseIndex::ROOT,
bound: ty::BoundTy { bound: ty::BoundTy {
var: ty::BoundVar::from_u32(idx), var: ty::BoundVar::from_u32(idx),
kind: ty::BoundTyKind::Anon, kind: ty::BoundTyKind::Anon,
}, },
}) },
)
} else { } else {
t.super_fold_with(self) t.super_fold_with(self)
} }

View file

@ -118,7 +118,7 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
(&ty::Error(e), _) | (_, &ty::Error(e)) => { (&ty::Error(e), _) | (_, &ty::Error(e)) => {
infcx.set_tainted_by_errors(e); infcx.set_tainted_by_errors(e);
Ok(self.tcx().ty_error(e)) Ok(Ty::new_error(self.tcx(), e))
} }
( (

View file

@ -3,7 +3,7 @@ use smallvec::smallvec;
use crate::infer::outlives::components::{push_outlives_components, Component}; use crate::infer::outlives::components::{push_outlives_components, Component};
use crate::traits::{self, Obligation, PredicateObligation}; use crate::traits::{self, Obligation, PredicateObligation};
use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
use rustc_middle::ty::{self, ToPredicate, TyCtxt}; use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use rustc_span::Span; use rustc_span::Span;
@ -344,7 +344,7 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
} }
Component::Param(p) => { Component::Param(p) => {
let ty = tcx.mk_ty_param(p.index, p.name); let ty = Ty::new_param(tcx, p.index, p.name);
Some(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty, r_min))) Some(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty, r_min)))
} }

View file

@ -674,21 +674,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
return; return;
} }
let def = cx.tcx.adt_def(item.owner_id); let def = cx.tcx.adt_def(item.owner_id);
(def, cx.tcx.mk_adt(def, ty::List::empty())) (def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
} }
hir::ItemKind::Union(_, ref ast_generics) => { hir::ItemKind::Union(_, ref ast_generics) => {
if !ast_generics.params.is_empty() { if !ast_generics.params.is_empty() {
return; return;
} }
let def = cx.tcx.adt_def(item.owner_id); let def = cx.tcx.adt_def(item.owner_id);
(def, cx.tcx.mk_adt(def, ty::List::empty())) (def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
} }
hir::ItemKind::Enum(_, ref ast_generics) => { hir::ItemKind::Enum(_, ref ast_generics) => {
if !ast_generics.params.is_empty() { if !ast_generics.params.is_empty() {
return; return;
} }
let def = cx.tcx.adt_def(item.owner_id); let def = cx.tcx.adt_def(item.owner_id);
(def, cx.tcx.mk_adt(def, ty::List::empty())) (def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
} }
_ => return, _ => return,
}; };

View file

@ -1345,7 +1345,7 @@ impl<'tcx> LateContext<'tcx> {
tcx.associated_items(trait_id) tcx.associated_items(trait_id)
.find_by_name_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id) .find_by_name_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id)
.and_then(|assoc| { .and_then(|assoc| {
let proj = tcx.mk_projection(assoc.def_id, [self_ty]); let proj = Ty::new_projection(tcx, assoc.def_id, [self_ty]);
tcx.try_normalize_erasing_regions(self.param_env, proj).ok() tcx.try_normalize_erasing_regions(self.param_env, proj).ok()
}) })
} }

View file

@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
} }
let proj_ty = let proj_ty =
cx.tcx.mk_projection(proj.projection_ty.def_id, proj.projection_ty.substs); Ty::new_projection(cx.tcx, proj.projection_ty.def_id, proj.projection_ty.substs);
// For every instance of the projection type in the bounds, // For every instance of the projection type in the bounds,
// replace them with the term we're assigning to the associated // replace them with the term we're assigning to the associated
// type in our opaque type. // type in our opaque type.
@ -144,7 +144,8 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
OPAQUE_HIDDEN_INFERRED_BOUND, OPAQUE_HIDDEN_INFERRED_BOUND,
pred_span, pred_span,
OpaqueHiddenInferredBoundLint { OpaqueHiddenInferredBoundLint {
ty: cx.tcx.mk_opaque( ty: Ty::new_opaque(
cx.tcx,
def_id, def_id,
ty::InternalSubsts::identity_for_item(cx.tcx, def_id), ty::InternalSubsts::identity_for_item(cx.tcx, def_id),
), ),

View file

@ -862,12 +862,12 @@ fn get_nullable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'t
}; };
return get_nullable_type(cx, inner_field_ty); return get_nullable_type(cx, inner_field_ty);
} }
ty::Int(ty) => tcx.mk_mach_int(ty), ty::Int(ty) => Ty::new_int(tcx, ty),
ty::Uint(ty) => tcx.mk_mach_uint(ty), ty::Uint(ty) => Ty::new_uint(tcx, ty),
ty::RawPtr(ty_mut) => tcx.mk_ptr(ty_mut), ty::RawPtr(ty_mut) => Ty::new_ptr(tcx, ty_mut),
// As these types are always non-null, the nullable equivalent of // As these types are always non-null, the nullable equivalent of
// Option<T> of these types are their raw pointer counterparts. // Option<T> of these types are their raw pointer counterparts.
ty::Ref(_region, ty, mutbl) => tcx.mk_ptr(ty::TypeAndMut { ty, mutbl }), ty::Ref(_region, ty, mutbl) => Ty::new_ptr(tcx, ty::TypeAndMut { ty, mutbl }),
ty::FnPtr(..) => { ty::FnPtr(..) => {
// There is no nullable equivalent for Rust's function pointers -- you // There is no nullable equivalent for Rust's function pointers -- you
// must use an Option<fn(..) -> _> to represent it. // must use an Option<fn(..) -> _> to represent it.

View file

@ -433,7 +433,8 @@ impl<'tcx> CanonicalVarValues<'tcx> {
|(i, info)| -> ty::GenericArg<'tcx> { |(i, info)| -> ty::GenericArg<'tcx> {
match info.kind { match info.kind {
CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => { CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => {
tcx.mk_bound(ty::INNERMOST, ty::BoundVar::from_usize(i).into()).into() Ty::new_bound(tcx, ty::INNERMOST, ty::BoundVar::from_usize(i).into())
.into()
} }
CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => { CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
let br = ty::BoundRegion { let br = ty::BoundRegion {

View file

@ -90,15 +90,15 @@ impl<'tcx> UnifyValue for UnifiedRegion<'tcx> {
impl ToType for ty::IntVarValue { impl ToType for ty::IntVarValue {
fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match *self { match *self {
ty::IntType(i) => tcx.mk_mach_int(i), ty::IntType(i) => Ty::new_int(tcx, i),
ty::UintType(i) => tcx.mk_mach_uint(i), ty::UintType(i) => Ty::new_uint(tcx, i),
} }
} }
} }
impl ToType for ty::FloatVarValue { impl ToType for ty::FloatVarValue {
fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
tcx.mk_mach_float(self.0) Ty::new_float(tcx, self.0)
} }
} }

View file

@ -1913,7 +1913,7 @@ impl<'tcx> Operand<'tcx> {
substs: impl IntoIterator<Item = GenericArg<'tcx>>, substs: impl IntoIterator<Item = GenericArg<'tcx>>,
span: Span, span: Span,
) -> Self { ) -> Self {
let ty = tcx.mk_fn_def(def_id, substs); let ty = Ty::new_fn_def(tcx, def_id, substs);
Operand::Constant(Box::new(Constant { Operand::Constant(Box::new(Constant {
span, span,
user_ty: None, user_ty: None,

View file

@ -95,11 +95,13 @@ impl<'tcx> PlaceTy<'tcx> {
ProjectionElem::Subslice { from, to, from_end } => { ProjectionElem::Subslice { from, to, from_end } => {
PlaceTy::from_ty(match self.ty.kind() { PlaceTy::from_ty(match self.ty.kind() {
ty::Slice(..) => self.ty, ty::Slice(..) => self.ty,
ty::Array(inner, _) if !from_end => tcx.mk_array(*inner, (to - from) as u64), ty::Array(inner, _) if !from_end => {
Ty::new_array(tcx, *inner, (to - from) as u64)
}
ty::Array(inner, size) if from_end => { ty::Array(inner, size) if from_end => {
let size = size.eval_target_usize(tcx, param_env); let size = size.eval_target_usize(tcx, param_env);
let len = size - from - to; let len = size - from - to;
tcx.mk_array(*inner, len) Ty::new_array(tcx, *inner, len)
} }
_ => bug!("cannot subslice non-array type: `{:?}`", self), _ => bug!("cannot subslice non-array type: `{:?}`", self),
}) })
@ -162,16 +164,16 @@ 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_array_with_const_len(operand.ty(local_decls, tcx), count) Ty::new_array_with_const_len(tcx, operand.ty(local_decls, tcx), count)
} }
Rvalue::ThreadLocalRef(did) => tcx.thread_local_ptr_ty(did), Rvalue::ThreadLocalRef(did) => tcx.thread_local_ptr_ty(did),
Rvalue::Ref(reg, bk, ref place) => { Rvalue::Ref(reg, bk, ref place) => {
let place_ty = place.ty(local_decls, tcx).ty; let place_ty = place.ty(local_decls, tcx).ty;
tcx.mk_ref(reg, ty::TypeAndMut { ty: place_ty, mutbl: bk.to_mutbl_lossy() }) Ty::new_ref(tcx, reg, ty::TypeAndMut { ty: place_ty, mutbl: bk.to_mutbl_lossy() })
} }
Rvalue::AddressOf(mutability, ref place) => { Rvalue::AddressOf(mutability, ref place) => {
let place_ty = place.ty(local_decls, tcx).ty; let place_ty = place.ty(local_decls, tcx).ty;
tcx.mk_ptr(ty::TypeAndMut { ty: place_ty, mutbl: mutability }) Ty::new_ptr(tcx, ty::TypeAndMut { ty: place_ty, mutbl: mutability })
} }
Rvalue::Len(..) => tcx.types.usize, Rvalue::Len(..) => tcx.types.usize,
Rvalue::Cast(.., ty) => ty, Rvalue::Cast(.., ty) => ty,
@ -184,7 +186,7 @@ impl<'tcx> Rvalue<'tcx> {
let lhs_ty = lhs.ty(local_decls, tcx); let lhs_ty = lhs.ty(local_decls, tcx);
let rhs_ty = rhs.ty(local_decls, tcx); let rhs_ty = rhs.ty(local_decls, tcx);
let ty = op.ty(tcx, lhs_ty, rhs_ty); let ty = op.ty(tcx, lhs_ty, rhs_ty);
tcx.mk_tup(&[ty, tcx.types.bool]) Ty::new_tup(tcx, &[ty, tcx.types.bool])
} }
Rvalue::UnaryOp(UnOp::Not | UnOp::Neg, ref operand) => operand.ty(local_decls, tcx), Rvalue::UnaryOp(UnOp::Not | UnOp::Neg, ref operand) => operand.ty(local_decls, tcx),
Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx), Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx),
@ -192,17 +194,17 @@ impl<'tcx> Rvalue<'tcx> {
tcx.types.usize tcx.types.usize
} }
Rvalue::Aggregate(ref ak, ref ops) => match **ak { Rvalue::Aggregate(ref ak, ref ops) => match **ak {
AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64), AggregateKind::Array(ty) => Ty::new_array(tcx, ty, ops.len() as u64),
AggregateKind::Tuple => { AggregateKind::Tuple => {
tcx.mk_tup_from_iter(ops.iter().map(|op| op.ty(local_decls, tcx))) Ty::new_tup_from_iter(tcx, ops.iter().map(|op| op.ty(local_decls, tcx)))
} }
AggregateKind::Adt(did, _, substs, _, _) => tcx.type_of(did).subst(tcx, substs), AggregateKind::Adt(did, _, substs, _, _) => tcx.type_of(did).subst(tcx, substs),
AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs), AggregateKind::Closure(did, substs) => Ty::new_closure(tcx, did, substs),
AggregateKind::Generator(did, substs, movability) => { AggregateKind::Generator(did, substs, movability) => {
tcx.mk_generator(did, substs, movability) Ty::new_generator(tcx, did, substs, movability)
} }
}, },
Rvalue::ShallowInitBox(_, ty) => tcx.mk_box(ty), Rvalue::ShallowInitBox(_, ty) => Ty::new_box(tcx, ty),
Rvalue::CopyForDeref(ref place) => place.ty(local_decls, tcx).ty, Rvalue::CopyForDeref(ref place) => place.ty(local_decls, tcx).ty,
} }
} }

View file

@ -81,7 +81,7 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
Err(TypeError::Sorts(relate::expected_found(self, a, b))) Err(TypeError::Sorts(relate::expected_found(self, a, b)))
} }
(&ty::Error(guar), _) | (_, &ty::Error(guar)) => Ok(self.tcx().ty_error(guar)), (&ty::Error(guar), _) | (_, &ty::Error(guar)) => Ok(Ty::new_error(self.tcx(), guar)),
_ => relate::structurally_relate_tys(self, a, b), _ => relate::structurally_relate_tys(self, a, b),
} }

Some files were not shown because too many files have changed in this diff Show more