mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 19:23:10 +00:00
Change ty.kind to a method
This commit is contained in:
parent
ef55a0a92f
commit
3e14b684dd
@ -306,10 +306,10 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
||||
use rustc_ast::UintTy::*;
|
||||
use rustc_middle::ty::{Int, Uint};
|
||||
|
||||
let new_kind = match ty.kind {
|
||||
let new_kind = match ty.kind() {
|
||||
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.ptr_width)),
|
||||
Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.ptr_width)),
|
||||
ref t @ (Uint(_) | Int(_)) => t.clone(),
|
||||
t @ (Uint(_) | Int(_)) => t.clone(),
|
||||
_ => panic!("tried to get overflow intrinsic for op applied to non-int type"),
|
||||
};
|
||||
|
||||
|
@ -125,7 +125,7 @@ fn check_and_apply_linkage(
|
||||
// extern "C" fn() from being non-null, so we can't just declare a
|
||||
// static and call it a day. Some linkages (like weak) will make it such
|
||||
// that the static actually has a null value.
|
||||
let llty2 = if let ty::RawPtr(ref mt) = ty.kind {
|
||||
let llty2 = if let ty::RawPtr(ref mt) = ty.kind() {
|
||||
cx.layout_of(mt.ty).llvm_type(cx)
|
||||
} else {
|
||||
cx.sess().span_fatal(
|
||||
|
@ -343,7 +343,7 @@ fn fixed_vec_metadata(
|
||||
|
||||
let (size, align) = cx.size_and_align_of(array_or_slice_type);
|
||||
|
||||
let upper_bound = match array_or_slice_type.kind {
|
||||
let upper_bound = match array_or_slice_type.kind() {
|
||||
ty::Array(_, len) => len.eval_usize(cx.tcx, ty::ParamEnv::reveal_all()) as c_longlong,
|
||||
_ => -1,
|
||||
};
|
||||
@ -432,7 +432,7 @@ fn subroutine_type_metadata(
|
||||
|
||||
let signature_metadata: Vec<_> = iter::once(
|
||||
// return type
|
||||
match signature.output().kind {
|
||||
match signature.output().kind() {
|
||||
ty::Tuple(ref tys) if tys.is_empty() => None,
|
||||
_ => Some(type_metadata(cx, signature.output(), span)),
|
||||
},
|
||||
@ -472,7 +472,7 @@ fn trait_pointer_metadata(
|
||||
// type is assigned the correct name, size, namespace, and source location.
|
||||
// However, it does not describe the trait's methods.
|
||||
|
||||
let containing_scope = match trait_type.kind {
|
||||
let containing_scope = match trait_type.kind() {
|
||||
ty::Dynamic(ref data, ..) => {
|
||||
data.principal_def_id().map(|did| get_namespace_for_item(cx, did))
|
||||
}
|
||||
@ -572,7 +572,7 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp
|
||||
|
||||
debug!("type_metadata: {:?}", t);
|
||||
|
||||
let ptr_metadata = |ty: Ty<'tcx>| match ty.kind {
|
||||
let ptr_metadata = |ty: Ty<'tcx>| match *ty.kind() {
|
||||
ty::Slice(typ) => Ok(vec_slice_metadata(cx, t, typ, unique_type_id, usage_site_span)),
|
||||
ty::Str => Ok(vec_slice_metadata(cx, t, cx.tcx.types.u8, unique_type_id, usage_site_span)),
|
||||
ty::Dynamic(..) => Ok(MetadataCreationResult::new(
|
||||
@ -592,7 +592,7 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp
|
||||
}
|
||||
};
|
||||
|
||||
let MetadataCreationResult { metadata, already_stored_in_typemap } = match t.kind {
|
||||
let MetadataCreationResult { metadata, already_stored_in_typemap } = match *t.kind() {
|
||||
ty::Never | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => {
|
||||
MetadataCreationResult::new(basic_type_metadata(cx, t), false)
|
||||
}
|
||||
@ -876,7 +876,7 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
|
||||
// .natvis visualizers (and perhaps other existing native debuggers?)
|
||||
let msvc_like_names = cx.tcx.sess.target.target.options.is_like_msvc;
|
||||
|
||||
let (name, encoding) = match t.kind {
|
||||
let (name, encoding) = match t.kind() {
|
||||
ty::Never => ("!", DW_ATE_unsigned),
|
||||
ty::Tuple(ref elements) if elements.is_empty() => ("()", DW_ATE_unsigned),
|
||||
ty::Bool => ("bool", DW_ATE_boolean),
|
||||
@ -904,7 +904,7 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
|
||||
return ty_metadata;
|
||||
}
|
||||
|
||||
let typedef_name = match t.kind {
|
||||
let typedef_name = match t.kind() {
|
||||
ty::Int(int_ty) => int_ty.name_str(),
|
||||
ty::Uint(uint_ty) => uint_ty.name_str(),
|
||||
ty::Float(float_ty) => float_ty.name_str(),
|
||||
@ -1239,7 +1239,7 @@ fn prepare_struct_metadata(
|
||||
) -> RecursiveTypeDescription<'ll, 'tcx> {
|
||||
let struct_name = compute_debuginfo_type_name(cx.tcx, struct_type, false);
|
||||
|
||||
let (struct_def_id, variant) = match struct_type.kind {
|
||||
let (struct_def_id, variant) = match struct_type.kind() {
|
||||
ty::Adt(def, _) => (def.did, def.non_enum_variant()),
|
||||
_ => bug!("prepare_struct_metadata on a non-ADT"),
|
||||
};
|
||||
@ -1373,7 +1373,7 @@ fn prepare_union_metadata(
|
||||
) -> RecursiveTypeDescription<'ll, 'tcx> {
|
||||
let union_name = compute_debuginfo_type_name(cx.tcx, union_type, false);
|
||||
|
||||
let (union_def_id, variant) = match union_type.kind {
|
||||
let (union_def_id, variant) = match union_type.kind() {
|
||||
ty::Adt(def, _) => (def.did, def.non_enum_variant()),
|
||||
_ => bug!("prepare_union_metadata on a non-ADT"),
|
||||
};
|
||||
@ -1457,14 +1457,14 @@ struct EnumMemberDescriptionFactory<'ll, 'tcx> {
|
||||
|
||||
impl EnumMemberDescriptionFactory<'ll, 'tcx> {
|
||||
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>) -> Vec<MemberDescription<'ll>> {
|
||||
let generator_variant_info_data = match self.enum_type.kind {
|
||||
let generator_variant_info_data = match *self.enum_type.kind() {
|
||||
ty::Generator(def_id, ..) => {
|
||||
Some(generator_layout_and_saved_local_names(cx.tcx, def_id))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let variant_info_for = |index: VariantIdx| match self.enum_type.kind {
|
||||
let variant_info_for = |index: VariantIdx| match *self.enum_type.kind() {
|
||||
ty::Adt(adt, _) => VariantInfo::Adt(&adt.variants[index]),
|
||||
ty::Generator(def_id, _, _) => {
|
||||
let (generator_layout, generator_saved_local_names) =
|
||||
@ -1486,14 +1486,14 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
|
||||
} else {
|
||||
type_metadata(cx, self.enum_type, self.span)
|
||||
};
|
||||
let flags = match self.enum_type.kind {
|
||||
let flags = match self.enum_type.kind() {
|
||||
ty::Generator(..) => DIFlags::FlagArtificial,
|
||||
_ => DIFlags::FlagZero,
|
||||
};
|
||||
|
||||
match self.layout.variants {
|
||||
Variants::Single { index } => {
|
||||
if let ty::Adt(adt, _) = &self.enum_type.kind {
|
||||
if let ty::Adt(adt, _) = self.enum_type.kind() {
|
||||
if adt.variants.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
@ -1942,7 +1942,7 @@ fn prepare_enum_metadata(
|
||||
let tcx = cx.tcx;
|
||||
let enum_name = compute_debuginfo_type_name(tcx, enum_type, false);
|
||||
// FIXME(tmandry): This doesn't seem to have any effect.
|
||||
let enum_flags = match enum_type.kind {
|
||||
let enum_flags = match enum_type.kind() {
|
||||
ty::Generator(..) => DIFlags::FlagArtificial,
|
||||
_ => DIFlags::FlagZero,
|
||||
};
|
||||
@ -1957,13 +1957,13 @@ fn prepare_enum_metadata(
|
||||
let file_metadata = unknown_file_metadata(cx);
|
||||
|
||||
let discriminant_type_metadata = |discr: Primitive| {
|
||||
let enumerators_metadata: Vec<_> = match enum_type.kind {
|
||||
let enumerators_metadata: Vec<_> = match enum_type.kind() {
|
||||
ty::Adt(def, _) => def
|
||||
.discriminants(tcx)
|
||||
.zip(&def.variants)
|
||||
.map(|((_, discr), v)| {
|
||||
let name = v.ident.as_str();
|
||||
let is_unsigned = match discr.ty.kind {
|
||||
let is_unsigned = match discr.ty.kind() {
|
||||
ty::Int(_) => false,
|
||||
ty::Uint(_) => true,
|
||||
_ => bug!("non integer discriminant"),
|
||||
@ -2012,7 +2012,7 @@ fn prepare_enum_metadata(
|
||||
type_metadata(cx, discr.to_ty(tcx), rustc_span::DUMMY_SP);
|
||||
|
||||
let item_name;
|
||||
let discriminant_name = match enum_type.kind {
|
||||
let discriminant_name = match enum_type.kind() {
|
||||
ty::Adt(..) => {
|
||||
item_name = tcx.item_name(enum_def_id).as_str();
|
||||
&*item_name
|
||||
@ -2105,7 +2105,7 @@ fn prepare_enum_metadata(
|
||||
);
|
||||
}
|
||||
|
||||
let discriminator_name = match &enum_type.kind {
|
||||
let discriminator_name = match enum_type.kind() {
|
||||
ty::Generator(..) => "__state",
|
||||
_ => "",
|
||||
};
|
||||
@ -2328,7 +2328,7 @@ fn set_members_of_composite_type(
|
||||
|
||||
/// Computes the type parameters for a type, if any, for the given metadata.
|
||||
fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> Option<&'ll DIArray> {
|
||||
if let ty::Adt(def, substs) = ty.kind {
|
||||
if let ty::Adt(def, substs) = *ty.kind() {
|
||||
if substs.types().next().is_some() {
|
||||
let generics = cx.tcx.generics_of(def.did);
|
||||
let names = get_parameter_names(cx, generics);
|
||||
|
@ -361,9 +361,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||
// already inaccurate due to ABI adjustments (see #42800).
|
||||
signature.extend(fn_abi.args.iter().map(|arg| {
|
||||
let t = arg.layout.ty;
|
||||
let t = match t.kind {
|
||||
let t = match t.kind() {
|
||||
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)
|
||||
}
|
||||
@ -467,7 +467,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||
|
||||
// Only "class" methods are generally understood by LLVM,
|
||||
// so avoid methods on other types (e.g., `<*mut T>::null`).
|
||||
match impl_self_ty.kind {
|
||||
match impl_self_ty.kind() {
|
||||
ty::Adt(def, ..) if !def.is_box() => {
|
||||
// Again, only create type information if full debuginfo is enabled
|
||||
if cx.sess().opts.debuginfo == DebugInfo::Full
|
||||
|
@ -90,7 +90,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
|
||||
let tcx = self.tcx;
|
||||
let callee_ty = instance.ty(tcx, ty::ParamEnv::reveal_all());
|
||||
|
||||
let (def_id, substs) = match callee_ty.kind {
|
||||
let (def_id, substs) = match *callee_ty.kind() {
|
||||
ty::FnDef(def_id, substs) => (def_id, substs),
|
||||
_ => bug!("expected fn item type, found {}", callee_ty),
|
||||
};
|
||||
@ -1271,7 +1271,7 @@ fn generic_simd_intrinsic(
|
||||
|
||||
if name == sym::simd_select_bitmask {
|
||||
let in_ty = arg_tys[0];
|
||||
let m_len = match in_ty.kind {
|
||||
let m_len = match in_ty.kind() {
|
||||
// Note that this `.unwrap()` crashes for isize/usize, that's sort
|
||||
// of intentional as there's not currently a use case for that.
|
||||
ty::Int(i) => i.bit_width().unwrap(),
|
||||
@ -1436,7 +1436,7 @@ fn generic_simd_intrinsic(
|
||||
m_len,
|
||||
v_len
|
||||
);
|
||||
match m_elem_ty.kind {
|
||||
match m_elem_ty.kind() {
|
||||
ty::Int(_) => {}
|
||||
_ => return_error!("mask element type is `{}`, expected `i_`", m_elem_ty),
|
||||
}
|
||||
@ -1455,13 +1455,13 @@ fn generic_simd_intrinsic(
|
||||
// If the vector has less than 8 lanes, an u8 is returned with zeroed
|
||||
// trailing bits.
|
||||
let expected_int_bits = in_len.max(8);
|
||||
match ret_ty.kind {
|
||||
match ret_ty.kind() {
|
||||
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => (),
|
||||
_ => return_error!("bitmask `{}`, expected `u{}`", ret_ty, expected_int_bits),
|
||||
}
|
||||
|
||||
// Integer vector <i{in_bitwidth} x in_len>:
|
||||
let (i_xn, in_elem_bitwidth) = match in_elem.kind {
|
||||
let (i_xn, in_elem_bitwidth) = match in_elem.kind() {
|
||||
ty::Int(i) => {
|
||||
(args[0].immediate(), i.bit_width().unwrap_or(bx.data_layout().pointer_size.bits()))
|
||||
}
|
||||
@ -1518,7 +1518,7 @@ fn generic_simd_intrinsic(
|
||||
}
|
||||
}
|
||||
}
|
||||
let ety = match in_elem.kind {
|
||||
let ety = match in_elem.kind() {
|
||||
ty::Float(f) if f.bit_width() == 32 => {
|
||||
if in_len < 2 || in_len > 16 {
|
||||
return_error!(
|
||||
@ -1612,7 +1612,7 @@ fn generic_simd_intrinsic(
|
||||
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Intrinsics.h#L81
|
||||
fn llvm_vector_str(elem_ty: Ty<'_>, vec_len: u64, no_pointers: usize) -> String {
|
||||
let p0s: String = "p0".repeat(no_pointers);
|
||||
match elem_ty.kind {
|
||||
match *elem_ty.kind() {
|
||||
ty::Int(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
|
||||
ty::Uint(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
|
||||
ty::Float(v) => format!("v{}{}f{}", vec_len, p0s, v.bit_width()),
|
||||
@ -1627,7 +1627,7 @@ fn generic_simd_intrinsic(
|
||||
mut no_pointers: usize,
|
||||
) -> &'ll Type {
|
||||
// FIXME: use cx.layout_of(ty).llvm_type() ?
|
||||
let mut elem_ty = match elem_ty.kind {
|
||||
let mut elem_ty = match *elem_ty.kind() {
|
||||
ty::Int(v) => cx.type_int_from_ty(v),
|
||||
ty::Uint(v) => cx.type_uint_from_ty(v),
|
||||
ty::Float(v) => cx.type_float_from_ty(v),
|
||||
@ -1680,7 +1680,7 @@ fn generic_simd_intrinsic(
|
||||
|
||||
// This counts how many pointers
|
||||
fn ptr_count(t: Ty<'_>) -> usize {
|
||||
match t.kind {
|
||||
match t.kind() {
|
||||
ty::RawPtr(p) => 1 + ptr_count(p.ty),
|
||||
_ => 0,
|
||||
}
|
||||
@ -1688,7 +1688,7 @@ fn generic_simd_intrinsic(
|
||||
|
||||
// Non-ptr type
|
||||
fn non_ptr(t: Ty<'_>) -> Ty<'_> {
|
||||
match t.kind {
|
||||
match t.kind() {
|
||||
ty::RawPtr(p) => non_ptr(p.ty),
|
||||
_ => t,
|
||||
}
|
||||
@ -1696,7 +1696,7 @@ fn generic_simd_intrinsic(
|
||||
|
||||
// The second argument must be a simd vector with an element type that's a pointer
|
||||
// to the element type of the first argument
|
||||
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind {
|
||||
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind() {
|
||||
ty::RawPtr(p) if p.ty == in_elem => {
|
||||
(ptr_count(arg_tys[1].simd_type(tcx)), non_ptr(arg_tys[1].simd_type(tcx)))
|
||||
}
|
||||
@ -1721,7 +1721,7 @@ fn generic_simd_intrinsic(
|
||||
assert_eq!(underlying_ty, non_ptr(arg_tys[0].simd_type(tcx)));
|
||||
|
||||
// The element type of the third argument must be a signed integer type of any width:
|
||||
match arg_tys[2].simd_type(tcx).kind {
|
||||
match arg_tys[2].simd_type(tcx).kind() {
|
||||
ty::Int(_) => (),
|
||||
_ => {
|
||||
require!(
|
||||
@ -1803,7 +1803,7 @@ fn generic_simd_intrinsic(
|
||||
|
||||
// This counts how many pointers
|
||||
fn ptr_count(t: Ty<'_>) -> usize {
|
||||
match t.kind {
|
||||
match t.kind() {
|
||||
ty::RawPtr(p) => 1 + ptr_count(p.ty),
|
||||
_ => 0,
|
||||
}
|
||||
@ -1811,7 +1811,7 @@ fn generic_simd_intrinsic(
|
||||
|
||||
// Non-ptr type
|
||||
fn non_ptr(t: Ty<'_>) -> Ty<'_> {
|
||||
match t.kind {
|
||||
match t.kind() {
|
||||
ty::RawPtr(p) => non_ptr(p.ty),
|
||||
_ => t,
|
||||
}
|
||||
@ -1819,7 +1819,7 @@ fn generic_simd_intrinsic(
|
||||
|
||||
// The second argument must be a simd vector with an element type that's a pointer
|
||||
// to the element type of the first argument
|
||||
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind {
|
||||
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind() {
|
||||
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == hir::Mutability::Mut => {
|
||||
(ptr_count(arg_tys[1].simd_type(tcx)), non_ptr(arg_tys[1].simd_type(tcx)))
|
||||
}
|
||||
@ -1844,7 +1844,7 @@ fn generic_simd_intrinsic(
|
||||
assert_eq!(underlying_ty, non_ptr(arg_tys[0].simd_type(tcx)));
|
||||
|
||||
// The element type of the third argument must be a signed integer type of any width:
|
||||
match arg_tys[2].simd_type(tcx).kind {
|
||||
match arg_tys[2].simd_type(tcx).kind() {
|
||||
ty::Int(_) => (),
|
||||
_ => {
|
||||
require!(
|
||||
@ -1900,7 +1900,7 @@ fn generic_simd_intrinsic(
|
||||
in_ty,
|
||||
ret_ty
|
||||
);
|
||||
return match in_elem.kind {
|
||||
return match in_elem.kind() {
|
||||
ty::Int(_) | ty::Uint(_) => {
|
||||
let r = bx.$integer_reduce(args[0].immediate());
|
||||
if $ordered {
|
||||
@ -1972,7 +1972,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||
in_ty,
|
||||
ret_ty
|
||||
);
|
||||
return match in_elem.kind {
|
||||
return match in_elem.kind() {
|
||||
ty::Int(_i) => Ok(bx.$int_red(args[0].immediate(), true)),
|
||||
ty::Uint(_u) => Ok(bx.$int_red(args[0].immediate(), false)),
|
||||
ty::Float(_f) => Ok(bx.$float_red(args[0].immediate())),
|
||||
@ -2007,7 +2007,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||
);
|
||||
args[0].immediate()
|
||||
} else {
|
||||
match in_elem.kind {
|
||||
match in_elem.kind() {
|
||||
ty::Int(_) | ty::Uint(_) => {}
|
||||
_ => return_error!(
|
||||
"unsupported {} from `{}` with element `{}` to `{}`",
|
||||
@ -2023,7 +2023,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||
let i1xn = bx.type_vector(i1, in_len as u64);
|
||||
bx.trunc(args[0].immediate(), i1xn)
|
||||
};
|
||||
return match in_elem.kind {
|
||||
return match in_elem.kind() {
|
||||
ty::Int(_) | ty::Uint(_) => {
|
||||
let r = bx.$red(input);
|
||||
Ok(if !$boolean { r } else { bx.zext(r, bx.type_bool()) })
|
||||
@ -2071,7 +2071,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||
Unsupported,
|
||||
}
|
||||
|
||||
let (in_style, in_width) = match in_elem.kind {
|
||||
let (in_style, in_width) = match in_elem.kind() {
|
||||
// vectors of pointer-sized integers should've been
|
||||
// disallowed before here, so this unwrap is safe.
|
||||
ty::Int(i) => (Style::Int(true), i.bit_width().unwrap()),
|
||||
@ -2079,7 +2079,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||
ty::Float(f) => (Style::Float, f.bit_width()),
|
||||
_ => (Style::Unsupported, 0),
|
||||
};
|
||||
let (out_style, out_width) = match out_elem.kind {
|
||||
let (out_style, out_width) = match out_elem.kind() {
|
||||
ty::Int(i) => (Style::Int(true), i.bit_width().unwrap()),
|
||||
ty::Uint(u) => (Style::Int(false), u.bit_width().unwrap()),
|
||||
ty::Float(f) => (Style::Float, f.bit_width()),
|
||||
@ -2135,7 +2135,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||
macro_rules! arith {
|
||||
($($name: ident: $($($p: ident),* => $call: ident),*;)*) => {
|
||||
$(if name == sym::$name {
|
||||
match in_elem.kind {
|
||||
match in_elem.kind() {
|
||||
$($(ty::$p(_))|* => {
|
||||
return Ok(bx.$call(args[0].immediate(), args[1].immediate()))
|
||||
})*
|
||||
@ -2169,7 +2169,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||
let rhs = args[1].immediate();
|
||||
let is_add = name == sym::simd_saturating_add;
|
||||
let ptr_bits = bx.tcx().data_layout.pointer_size.bits() as _;
|
||||
let (signed, elem_width, elem_ty) = match in_elem.kind {
|
||||
let (signed, elem_width, elem_ty) = match *in_elem.kind() {
|
||||
ty::Int(i) => (true, i.bit_width().unwrap_or(ptr_bits), bx.cx.type_int_from_ty(i)),
|
||||
ty::Uint(i) => (false, i.bit_width().unwrap_or(ptr_bits), bx.cx.type_uint_from_ty(i)),
|
||||
_ => {
|
||||
@ -2204,7 +2204,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||
// FIXME: there’s multiple of this functions, investigate using some of the already existing
|
||||
// stuffs.
|
||||
fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, bool)> {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Int(t) => Some((
|
||||
match t {
|
||||
ast::IntTy::Isize => u64::from(cx.tcx.sess.target.ptr_width),
|
||||
@ -2234,7 +2234,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo
|
||||
// Returns the width of a float Ty
|
||||
// Returns None if the type is not a float
|
||||
fn float_type_width(ty: Ty<'_>) -> Option<u64> {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Float(t) => Some(t.bit_width()),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ fn uncached_llvm_type<'a, 'tcx>(
|
||||
Abi::Uninhabited | Abi::Aggregate { .. } => {}
|
||||
}
|
||||
|
||||
let name = match layout.ty.kind {
|
||||
let name = match layout.ty.kind() {
|
||||
// FIXME(eddyb) producing readable type names for trait objects can result
|
||||
// in problematically distinct types due to HRTB and subtyping (see #47638).
|
||||
// ty::Dynamic(..) |
|
||||
@ -60,14 +60,14 @@ fn uncached_llvm_type<'a, 'tcx>(
|
||||
{
|
||||
let mut name = with_no_trimmed_paths(|| layout.ty.to_string());
|
||||
if let (&ty::Adt(def, _), &Variants::Single { index }) =
|
||||
(&layout.ty.kind, &layout.variants)
|
||||
(layout.ty.kind(), &layout.variants)
|
||||
{
|
||||
if def.is_enum() && !def.variants.is_empty() {
|
||||
write!(&mut name, "::{}", def.variants[index].ident).unwrap();
|
||||
}
|
||||
}
|
||||
if let (&ty::Generator(_, _, _), &Variants::Single { index }) =
|
||||
(&layout.ty.kind, &layout.variants)
|
||||
(layout.ty.kind(), &layout.variants)
|
||||
{
|
||||
write!(&mut name, "::{}", ty::GeneratorSubsts::variant_name(index)).unwrap();
|
||||
}
|
||||
@ -238,7 +238,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
|
||||
if let Some(&llty) = cx.scalar_lltypes.borrow().get(&self.ty) {
|
||||
return llty;
|
||||
}
|
||||
let llty = match self.ty.kind {
|
||||
let llty = match *self.ty.kind() {
|
||||
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {
|
||||
cx.type_ptr_to(cx.layout_of(ty).llvm_type(cx))
|
||||
}
|
||||
@ -331,7 +331,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
|
||||
) -> &'a Type {
|
||||
// HACK(eddyb) special-case fat pointers until LLVM removes
|
||||
// pointee types, to avoid bitcasting every `OperandRef::deref`.
|
||||
match self.ty.kind {
|
||||
match self.ty.kind() {
|
||||
ty::Ref(..) | ty::RawPtr(_) => {
|
||||
return self.field(cx, index).llvm_type(cx);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ pub fn compare_simd_types<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
ret_ty: Bx::Type,
|
||||
op: hir::BinOpKind,
|
||||
) -> Bx::Value {
|
||||
let signed = match t.kind {
|
||||
let signed = match t.kind() {
|
||||
ty::Float(_) => {
|
||||
let cmp = bin_op_to_fcmp_predicate(op);
|
||||
let cmp = bx.fcmp(cmp, lhs, rhs);
|
||||
@ -153,7 +153,7 @@ pub fn unsized_info<'tcx, Cx: CodegenMethods<'tcx>>(
|
||||
) -> Cx::Value {
|
||||
let (source, target) =
|
||||
cx.tcx().struct_lockstep_tails_erasing_lifetimes(source, target, cx.param_env());
|
||||
match (&source.kind, &target.kind) {
|
||||
match (source.kind(), target.kind()) {
|
||||
(&ty::Array(_, len), &ty::Slice(_)) => {
|
||||
cx.const_usize(len.eval_usize(cx.tcx(), ty::ParamEnv::reveal_all()))
|
||||
}
|
||||
@ -182,7 +182,7 @@ pub fn unsize_thin_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
dst_ty: Ty<'tcx>,
|
||||
) -> (Bx::Value, Bx::Value) {
|
||||
debug!("unsize_thin_ptr: {:?} => {:?}", src_ty, dst_ty);
|
||||
match (&src_ty.kind, &dst_ty.kind) {
|
||||
match (src_ty.kind(), dst_ty.kind()) {
|
||||
(&ty::Ref(_, a, _), &ty::Ref(_, b, _) | &ty::RawPtr(ty::TypeAndMut { ty: b, .. }))
|
||||
| (&ty::RawPtr(ty::TypeAndMut { ty: a, .. }), &ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
|
||||
assert!(bx.cx().type_is_sized(a));
|
||||
@ -231,7 +231,7 @@ pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
) {
|
||||
let src_ty = src.layout.ty;
|
||||
let dst_ty = dst.layout.ty;
|
||||
match (&src_ty.kind, &dst_ty.kind) {
|
||||
match (src_ty.kind(), dst_ty.kind()) {
|
||||
(&ty::Ref(..), &ty::Ref(..) | &ty::RawPtr(..)) | (&ty::RawPtr(..), &ty::RawPtr(..)) => {
|
||||
let (base, info) = match bx.load_operand(src).val {
|
||||
OperandValue::Pair(base, info) => {
|
||||
|
@ -33,7 +33,7 @@ pub fn push_debuginfo_type_name<'tcx>(
|
||||
// .natvis visualizers (and perhaps other existing native debuggers?)
|
||||
let cpp_like_names = tcx.sess.target.target.options.is_like_msvc;
|
||||
|
||||
match t.kind {
|
||||
match *t.kind() {
|
||||
ty::Bool => output.push_str("bool"),
|
||||
ty::Char => output.push_str("char"),
|
||||
ty::Str => output.push_str("str"),
|
||||
|
@ -19,7 +19,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
let align = bx.const_usize(layout.align.abi.bytes());
|
||||
return (size, align);
|
||||
}
|
||||
match t.kind {
|
||||
match t.kind() {
|
||||
ty::Dynamic(..) => {
|
||||
// load size/align from vtable
|
||||
let vtable = info.unwrap();
|
||||
@ -64,7 +64,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
let size = bx.add(sized_size, unsized_size);
|
||||
|
||||
// Packed types ignore the alignment of their fields.
|
||||
if let ty::Adt(def, _) = t.kind {
|
||||
if let ty::Adt(def, _) = t.kind() {
|
||||
if def.repr.packed() {
|
||||
unsized_align = sized_align;
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
|
||||
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
|
||||
let check = match terminator.kind {
|
||||
mir::TerminatorKind::Call { func: mir::Operand::Constant(ref c), ref args, .. } => {
|
||||
match c.literal.ty.kind {
|
||||
match *c.literal.ty.kind() {
|
||||
ty::FnDef(did, _) => Some((did, args)),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
args1 = [place.llval];
|
||||
&args1[..]
|
||||
};
|
||||
let (drop_fn, fn_abi) = match ty.kind {
|
||||
let (drop_fn, fn_abi) = match ty.kind() {
|
||||
// FIXME(eddyb) perhaps move some of this logic into
|
||||
// `Instance::resolve_drop_in_place`?
|
||||
ty::Dynamic(..) => {
|
||||
@ -540,7 +540,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
// Create the callee. This is a fn ptr or zero-sized and hence a kind of scalar.
|
||||
let callee = self.codegen_operand(&mut bx, func);
|
||||
|
||||
let (instance, mut llfn) = match callee.layout.ty.kind {
|
||||
let (instance, mut llfn) = match *callee.layout.ty.kind() {
|
||||
ty::FnDef(def_id, substs) => (
|
||||
Some(
|
||||
ty::Instance::resolve(bx.tcx(), ty::ParamEnv::reveal_all(), def_id, substs)
|
||||
@ -887,7 +887,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
_ => span_bug!(span, "expected ByRef for promoted asm const"),
|
||||
};
|
||||
let value = scalar.assert_bits(size);
|
||||
let string = match ty.kind {
|
||||
let string = match ty.kind() {
|
||||
ty::Uint(_) => value.to_string(),
|
||||
ty::Int(int_ty) => {
|
||||
match int_ty.normalize(bx.tcx().sess.target.ptr_width) {
|
||||
@ -914,7 +914,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
}
|
||||
mir::InlineAsmOperand::SymFn { ref value } => {
|
||||
let literal = self.monomorphize(&value.literal);
|
||||
if let ty::FnDef(def_id, substs) = literal.ty.kind {
|
||||
if let ty::FnDef(def_id, substs) = *literal.ty.kind() {
|
||||
let instance = ty::Instance::resolve_for_fn_ptr(
|
||||
bx.tcx(),
|
||||
ty::ParamEnv::reveal_all(),
|
||||
|
@ -369,8 +369,8 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
// individual LLVM function arguments.
|
||||
|
||||
let arg_ty = fx.monomorphize(&arg_decl.ty);
|
||||
let tupled_arg_tys = match arg_ty.kind {
|
||||
ty::Tuple(ref tys) => tys,
|
||||
let tupled_arg_tys = match arg_ty.kind() {
|
||||
ty::Tuple(tys) => tys,
|
||||
_ => bug!("spread argument isn't a tuple?!"),
|
||||
};
|
||||
|
||||
|
@ -116,7 +116,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
|
||||
// * no metadata available - just log the case
|
||||
// * known alignment - sized types, `[T]`, `str` or a foreign type
|
||||
// * packed struct - there is no alignment padding
|
||||
match field.ty.kind {
|
||||
match field.ty.kind() {
|
||||
_ if self.llextra.is_none() => {
|
||||
debug!(
|
||||
"unsized field `{}`, of `{:?}` has no metadata for adjustment",
|
||||
|
@ -185,7 +185,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
|
||||
let val = match *kind {
|
||||
mir::CastKind::Pointer(PointerCast::ReifyFnPointer) => {
|
||||
match operand.layout.ty.kind {
|
||||
match *operand.layout.ty.kind() {
|
||||
ty::FnDef(def_id, substs) => {
|
||||
if bx.cx().tcx().has_attr(def_id, sym::rustc_args_required_const) {
|
||||
bug!("reifying a fn ptr that requires const arguments");
|
||||
@ -204,7 +204,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
}
|
||||
}
|
||||
mir::CastKind::Pointer(PointerCast::ClosureFnPointer(_)) => {
|
||||
match operand.layout.ty.kind {
|
||||
match *operand.layout.ty.kind() {
|
||||
ty::Closure(def_id, substs) => {
|
||||
let instance = Instance::resolve_closure(
|
||||
bx.cx().tcx(),
|
||||
@ -564,7 +564,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
// because codegen_place() panics if Local is operand.
|
||||
if let Some(index) = place.as_local() {
|
||||
if let LocalRef::Operand(Some(op)) = self.locals[index] {
|
||||
if let ty::Array(_, n) = op.layout.ty.kind {
|
||||
if let ty::Array(_, n) = op.layout.ty.kind() {
|
||||
let n = n.eval_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all());
|
||||
return bx.cx().const_usize(n);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
|
||||
}
|
||||
|
||||
let tail = self.tcx().struct_tail_erasing_lifetimes(ty, param_env);
|
||||
match tail.kind {
|
||||
match tail.kind() {
|
||||
ty::Foreign(..) => false,
|
||||
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
|
||||
_ => bug!("unexpected unsized tail: {:?}", tail),
|
||||
|
@ -340,7 +340,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
|
||||
}
|
||||
|
||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||
match t.kind {
|
||||
match *t.kind() {
|
||||
ty::Infer(ty::TyVar(vid)) => {
|
||||
debug!("canonical: type var found with vid {:?}", vid);
|
||||
match self.infcx.unwrap().probe_ty_var(vid) {
|
||||
|
@ -422,7 +422,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
match result_value.unpack() {
|
||||
GenericArgKind::Type(result_value) => {
|
||||
// e.g., here `result_value` might be `?0` in the example above...
|
||||
if let ty::Bound(debruijn, b) = result_value.kind {
|
||||
if let ty::Bound(debruijn, b) = *result_value.kind() {
|
||||
// ...in which case we would set `canonical_vars[0]` to `Some(?U)`.
|
||||
|
||||
// We only allow a `ty::INNERMOST` index in substitutions.
|
||||
|
@ -72,7 +72,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
|
||||
{
|
||||
let a_is_expected = relation.a_is_expected();
|
||||
|
||||
match (&a.kind, &b.kind) {
|
||||
match (a.kind(), b.kind()) {
|
||||
// Relate integral variables to other types
|
||||
(&ty::Infer(ty::IntVar(a_id)), &ty::Infer(ty::IntVar(b_id))) => {
|
||||
self.inner
|
||||
@ -541,7 +541,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
||||
// any other type variable related to `vid` via
|
||||
// subtyping. This is basically our "occurs check", preventing
|
||||
// us from creating infinitely sized types.
|
||||
match t.kind {
|
||||
match *t.kind() {
|
||||
ty::Infer(ty::TyVar(vid)) => {
|
||||
let vid = self.infcx.inner.borrow_mut().type_variables().root_var(vid);
|
||||
let sub_vid = self.infcx.inner.borrow_mut().type_variables().sub_root_var(vid);
|
||||
|
@ -77,7 +77,7 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
|
||||
|
||||
debug!("{}.tys: replacements ({:?}, {:?})", self.tag(), a, b);
|
||||
|
||||
match (&a.kind, &b.kind) {
|
||||
match (a.kind(), b.kind()) {
|
||||
(&ty::Infer(TyVar(a_id)), &ty::Infer(TyVar(b_id))) => {
|
||||
infcx.inner.borrow_mut().type_variables().equate(a_id, b_id);
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
// if they are both "path types", there's a chance of ambiguity
|
||||
// due to different versions of the same crate
|
||||
if let (&ty::Adt(exp_adt, _), &ty::Adt(found_adt, _)) =
|
||||
(&exp_found.expected.kind, &exp_found.found.kind)
|
||||
(exp_found.expected.kind(), exp_found.found.kind())
|
||||
{
|
||||
report_path_match(err, exp_adt.did, found_adt.did);
|
||||
}
|
||||
@ -796,7 +796,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
|
||||
return Some(());
|
||||
}
|
||||
if let &ty::Adt(def, _) = &ta.kind {
|
||||
if let &ty::Adt(def, _) = ta.kind() {
|
||||
let path_ = self.tcx.def_path_str(def.did);
|
||||
if path_ == other_path {
|
||||
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
|
||||
@ -977,11 +977,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
/// Compares two given types, eliding parts that are the same between them and highlighting
|
||||
/// relevant differences, and return two representation of those types for highlighted printing.
|
||||
fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> (DiagnosticStyledString, DiagnosticStyledString) {
|
||||
debug!("cmp(t1={}, t1.kind={:?}, t2={}, t2.kind={:?})", t1, t1.kind, t2, t2.kind);
|
||||
debug!("cmp(t1={}, t1.kind={:?}, t2={}, t2.kind={:?})", t1, t1.kind(), t2, t2.kind());
|
||||
|
||||
// helper functions
|
||||
fn equals<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
|
||||
match (&a.kind, &b.kind) {
|
||||
match (a.kind(), b.kind()) {
|
||||
(a, b) if *a == *b => true,
|
||||
(&ty::Int(_), &ty::Infer(ty::InferTy::IntVar(_)))
|
||||
| (
|
||||
@ -1014,7 +1014,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
// process starts here
|
||||
match (&t1.kind, &t2.kind) {
|
||||
match (t1.kind(), t2.kind()) {
|
||||
(&ty::Adt(def1, sub1), &ty::Adt(def2, sub2)) => {
|
||||
let sub_no_defaults_1 = self.strip_generic_default_params(def1.did, sub1);
|
||||
let sub_no_defaults_2 = self.strip_generic_default_params(def2.did, sub2);
|
||||
@ -1476,7 +1476,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
};
|
||||
match (&terr, expected == found) {
|
||||
(TypeError::Sorts(values), extra) => {
|
||||
let sort_string = |ty: Ty<'tcx>| match (extra, &ty.kind) {
|
||||
let sort_string = |ty: Ty<'tcx>| match (extra, ty.kind()) {
|
||||
(true, ty::Opaque(def_id, _)) => format!(
|
||||
" (opaque type at {})",
|
||||
self.tcx
|
||||
@ -1563,7 +1563,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
exp_span, exp_found.expected, exp_found.found
|
||||
);
|
||||
|
||||
if let ty::Opaque(def_id, _) = exp_found.expected.kind {
|
||||
if let ty::Opaque(def_id, _) = *exp_found.expected.kind() {
|
||||
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
|
||||
// Future::Output
|
||||
let item_def_id = self
|
||||
@ -1616,9 +1616,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
diag: &mut DiagnosticBuilder<'tcx>,
|
||||
) {
|
||||
if let (ty::Adt(exp_def, exp_substs), ty::Ref(_, found_ty, _)) =
|
||||
(&exp_found.expected.kind, &exp_found.found.kind)
|
||||
(exp_found.expected.kind(), exp_found.found.kind())
|
||||
{
|
||||
if let ty::Adt(found_def, found_substs) = found_ty.kind {
|
||||
if let ty::Adt(found_def, found_substs) = *found_ty.kind() {
|
||||
let path_str = format!("{:?}", exp_def);
|
||||
if exp_def == &found_def {
|
||||
let opt_msg = "you can convert from `&Option<T>` to `Option<&T>` using \
|
||||
@ -1637,9 +1637,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
{
|
||||
let mut show_suggestion = true;
|
||||
for (exp_ty, found_ty) in exp_substs.types().zip(found_substs.types()) {
|
||||
match exp_ty.kind {
|
||||
match *exp_ty.kind() {
|
||||
ty::Ref(_, exp_ty, _) => {
|
||||
match (&exp_ty.kind, &found_ty.kind) {
|
||||
match (exp_ty.kind(), found_ty.kind()) {
|
||||
(_, ty::Param(_))
|
||||
| (_, ty::Infer(_))
|
||||
| (ty::Param(_), _)
|
||||
@ -1989,7 +1989,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
);
|
||||
if let Some(infer::RelateParamBound(_, t)) = origin {
|
||||
let t = self.resolve_vars_if_possible(&t);
|
||||
match t.kind {
|
||||
match t.kind() {
|
||||
// We've got:
|
||||
// fn get_later<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
|
||||
// suggest:
|
||||
@ -2231,7 +2231,7 @@ impl TyCategory {
|
||||
}
|
||||
|
||||
pub fn from_ty(ty: Ty<'_>) -> Option<(Self, DefId)> {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Closure(def_id, _) => Some((Self::Closure, def_id)),
|
||||
ty::Opaque(def_id, _) => Some((Self::Opaque, def_id)),
|
||||
ty::Generator(def_id, ..) => Some((Self::Generator, def_id)),
|
||||
|
@ -53,7 +53,7 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
|
||||
inner == self.target
|
||||
|| match (inner.unpack(), self.target.unpack()) {
|
||||
(GenericArgKind::Type(inner_ty), GenericArgKind::Type(target_ty)) => {
|
||||
match (&inner_ty.kind, &target_ty.kind) {
|
||||
match (inner_ty.kind(), target_ty.kind()) {
|
||||
(
|
||||
&ty::Infer(ty::TyVar(a_vid)),
|
||||
&ty::Infer(ty::TyVar(b_vid)),
|
||||
@ -222,7 +222,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
ty: Ty<'tcx>,
|
||||
highlight: Option<ty::print::RegionHighlightMode>,
|
||||
) -> (String, Option<Span>, Cow<'static, str>, Option<String>, Option<&'static str>) {
|
||||
if let ty::Infer(ty::TyVar(ty_vid)) = ty.kind {
|
||||
if let ty::Infer(ty::TyVar(ty_vid)) = *ty.kind() {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let ty_vars = &inner.type_variables();
|
||||
let var_origin = ty_vars.var_origin(ty_vid);
|
||||
@ -288,7 +288,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
None
|
||||
};
|
||||
printer.name_resolver = Some(Box::new(&getter));
|
||||
let _ = if let ty::FnDef(..) = ty.kind {
|
||||
let _ = if let ty::FnDef(..) = ty.kind() {
|
||||
// We don't want the regular output for `fn`s because it includes its path in
|
||||
// invalid pseudo-syntax, we want the `fn`-pointer output instead.
|
||||
ty.fn_sig(self.tcx).print(printer)
|
||||
@ -336,7 +336,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
|
||||
let ty_msg = match (local_visitor.found_node_ty, local_visitor.found_exact_method_call) {
|
||||
(_, Some(_)) => String::new(),
|
||||
(Some(ty::TyS { kind: ty::Closure(_, substs), .. }), _) => {
|
||||
(Some(ty), _) if ty.is_closure() => {
|
||||
let substs =
|
||||
if let ty::Closure(_, substs) = *ty.kind() { substs } else { unreachable!() };
|
||||
let fn_sig = substs.as_closure().sig();
|
||||
let args = closure_args(&fn_sig);
|
||||
let ret = fn_sig.output().skip_binder().to_string();
|
||||
@ -370,7 +372,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
);
|
||||
|
||||
let suffix = match local_visitor.found_node_ty {
|
||||
Some(ty::TyS { kind: ty::Closure(_, substs), .. }) => {
|
||||
Some(ty) if ty.is_closure() => {
|
||||
let substs =
|
||||
if let ty::Closure(_, substs) = *ty.kind() { substs } else { unreachable!() };
|
||||
let fn_sig = substs.as_closure().sig();
|
||||
let ret = fn_sig.output().skip_binder().to_string();
|
||||
|
||||
@ -612,7 +616,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
let bound_output = sig.output();
|
||||
let output = bound_output.skip_binder();
|
||||
err.span_label(e.span, &format!("this method call resolves to `{}`", output));
|
||||
let kind = &output.kind;
|
||||
let kind = output.kind();
|
||||
if let ty::Projection(proj) = kind {
|
||||
if let Some(span) = self.tcx.hir().span_if_local(proj.item_def_id) {
|
||||
err.span_label(span, &format!("`{}` defined here", output));
|
||||
|
@ -465,7 +465,7 @@ struct TraitObjectVisitor(Vec<DefId>);
|
||||
|
||||
impl TypeVisitor<'_> for TraitObjectVisitor {
|
||||
fn visit_ty(&mut self, t: Ty<'_>) -> bool {
|
||||
match t.kind {
|
||||
match t.kind() {
|
||||
ty::Dynamic(preds, RegionKind::ReStatic) => {
|
||||
if let Some(def_id) = preds.principal_def_id() {
|
||||
self.0.push(def_id);
|
||||
|
@ -95,7 +95,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
decl: &hir::FnDecl<'_>,
|
||||
) -> Option<Span> {
|
||||
let ret_ty = self.tcx().type_of(scope_def_id);
|
||||
if let ty::FnDef(_, _) = ret_ty.kind {
|
||||
if let ty::FnDef(_, _) = ret_ty.kind() {
|
||||
let sig = ret_ty.fn_sig(self.tcx());
|
||||
let late_bound_regions =
|
||||
self.tcx().collect_referenced_late_bound_regions(&sig.output());
|
||||
|
@ -144,7 +144,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
|
||||
|
||||
let tcx = self.infcx.tcx;
|
||||
|
||||
match t.kind {
|
||||
match *t.kind() {
|
||||
ty::Infer(ty::TyVar(v)) => {
|
||||
let opt_ty = self.infcx.inner.borrow_mut().type_variables().probe(v).known();
|
||||
self.freshen_ty(opt_ty, ty::TyVar(v), ty::FreshTy)
|
||||
|
@ -182,7 +182,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for InferenceFudger<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Infer(ty::InferTy::TyVar(vid)) => {
|
||||
if self.type_vars.0.contains(&vid) {
|
||||
// This variable was created during the fudging.
|
||||
|
@ -58,7 +58,7 @@ where
|
||||
let infcx = this.infcx();
|
||||
let a = infcx.inner.borrow_mut().type_variables().replace_if_possible(a);
|
||||
let b = infcx.inner.borrow_mut().type_variables().replace_if_possible(b);
|
||||
match (&a.kind, &b.kind) {
|
||||
match (a.kind(), b.kind()) {
|
||||
// If one side is known to be a variable and one is not,
|
||||
// create a variable (`v`) to represent the LUB. Make sure to
|
||||
// relate `v` to the non-type-variable first (by passing it
|
||||
|
@ -680,7 +680,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
pub fn type_var_diverges(&'a self, ty: Ty<'_>) -> bool {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Infer(ty::TyVar(vid)) => self.inner.borrow_mut().type_variables().var_diverges(vid),
|
||||
_ => false,
|
||||
}
|
||||
@ -693,7 +693,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
pub fn type_is_unconstrained_numeric(&'a self, ty: Ty<'_>) -> UnconstrainedNumeric {
|
||||
use rustc_middle::ty::error::UnconstrainedNumeric::Neither;
|
||||
use rustc_middle::ty::error::UnconstrainedNumeric::{UnconstrainedFloat, UnconstrainedInt};
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Infer(ty::IntVar(vid)) => {
|
||||
if self.inner.borrow_mut().int_unification_table().probe_value(vid).is_some() {
|
||||
Neither
|
||||
@ -1557,7 +1557,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
/// not a type variable, just return it unmodified.
|
||||
// FIXME(eddyb) inline into `ShallowResolver::visit_ty`.
|
||||
fn shallow_resolve_ty(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
|
||||
match typ.kind {
|
||||
match *typ.kind() {
|
||||
ty::Infer(ty::TyVar(v)) => {
|
||||
// Not entirely obvious: if `typ` is a type variable,
|
||||
// it can be resolved to an int/float variable, which
|
||||
@ -1677,7 +1677,7 @@ impl TyOrConstInferVar<'tcx> {
|
||||
/// Tries to extract an inference variable from a type, returns `None`
|
||||
/// for types other than `ty::Infer(_)` (or `InferTy::Fresh*`).
|
||||
pub fn maybe_from_ty(ty: Ty<'tcx>) -> Option<Self> {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Infer(ty::TyVar(v)) => Some(TyOrConstInferVar::Ty(v)),
|
||||
ty::Infer(ty::IntVar(v)) => Some(TyOrConstInferVar::TyInt(v)),
|
||||
ty::Infer(ty::FloatVar(v)) => Some(TyOrConstInferVar::TyFloat(v)),
|
||||
|
@ -265,7 +265,7 @@ where
|
||||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc_span::DUMMY_SP;
|
||||
|
||||
match value_ty.kind {
|
||||
match *value_ty.kind() {
|
||||
ty::Projection(other_projection_ty) => {
|
||||
let var = self.infcx.next_ty_var(TypeVariableOrigin {
|
||||
kind: TypeVariableOriginKind::MiscVariable,
|
||||
@ -311,7 +311,7 @@ where
|
||||
// This only presently applies to chalk integration, as NLL
|
||||
// doesn't permit type variables to appear on both sides (and
|
||||
// doesn't use lazy norm).
|
||||
match value_ty.kind {
|
||||
match *value_ty.kind() {
|
||||
ty::Infer(ty::TyVar(value_vid)) => {
|
||||
// Two type variables: just equate them.
|
||||
self.infcx.inner.borrow_mut().type_variables().equate(vid, value_vid);
|
||||
@ -531,7 +531,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
match (&a.kind, &b.kind) {
|
||||
match (a.kind(), b.kind()) {
|
||||
(_, &ty::Infer(ty::TyVar(vid))) => {
|
||||
if D::forbid_inference_vars() {
|
||||
// Forbid inference variables in the RHS.
|
||||
@ -868,7 +868,7 @@ where
|
||||
|
||||
debug!("TypeGeneralizer::tys(a={:?})", a);
|
||||
|
||||
match a.kind {
|
||||
match *a.kind() {
|
||||
ty::Infer(ty::TyVar(_)) | ty::Infer(ty::IntVar(_)) | ty::Infer(ty::FloatVar(_))
|
||||
if D::forbid_inference_vars() =>
|
||||
{
|
||||
|
@ -383,7 +383,7 @@ where
|
||||
// #55756) in cases where you have e.g., `<T as Foo<'a>>::Item:
|
||||
// 'a` in the environment but `trait Foo<'b> { type Item: 'b
|
||||
// }` in the trait definition.
|
||||
approx_env_bounds.retain(|bound| match bound.0.kind {
|
||||
approx_env_bounds.retain(|bound| match *bound.0.kind() {
|
||||
ty::Projection(projection_ty) => self
|
||||
.verify_bound
|
||||
.projection_declared_bounds_from_trait(projection_ty)
|
||||
|
@ -38,7 +38,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
|
||||
}
|
||||
|
||||
fn type_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Param(p) => self.param_bound(p),
|
||||
ty::Projection(data) => self.projection_bound(data),
|
||||
ty::FnDef(_, substs) => {
|
||||
@ -118,7 +118,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
|
||||
let projection_ty = GenericKind::Projection(projection_ty).to_ty(self.tcx);
|
||||
let erased_projection_ty = self.tcx.erase_regions(&projection_ty);
|
||||
self.declared_generic_bounds_from_env_with_compare_fn(|ty| {
|
||||
if let ty::Projection(..) = ty.kind {
|
||||
if let ty::Projection(..) = ty.kind() {
|
||||
let erased_ty = self.tcx.erase_regions(&ty);
|
||||
erased_ty == erased_projection_ty
|
||||
} else {
|
||||
|
@ -124,7 +124,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
|
||||
let t = self.infcx.shallow_resolve(t);
|
||||
if t.has_infer_types() {
|
||||
if let ty::Infer(infer_ty) = t.kind {
|
||||
if let ty::Infer(infer_ty) = *t.kind() {
|
||||
// Since we called `shallow_resolve` above, this must
|
||||
// be an (as yet...) unresolved inference variable.
|
||||
let ty_var_span = if let ty::TyVar(ty_vid) = infer_ty {
|
||||
@ -191,7 +191,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
|
||||
t // micro-optimize -- if there is nothing in this type that this fold affects...
|
||||
} else {
|
||||
let t = self.infcx.shallow_resolve(t);
|
||||
match t.kind {
|
||||
match *t.kind() {
|
||||
ty::Infer(ty::TyVar(vid)) => {
|
||||
self.err = Some(FixupError::UnresolvedTy(vid));
|
||||
self.tcx().ty_error()
|
||||
|
@ -83,7 +83,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
|
||||
let infcx = self.fields.infcx;
|
||||
let a = infcx.inner.borrow_mut().type_variables().replace_if_possible(a);
|
||||
let b = infcx.inner.borrow_mut().type_variables().replace_if_possible(b);
|
||||
match (&a.kind, &b.kind) {
|
||||
match (a.kind(), b.kind()) {
|
||||
(&ty::Infer(TyVar(a_vid)), &ty::Infer(TyVar(b_vid))) => {
|
||||
// Shouldn't have any LBR here, so we can safely put
|
||||
// this under a binder below without fear of accidental
|
||||
|
@ -306,7 +306,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
|
||||
/// instantiated, then return the with which it was
|
||||
/// instantiated. Otherwise, returns `t`.
|
||||
pub fn replace_if_possible(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||
match t.kind {
|
||||
match *t.kind() {
|
||||
ty::Infer(ty::TyVar(v)) => match self.probe(v) {
|
||||
TypeVariableValue::Unknown { .. } => t,
|
||||
TypeVariableValue::Known { value } => value,
|
||||
|
@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
|
||||
}
|
||||
|
||||
// Make sure we found an array after peeling the boxes.
|
||||
if !matches!(recv_ty.kind, ty::Array(..)) {
|
||||
if !matches!(recv_ty.kind(), ty::Array(..)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -66,9 +66,9 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
|
||||
}
|
||||
|
||||
// Emit lint diagnostic.
|
||||
let target = match cx.typeck_results().expr_ty_adjusted(receiver_arg).kind {
|
||||
ty::Ref(_, ty::TyS { kind: ty::Array(..), .. }, _) => "[T; N]",
|
||||
ty::Ref(_, ty::TyS { kind: ty::Slice(..), .. }, _) => "[T]",
|
||||
let target = match *cx.typeck_results().expr_ty_adjusted(receiver_arg).kind() {
|
||||
ty::Ref(_, inner_ty, _) if inner_ty.is_array() => "[T; N]",
|
||||
ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), ty::Slice(..)) => "[T]",
|
||||
|
||||
// We know the original first argument type is an array type,
|
||||
// we know that the first adjustment was an autoref coercion
|
||||
|
@ -893,7 +893,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
|
||||
use rustc_target::spec::abi::Abi::RustIntrinsic;
|
||||
if let Some((&ty::Ref(_, _, from_mt), &ty::Ref(_, _, to_mt))) =
|
||||
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (&ty1.kind, &ty2.kind))
|
||||
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind()))
|
||||
{
|
||||
if to_mt == hir::Mutability::Mut && from_mt == hir::Mutability::Not {
|
||||
let msg = "mutating transmuted &mut T from &T may cause undefined behavior, \
|
||||
@ -1940,13 +1940,13 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
|
||||
init: InitKind,
|
||||
) -> Option<InitError> {
|
||||
use rustc_middle::ty::TyKind::*;
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
// Primitive types that don't like 0 as a value.
|
||||
Ref(..) => Some(("references must be non-null".to_string(), None)),
|
||||
Adt(..) if ty.is_box() => Some(("`Box` must be non-null".to_string(), None)),
|
||||
FnPtr(..) => Some(("function pointers must be non-null".to_string(), None)),
|
||||
Never => Some(("the `!` type has no valid value".to_string(), None)),
|
||||
RawPtr(tm) if matches!(tm.ty.kind, Dynamic(..)) =>
|
||||
RawPtr(tm) if matches!(tm.ty.kind(), Dynamic(..)) =>
|
||||
// raw ptr to dyn Trait
|
||||
{
|
||||
Some(("the vtable of a wide raw pointer must be non-null".to_string(), None))
|
||||
@ -2173,7 +2173,7 @@ impl ClashingExternDeclarations {
|
||||
let non_transparent_ty = |ty: Ty<'tcx>| -> Ty<'tcx> {
|
||||
let mut ty = ty;
|
||||
loop {
|
||||
if let ty::Adt(def, substs) = ty.kind {
|
||||
if let ty::Adt(def, substs) = *ty.kind() {
|
||||
let is_transparent = def.subst(tcx, substs).repr.transparent();
|
||||
let is_non_null = crate::types::nonnull_optimization_guaranteed(tcx, &def);
|
||||
debug!(
|
||||
@ -2212,8 +2212,8 @@ impl ClashingExternDeclarations {
|
||||
} else {
|
||||
// Do a full, depth-first comparison between the two.
|
||||
use rustc_middle::ty::TyKind::*;
|
||||
let a_kind = &a.kind;
|
||||
let b_kind = &b.kind;
|
||||
let a_kind = a.kind();
|
||||
let b_kind = b.kind();
|
||||
|
||||
let compare_layouts = |a, b| -> Result<bool, LayoutError<'tcx>> {
|
||||
debug!("compare_layouts({:?}, {:?})", a, b);
|
||||
@ -2335,7 +2335,7 @@ impl ClashingExternDeclarations {
|
||||
if is_primitive_or_pointer(other_kind) =>
|
||||
{
|
||||
let (primitive, adt) =
|
||||
if is_primitive_or_pointer(&a.kind) { (a, b) } else { (b, a) };
|
||||
if is_primitive_or_pointer(a.kind()) { (a, b) } else { (b, a) };
|
||||
if let Some(ty) = crate::types::repr_nullable_ptr(cx, adt, ckind) {
|
||||
ty == primitive
|
||||
} else {
|
||||
|
@ -790,7 +790,7 @@ impl<'tcx> LateContext<'tcx> {
|
||||
trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self::Path, Self::Error> {
|
||||
if trait_ref.is_none() {
|
||||
if let ty::Adt(def, substs) = self_ty.kind {
|
||||
if let ty::Adt(def, substs) = self_ty.kind() {
|
||||
return self.print_def_path(def.did, substs);
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<&'static
|
||||
}
|
||||
}
|
||||
}
|
||||
match t.kind {
|
||||
match t.kind() {
|
||||
ty::Int(i) => find_fit!(i, val, negative,
|
||||
I8 => [U8] => [I16, I32, I64, I128],
|
||||
I16 => [U16] => [I32, I64, I128],
|
||||
@ -303,7 +303,7 @@ fn lint_uint_literal<'tcx>(
|
||||
if let Node::Expr(par_e) = cx.tcx.hir().get(parent_id) {
|
||||
match par_e.kind {
|
||||
hir::ExprKind::Cast(..) => {
|
||||
if let ty::Char = cx.typeck_results().expr_ty(par_e).kind {
|
||||
if let ty::Char = cx.typeck_results().expr_ty(par_e).kind() {
|
||||
cx.struct_span_lint(OVERFLOWING_LITERALS, par_e.span, |lint| {
|
||||
lint.build("only `u8` can be cast into `char`")
|
||||
.span_suggestion(
|
||||
@ -354,7 +354,7 @@ fn lint_literal<'tcx>(
|
||||
e: &'tcx hir::Expr<'tcx>,
|
||||
lit: &hir::Lit,
|
||||
) {
|
||||
match cx.typeck_results().node_type(e.hir_id).kind {
|
||||
match *cx.typeck_results().node_type(e.hir_id).kind() {
|
||||
ty::Int(t) => {
|
||||
match lit.node {
|
||||
ast::LitKind::Int(v, ast::LitIntType::Signed(_) | ast::LitIntType::Unsuffixed) => {
|
||||
@ -450,7 +450,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
|
||||
// Normalize the binop so that the literal is always on the RHS in
|
||||
// the comparison
|
||||
let norm_binop = if swap { rev_binop(binop) } else { binop };
|
||||
match cx.typeck_results().node_type(expr.hir_id).kind {
|
||||
match *cx.typeck_results().node_type(expr.hir_id).kind() {
|
||||
ty::Int(int_ty) => {
|
||||
let (min, max) = int_ty_range(int_ty);
|
||||
let lit_val: i128 = match lit.kind {
|
||||
@ -536,7 +536,7 @@ crate fn nonnull_optimization_guaranteed<'tcx>(tcx: TyCtxt<'tcx>, def: &ty::AdtD
|
||||
/// Is type known to be non-null?
|
||||
crate fn ty_is_known_nonnull<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, mode: CItemKind) -> bool {
|
||||
let tcx = cx.tcx;
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::FnPtr(_) => true,
|
||||
ty::Ref(..) => true,
|
||||
ty::Adt(def, _) if def.is_box() && matches!(mode, CItemKind::Definition) => true,
|
||||
@ -565,7 +565,7 @@ crate fn ty_is_known_nonnull<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, mode: C
|
||||
/// If the type passed in was not scalar, returns None.
|
||||
fn get_nullable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||
let tcx = cx.tcx;
|
||||
Some(match ty.kind {
|
||||
Some(match *ty.kind() {
|
||||
ty::Adt(field_def, field_substs) => {
|
||||
let inner_field_ty = {
|
||||
let first_non_zst_ty =
|
||||
@ -617,7 +617,7 @@ crate fn repr_nullable_ptr<'tcx>(
|
||||
ckind: CItemKind,
|
||||
) -> Option<Ty<'tcx>> {
|
||||
debug!("is_repr_nullable_ptr(cx, ty = {:?})", ty);
|
||||
if let ty::Adt(ty_def, substs) = ty.kind {
|
||||
if let ty::Adt(ty_def, substs) = ty.kind() {
|
||||
if ty_def.variants.len() != 2 {
|
||||
return None;
|
||||
}
|
||||
@ -667,7 +667,7 @@ crate fn repr_nullable_ptr<'tcx>(
|
||||
impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
/// Check if the type is array and emit an unsafe type lint.
|
||||
fn check_for_array_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
|
||||
if let ty::Array(..) = ty.kind {
|
||||
if let ty::Array(..) = ty.kind() {
|
||||
self.emit_ffi_unsafe_type_lint(
|
||||
ty,
|
||||
sp,
|
||||
@ -755,7 +755,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
return FfiSafe;
|
||||
}
|
||||
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Adt(def, _) if def.is_box() && matches!(self.mode, CItemKind::Definition) => {
|
||||
FfiSafe
|
||||
}
|
||||
@ -994,7 +994,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
diag.help(help);
|
||||
}
|
||||
diag.note(note);
|
||||
if let ty::Adt(def, _) = ty.kind {
|
||||
if let ty::Adt(def, _) = ty.kind() {
|
||||
if let Some(sp) = self.cx.tcx.hir().span_if_local(def.did) {
|
||||
diag.span_note(sp, "the type is defined here");
|
||||
}
|
||||
@ -1011,7 +1011,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
|
||||
impl<'a, 'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'a, 'tcx> {
|
||||
fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Opaque(..) => {
|
||||
self.ty = Some(ty);
|
||||
true
|
||||
|
@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
||||
|
||||
let plural_suffix = pluralize!(plural_len);
|
||||
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Adt(..) if ty.is_box() => {
|
||||
let boxed_ty = ty.boxed_ty();
|
||||
let descr_pre = &format!("{}boxed ", descr_pre);
|
||||
|
@ -1418,7 +1418,7 @@ impl EncodeContext<'a, 'tcx> {
|
||||
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
let ty = self.tcx.typeck(def_id).node_type(hir_id);
|
||||
|
||||
record!(self.tables.kind[def_id.to_def_id()] <- match ty.kind {
|
||||
record!(self.tables.kind[def_id.to_def_id()] <- match ty.kind() {
|
||||
ty::Generator(..) => {
|
||||
let data = self.tcx.generator_kind(def_id).unwrap();
|
||||
EntryKind::Generator(data)
|
||||
@ -1432,7 +1432,7 @@ impl EncodeContext<'a, 'tcx> {
|
||||
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
|
||||
record!(self.tables.attributes[def_id.to_def_id()] <- &self.tcx.get_attrs(def_id.to_def_id())[..]);
|
||||
self.encode_item_type(def_id.to_def_id());
|
||||
if let ty::Closure(def_id, substs) = ty.kind {
|
||||
if let ty::Closure(def_id, substs) = *ty.kind() {
|
||||
record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig());
|
||||
}
|
||||
self.encode_generics(def_id.to_def_id());
|
||||
|
@ -2482,7 +2482,7 @@ impl<'tcx> Debug for Constant<'tcx> {
|
||||
|
||||
impl<'tcx> Display for Constant<'tcx> {
|
||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
|
||||
match self.literal.ty.kind {
|
||||
match self.literal.ty.kind() {
|
||||
ty::FnDef(..) => {}
|
||||
_ => write!(fmt, "const ")?,
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ impl<'tcx> PlaceTy<'tcx> {
|
||||
///
|
||||
/// Note that the resulting type has not been normalized.
|
||||
pub fn field_ty(self, tcx: TyCtxt<'tcx>, f: &Field) -> Ty<'tcx> {
|
||||
let answer = match self.ty.kind {
|
||||
let answer = match self.ty.kind() {
|
||||
ty::Adt(adt_def, substs) => {
|
||||
let variant_def = match self.variant_index {
|
||||
None => adt_def.non_enum_variant(),
|
||||
@ -90,7 +90,7 @@ impl<'tcx> PlaceTy<'tcx> {
|
||||
PlaceTy::from_ty(self.ty.builtin_index().unwrap())
|
||||
}
|
||||
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::Array(inner, _) if !from_end => tcx.mk_array(inner, (to - from) as u64),
|
||||
ty::Array(inner, size) if from_end => {
|
||||
|
@ -202,7 +202,7 @@ impl<'tcx> FromIterator<DtorckConstraint<'tcx>> for DtorckConstraint<'tcx> {
|
||||
/// Note also that `needs_drop` requires a "global" type (i.e., one
|
||||
/// with erased regions), but this function does not.
|
||||
pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
// None of these types have a destructor and hence they do not
|
||||
// require anything in particular to outlive the dtor's
|
||||
// execution.
|
||||
|
@ -67,7 +67,7 @@ impl TypeRelation<'tcx> for Match<'tcx> {
|
||||
return Ok(a);
|
||||
}
|
||||
|
||||
match (&a.kind, &b.kind) {
|
||||
match (a.kind(), b.kind()) {
|
||||
(
|
||||
_,
|
||||
&ty::Infer(ty::FreshTy(_))
|
||||
|
@ -50,7 +50,7 @@ impl<'tcx> CastTy<'tcx> {
|
||||
/// Returns `Some` for integral/pointer casts.
|
||||
/// casts like unsizing casts will return `None`
|
||||
pub fn from_ty(t: Ty<'tcx>) -> Option<CastTy<'tcx>> {
|
||||
match t.kind {
|
||||
match *t.kind() {
|
||||
ty::Bool => Some(CastTy::Int(IntTy::Bool)),
|
||||
ty::Char => Some(CastTy::Int(IntTy::Char)),
|
||||
ty::Int(_) => Some(CastTy::Int(IntTy::I)),
|
||||
|
@ -36,8 +36,10 @@ pub trait EncodableWithShorthand<'tcx, E: TyEncoder<'tcx>>: Copy + Eq + Hash {
|
||||
#[allow(rustc::usage_of_ty_tykind)]
|
||||
impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> {
|
||||
type Variant = ty::TyKind<'tcx>;
|
||||
|
||||
#[inline]
|
||||
fn variant(&self) -> &Self::Variant {
|
||||
&self.kind
|
||||
self.kind()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -759,10 +759,10 @@ impl CanonicalUserType<'tcx> {
|
||||
|
||||
user_substs.substs.iter().zip(BoundVar::new(0)..).all(|(kind, cvar)| {
|
||||
match kind.unpack() {
|
||||
GenericArgKind::Type(ty) => match ty.kind {
|
||||
GenericArgKind::Type(ty) => match ty.kind() {
|
||||
ty::Bound(debruijn, b) => {
|
||||
// We only allow a `ty::INNERMOST` index in substitutions.
|
||||
assert_eq!(debruijn, ty::INNERMOST);
|
||||
assert_eq!(*debruijn, ty::INNERMOST);
|
||||
cvar == b.var
|
||||
}
|
||||
_ => false,
|
||||
@ -1498,7 +1498,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
|
||||
let ret_ty = self.type_of(scope_def_id);
|
||||
match ret_ty.kind {
|
||||
match ret_ty.kind() {
|
||||
ty::FnDef(_, _) => {
|
||||
let sig = ret_ty.fn_sig(*self);
|
||||
let output = self.erase_late_bound_regions(&sig.output());
|
||||
@ -1822,7 +1822,7 @@ macro_rules! sty_debug_print {
|
||||
let shards = tcx.interners.type_.lock_shards();
|
||||
let types = shards.iter().flat_map(|shard| shard.keys());
|
||||
for &Interned(t) in types {
|
||||
let variant = match t.kind {
|
||||
let variant = match t.kind() {
|
||||
ty::Bool | ty::Char | ty::Int(..) | ty::Uint(..) |
|
||||
ty::Float(..) | ty::Str | ty::Never => continue,
|
||||
ty::Error(_) => /* unimportant */ continue,
|
||||
@ -1931,7 +1931,7 @@ impl<'tcx, T: 'tcx + ?Sized> IntoPointer for Interned<'tcx, T> {
|
||||
// N.B., an `Interned<Ty>` compares and hashes as a `TyKind`.
|
||||
impl<'tcx> PartialEq for Interned<'tcx, TyS<'tcx>> {
|
||||
fn eq(&self, other: &Interned<'tcx, TyS<'tcx>>) -> bool {
|
||||
self.0.kind == other.0.kind
|
||||
self.0.kind() == other.0.kind()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1939,14 +1939,14 @@ impl<'tcx> Eq for Interned<'tcx, TyS<'tcx>> {}
|
||||
|
||||
impl<'tcx> Hash for Interned<'tcx, TyS<'tcx>> {
|
||||
fn hash<H: Hasher>(&self, s: &mut H) {
|
||||
self.0.kind.hash(s)
|
||||
self.0.kind().hash(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(rustc::usage_of_ty_tykind)]
|
||||
impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
|
||||
fn borrow<'a>(&'a self) -> &'a TyKind<'tcx> {
|
||||
&self.0.kind
|
||||
&self.0.kind()
|
||||
}
|
||||
}
|
||||
// N.B., an `Interned<PredicateInner>` compares and hashes as a `PredicateKind`.
|
||||
@ -2086,7 +2086,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
unsafety: hir::Unsafety,
|
||||
) -> PolyFnSig<'tcx> {
|
||||
sig.map_bound(|s| {
|
||||
let params_iter = match s.inputs()[0].kind {
|
||||
let params_iter = match s.inputs()[0].kind() {
|
||||
ty::Tuple(params) => params.into_iter().map(|k| k.expect_ty()),
|
||||
_ => bug!(),
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ use rustc_hir::{QPath, TyKind, WhereBoundPredicate, WherePredicate};
|
||||
impl<'tcx> TyS<'tcx> {
|
||||
/// Similar to `TyS::is_primitive`, but also considers inferred numeric values to be primitive.
|
||||
pub fn is_primitive_ty(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Bool
|
||||
| Char
|
||||
| Str
|
||||
@ -31,7 +31,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
/// Whether the type is succinctly representable as a type instead of just referred to with a
|
||||
/// description in error messages. This is used in the main error message.
|
||||
pub fn is_simple_ty(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Bool
|
||||
| Char
|
||||
| Str
|
||||
@ -55,7 +55,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
/// `is_simple_ty` includes, it also accepts ADTs with no type arguments and references to
|
||||
/// ADTs with no type arguments.
|
||||
pub fn is_simple_text(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Adt(_, substs) => substs.types().next().is_none(),
|
||||
Ref(_, ty, _) => ty.is_simple_text(),
|
||||
_ => self.is_simple_ty(),
|
||||
@ -64,7 +64,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
/// Whether the type can be safely suggested during error recovery.
|
||||
pub fn is_suggestable(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Opaque(..) | FnDef(..) | FnPtr(..) | Dynamic(..) | Closure(..) | Infer(..)
|
||||
| Projection(..) => false,
|
||||
_ => true,
|
||||
|
@ -218,7 +218,7 @@ impl<'tcx> TypeError<'tcx> {
|
||||
|
||||
impl<'tcx> ty::TyS<'tcx> {
|
||||
pub fn sort_string(&self, tcx: TyCtxt<'_>) -> Cow<'static, str> {
|
||||
match self.kind {
|
||||
match *self.kind() {
|
||||
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str | ty::Never => {
|
||||
format!("`{}`", self).into()
|
||||
}
|
||||
@ -282,7 +282,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
}
|
||||
|
||||
pub fn prefix_string(&self) -> Cow<'static, str> {
|
||||
match self.kind {
|
||||
match *self.kind() {
|
||||
ty::Infer(_)
|
||||
| ty::Error(_)
|
||||
| ty::Bool
|
||||
@ -351,7 +351,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
);
|
||||
}
|
||||
}
|
||||
match (&values.expected.kind, &values.found.kind) {
|
||||
match (values.expected.kind(), values.found.kind()) {
|
||||
(ty::Float(_), ty::Infer(ty::IntVar(_))) => {
|
||||
if let Ok(
|
||||
// Issue #53280
|
||||
@ -512,7 +512,10 @@ impl<T> Trait<T> for X {
|
||||
}
|
||||
debug!(
|
||||
"note_and_explain_type_err expected={:?} ({:?}) found={:?} ({:?})",
|
||||
values.expected, values.expected.kind, values.found, values.found.kind,
|
||||
values.expected,
|
||||
values.expected.kind(),
|
||||
values.found,
|
||||
values.found.kind(),
|
||||
);
|
||||
}
|
||||
CyclicTy(ty) => {
|
||||
@ -556,7 +559,7 @@ impl<T> Trait<T> for X {
|
||||
if let Some(hir_generics) = item.generics() {
|
||||
// Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`.
|
||||
// This will also work for `impl Trait`.
|
||||
let def_id = if let ty::Param(param_ty) = proj_ty.self_ty().kind {
|
||||
let def_id = if let ty::Param(param_ty) = proj_ty.self_ty().kind() {
|
||||
let generics = self.generics_of(body_owner_def_id);
|
||||
generics.type_param(¶m_ty, *self).def_id
|
||||
} else {
|
||||
@ -680,7 +683,7 @@ impl<T> Trait<T> for X {
|
||||
}
|
||||
}
|
||||
|
||||
if let ty::Opaque(def_id, _) = proj_ty.self_ty().kind {
|
||||
if let ty::Opaque(def_id, _) = *proj_ty.self_ty().kind() {
|
||||
// When the expected `impl Trait` is not defined in the current item, it will come from
|
||||
// a return type. This can occur when dealing with `TryStream` (#71035).
|
||||
if self.constrain_associated_type_structured_suggestion(
|
||||
@ -750,7 +753,7 @@ fn foo(&self) -> Self::T { String::new() }
|
||||
})
|
||||
.filter_map(|(_, item)| {
|
||||
let method = self.fn_sig(item.def_id);
|
||||
match method.output().skip_binder().kind {
|
||||
match *method.output().skip_binder().kind() {
|
||||
ty::Projection(ty::ProjectionTy { item_def_id, .. })
|
||||
if item_def_id == proj_ty_item_def_id =>
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ pub fn simplify_type(
|
||||
ty: Ty<'_>,
|
||||
can_simplify_params: bool,
|
||||
) -> Option<SimplifiedType> {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Bool => Some(BoolSimplifiedType),
|
||||
ty::Char => Some(CharSimplifiedType),
|
||||
ty::Int(int_type) => Some(IntSimplifiedType(int_type)),
|
||||
|
@ -471,7 +471,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for BoundVarReplacer<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||
match t.kind {
|
||||
match *t.kind() {
|
||||
ty::Bound(debruijn, bound_ty) => {
|
||||
if debruijn == self.current_index {
|
||||
let fld_t = &mut self.fld_t;
|
||||
@ -771,7 +771,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
|
||||
}
|
||||
|
||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Bound(debruijn, bound_ty) => {
|
||||
if self.amount == 0 || debruijn < self.current_index {
|
||||
ty
|
||||
@ -987,7 +987,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
|
||||
// ignore the inputs to a projection, as they may not appear
|
||||
// in the normalized form
|
||||
if self.just_constrained {
|
||||
if let ty::Projection(..) | ty::Opaque(..) = t.kind {
|
||||
if let ty::Projection(..) | ty::Opaque(..) = t.kind() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ impl<'tcx> FieldDef {
|
||||
impl<'tcx> TyS<'tcx> {
|
||||
/// Calculates the forest of `DefId`s from which this type is visibly uninhabited.
|
||||
fn uninhabited_from(&self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> DefIdForest {
|
||||
match self.kind {
|
||||
match *self.kind() {
|
||||
Adt(def, substs) => {
|
||||
ensure_sufficient_stack(|| def.uninhabited_from(tcx, substs, param_env))
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||
};
|
||||
debug_assert!(!ty.has_infer_types_or_consts());
|
||||
|
||||
Ok(match ty.kind {
|
||||
Ok(match *ty.kind() {
|
||||
// Basic scalars.
|
||||
ty::Bool => tcx.intern_layout(Layout::scalar(
|
||||
self,
|
||||
@ -540,7 +540,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||
}
|
||||
|
||||
let unsized_part = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
|
||||
let metadata = match unsized_part.kind {
|
||||
let metadata = match unsized_part.kind() {
|
||||
ty::Foreign(..) => {
|
||||
return Ok(tcx.intern_layout(Layout::scalar(self, data_ptr)));
|
||||
}
|
||||
@ -1624,7 +1624,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||
);
|
||||
};
|
||||
|
||||
let adt_def = match layout.ty.kind {
|
||||
let adt_def = match *layout.ty.kind() {
|
||||
ty::Adt(ref adt_def, _) => {
|
||||
debug!("print-type-size t: `{:?}` process adt", layout.ty);
|
||||
adt_def
|
||||
@ -1767,11 +1767,11 @@ impl<'tcx> SizeSkeleton<'tcx> {
|
||||
Err(err) => err,
|
||||
};
|
||||
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
|
||||
let non_zero = !ty.is_unsafe_ptr();
|
||||
let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
|
||||
match tail.kind {
|
||||
match tail.kind() {
|
||||
ty::Param(_) | ty::Projection(_) => {
|
||||
debug_assert!(tail.has_param_types_or_consts());
|
||||
Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(&tail) })
|
||||
@ -2018,7 +2018,7 @@ where
|
||||
assert_eq!(original_layout.variants, Variants::Single { index });
|
||||
}
|
||||
|
||||
let fields = match this.ty.kind {
|
||||
let fields = match this.ty.kind() {
|
||||
ty::Adt(def, _) if def.variants.is_empty() =>
|
||||
bug!("for_variant called on zero-variant enum"),
|
||||
ty::Adt(def, _) => def.variants[variant_index].fields.len(),
|
||||
@ -2056,7 +2056,7 @@ where
|
||||
}))
|
||||
};
|
||||
|
||||
cx.layout_of(match this.ty.kind {
|
||||
cx.layout_of(match *this.ty.kind() {
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
| ty::Int(_)
|
||||
@ -2092,7 +2092,7 @@ where
|
||||
));
|
||||
}
|
||||
|
||||
match tcx.struct_tail_erasing_lifetimes(pointee, cx.param_env()).kind {
|
||||
match tcx.struct_tail_erasing_lifetimes(pointee, cx.param_env()).kind() {
|
||||
ty::Slice(_) | ty::Str => tcx.types.usize,
|
||||
ty::Dynamic(_, _) => {
|
||||
tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_array(tcx.types.usize, 3))
|
||||
@ -2170,7 +2170,7 @@ where
|
||||
if ty.is_fn() { cx.data_layout().instruction_address_space } else { AddressSpace::DATA }
|
||||
};
|
||||
|
||||
let pointee_info = match this.ty.kind {
|
||||
let pointee_info = match *this.ty.kind() {
|
||||
ty::RawPtr(mt) if offset.bytes() == 0 => {
|
||||
cx.layout_of(mt.ty).to_result().ok().map(|layout| PointeeInfo {
|
||||
size: layout.size,
|
||||
@ -2286,7 +2286,7 @@ where
|
||||
|
||||
// FIXME(eddyb) This should be for `ptr::Unique<T>`, not `Box<T>`.
|
||||
if let Some(ref mut pointee) = result {
|
||||
if let ty::Adt(def, _) = this.ty.kind {
|
||||
if let ty::Adt(def, _) = this.ty.kind() {
|
||||
if def.is_box() && offset.bytes() == 0 {
|
||||
pointee.safe = Some(PointerKind::UniqueOwned);
|
||||
}
|
||||
@ -2299,7 +2299,9 @@ where
|
||||
|
||||
debug!(
|
||||
"pointee_info_at (offset={:?}, type kind: {:?}) => {:?}",
|
||||
offset, this.ty.kind, pointee_info
|
||||
offset,
|
||||
this.ty.kind(),
|
||||
pointee_info
|
||||
);
|
||||
|
||||
pointee_info
|
||||
@ -2326,14 +2328,14 @@ impl<'tcx> ty::Instance<'tcx> {
|
||||
fn fn_sig_for_fn_abi(&self, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
|
||||
// FIXME(davidtwco,eddyb): A `ParamEnv` should be passed through to this function.
|
||||
let ty = self.ty(tcx, ty::ParamEnv::reveal_all());
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::FnDef(..) => {
|
||||
// HACK(davidtwco,eddyb): This is a workaround for polymorphization considering
|
||||
// parameters unused if they show up in the signature, but not in the `mir::Body`
|
||||
// (i.e. due to being inside a projection that got normalized, see
|
||||
// `src/test/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping
|
||||
// track of a polymorphization `ParamEnv` to allow normalizing later.
|
||||
let mut sig = match ty.kind {
|
||||
let mut sig = match *ty.kind() {
|
||||
ty::FnDef(def_id, substs) => tcx
|
||||
.normalize_erasing_regions(tcx.param_env(def_id), tcx.fn_sig(def_id))
|
||||
.subst(tcx, substs),
|
||||
@ -2596,7 +2598,7 @@ where
|
||||
assert!(!sig.c_variadic && extra_args.is_empty());
|
||||
|
||||
if let Some(input) = sig.inputs().last() {
|
||||
if let ty::Tuple(tupled_arguments) = input.kind {
|
||||
if let ty::Tuple(tupled_arguments) = input.kind() {
|
||||
inputs = &sig.inputs()[0..sig.inputs().len() - 1];
|
||||
tupled_arguments.iter().map(|k| k.expect_ty()).collect()
|
||||
} else {
|
||||
|
@ -580,7 +580,9 @@ bitflags! {
|
||||
|
||||
#[allow(rustc::usage_of_ty_tykind)]
|
||||
pub struct TyS<'tcx> {
|
||||
pub kind: TyKind<'tcx>,
|
||||
/// This field shouldn't be used directly and may be removed in the future.
|
||||
/// Use `TyS::kind()` instead.
|
||||
kind: TyKind<'tcx>,
|
||||
pub flags: TypeFlags,
|
||||
|
||||
/// This is a kind of confusing thing: it stores the smallest
|
||||
@ -609,13 +611,13 @@ static_assert_size!(TyS<'_>, 32);
|
||||
|
||||
impl<'tcx> Ord for TyS<'tcx> {
|
||||
fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
|
||||
self.kind.cmp(&other.kind)
|
||||
self.kind().cmp(other.kind())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> PartialOrd for TyS<'tcx> {
|
||||
fn partial_cmp(&self, other: &TyS<'tcx>) -> Option<Ordering> {
|
||||
Some(self.kind.cmp(&other.kind))
|
||||
Some(self.kind().cmp(other.kind()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ fn compute_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Compo
|
||||
// with `collect()` because of the need to sometimes skip subtrees
|
||||
// in the `subtys` iterator (e.g., when encountering a
|
||||
// projection).
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::FnDef(_, substs) => {
|
||||
// HACK(eddyb) ignore lifetimes found shallowly in `substs`.
|
||||
// This is inconsistent with `ty::Adt` (including all substs)
|
||||
|
@ -264,7 +264,7 @@ pub trait Printer<'tcx>: Sized {
|
||||
/// type. It's just a heuristic so it makes some questionable
|
||||
/// decisions and we may want to adjust it later.
|
||||
pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Adt(adt_def, _) => Some(adt_def.did),
|
||||
|
||||
ty::Dynamic(data, ..) => data.principal_def_id(),
|
||||
|
@ -457,7 +457,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
// Inherent impls. Try to print `Foo::bar` for an inherent
|
||||
// impl on `Foo`, but fallback to `<Foo>::bar` if self-type is
|
||||
// anything other than a simple path.
|
||||
match self_ty.kind {
|
||||
match self_ty.kind() {
|
||||
ty::Adt(..)
|
||||
| ty::Foreign(_)
|
||||
| ty::Bool
|
||||
@ -508,7 +508,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Bool => p!(write("bool")),
|
||||
ty::Char => p!(write("char")),
|
||||
ty::Int(t) => p!(write("{}", t.name_str())),
|
||||
@ -797,7 +797,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
// Special-case `Fn(...) -> ...` and resugar it.
|
||||
let fn_trait_kind = self.tcx().fn_trait_kind_from_lang_item(principal.def_id);
|
||||
if !self.tcx().sess.verbose() && fn_trait_kind.is_some() {
|
||||
if let ty::Tuple(ref args) = principal.substs.type_at(0).kind {
|
||||
if let ty::Tuple(ref args) = principal.substs.type_at(0).kind() {
|
||||
let mut projections = predicates.projection_bounds();
|
||||
if let (Some(proj), None) = (projections.next(), projections.next()) {
|
||||
let tys: Vec<_> = args.iter().map(|k| k.expect_ty()).collect();
|
||||
@ -976,7 +976,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
) -> Result<Self::Const, Self::Error> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
match (scalar, &ty.kind) {
|
||||
match (scalar, &ty.kind()) {
|
||||
// Byte strings (&[u8; N])
|
||||
(
|
||||
Scalar::Ptr(ptr),
|
||||
@ -1136,7 +1136,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
|
||||
let u8_type = self.tcx().types.u8;
|
||||
|
||||
match (ct, &ty.kind) {
|
||||
match (ct, ty.kind()) {
|
||||
// Byte/string slices, printed as (byte) string literals.
|
||||
(
|
||||
ConstValue::Slice { data, start, end },
|
||||
@ -1189,7 +1189,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
);
|
||||
let fields = contents.fields.iter().copied();
|
||||
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Array(..) => {
|
||||
p!(write("["), comma_sep(fields), write("]"));
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
|
||||
) -> RelateResult<'tcx, Ty<'tcx>> {
|
||||
let tcx = relation.tcx();
|
||||
debug!("super_relate_tys: a={:?} b={:?}", a, b);
|
||||
match (&a.kind, &b.kind) {
|
||||
match (a.kind(), b.kind()) {
|
||||
(&ty::Infer(_), _) | (_, &ty::Infer(_)) => {
|
||||
// The caller should handle these cases!
|
||||
bug!("var types encountered in super_relate_tys")
|
||||
@ -516,7 +516,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
|
||||
(ConstValue::Scalar(a_val), ConstValue::Scalar(b_val)) if a.ty == b.ty => {
|
||||
if a_val == b_val {
|
||||
Ok(ConstValue::Scalar(a_val))
|
||||
} else if let ty::FnPtr(_) = a.ty.kind {
|
||||
} else if let ty::FnPtr(_) = a.ty.kind() {
|
||||
let a_instance = tcx.global_alloc(a_val.assert_ptr().alloc_id).unwrap_fn();
|
||||
let b_instance = tcx.global_alloc(b_val.assert_ptr().alloc_id).unwrap_fn();
|
||||
if a_instance == b_instance {
|
||||
@ -540,7 +540,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
|
||||
}
|
||||
|
||||
(ConstValue::ByRef { .. }, ConstValue::ByRef { .. }) => {
|
||||
match a.ty.kind {
|
||||
match a.ty.kind() {
|
||||
ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => {
|
||||
let a_destructured = tcx.destructure_const(relation.param_env().and(a));
|
||||
let b_destructured = tcx.destructure_const(relation.param_env().and(b));
|
||||
|
@ -923,25 +923,25 @@ impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let kind = match self.kind {
|
||||
let kind = match self.kind() {
|
||||
ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)),
|
||||
ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
|
||||
ty::Slice(typ) => ty::Slice(typ.fold_with(folder)),
|
||||
ty::Adt(tid, substs) => ty::Adt(tid, substs.fold_with(folder)),
|
||||
ty::Adt(tid, substs) => ty::Adt(*tid, substs.fold_with(folder)),
|
||||
ty::Dynamic(ref trait_ty, ref region) => {
|
||||
ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder))
|
||||
}
|
||||
ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)),
|
||||
ty::FnDef(def_id, substs) => ty::FnDef(def_id, substs.fold_with(folder)),
|
||||
ty::FnDef(def_id, substs) => ty::FnDef(*def_id, substs.fold_with(folder)),
|
||||
ty::FnPtr(f) => ty::FnPtr(f.fold_with(folder)),
|
||||
ty::Ref(ref r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl),
|
||||
ty::Ref(ref r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), *mutbl),
|
||||
ty::Generator(did, substs, movability) => {
|
||||
ty::Generator(did, substs.fold_with(folder), movability)
|
||||
ty::Generator(*did, substs.fold_with(folder), *movability)
|
||||
}
|
||||
ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)),
|
||||
ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)),
|
||||
ty::Closure(did, substs) => ty::Closure(*did, substs.fold_with(folder)),
|
||||
ty::Projection(ref data) => ty::Projection(data.fold_with(folder)),
|
||||
ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)),
|
||||
ty::Opaque(did, substs) => ty::Opaque(*did, substs.fold_with(folder)),
|
||||
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
@ -958,7 +958,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||
| ty::Foreign(..) => return self,
|
||||
};
|
||||
|
||||
if self.kind == kind { self } else { folder.tcx().mk_ty(kind) }
|
||||
if *self.kind() == kind { self } else { folder.tcx().mk_ty(kind) }
|
||||
}
|
||||
|
||||
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
@ -966,7 +966,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
ty::RawPtr(ref tm) => tm.visit_with(visitor),
|
||||
ty::Array(typ, sz) => typ.visit_with(visitor) || sz.visit_with(visitor),
|
||||
ty::Slice(typ) => typ.visit_with(visitor),
|
||||
|
@ -367,7 +367,8 @@ impl<'tcx> ClosureSubsts<'tcx> {
|
||||
/// Used primarily by `ty::print::pretty` to be able to handle closure
|
||||
/// types that haven't had their synthetic types substituted in.
|
||||
pub fn is_valid(self) -> bool {
|
||||
self.substs.len() >= 3 && matches!(self.split().tupled_upvars_ty.expect_ty().kind, Tuple(_))
|
||||
self.substs.len() >= 3
|
||||
&& matches!(self.split().tupled_upvars_ty.expect_ty().kind(), Tuple(_))
|
||||
}
|
||||
|
||||
/// Returns the substitutions of the closure's parent.
|
||||
@ -414,9 +415,9 @@ impl<'tcx> ClosureSubsts<'tcx> {
|
||||
/// Extracts the signature from the closure.
|
||||
pub fn sig(self) -> ty::PolyFnSig<'tcx> {
|
||||
let ty = self.sig_as_fn_ptr_ty();
|
||||
match ty.kind {
|
||||
ty::FnPtr(sig) => sig,
|
||||
_ => bug!("closure_sig_as_fn_ptr_ty is not a fn-ptr: {:?}", ty.kind),
|
||||
match ty.kind() {
|
||||
ty::FnPtr(sig) => *sig,
|
||||
_ => bug!("closure_sig_as_fn_ptr_ty is not a fn-ptr: {:?}", ty.kind()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -484,7 +485,8 @@ impl<'tcx> GeneratorSubsts<'tcx> {
|
||||
/// Used primarily by `ty::print::pretty` to be able to handle generator
|
||||
/// types that haven't had their synthetic types substituted in.
|
||||
pub fn is_valid(self) -> bool {
|
||||
self.substs.len() >= 5 && matches!(self.split().tupled_upvars_ty.expect_ty().kind, Tuple(_))
|
||||
self.substs.len() >= 5
|
||||
&& matches!(self.split().tupled_upvars_ty.expect_ty().kind(), Tuple(_))
|
||||
}
|
||||
|
||||
/// Returns the substitutions of the generator's parent.
|
||||
@ -1741,9 +1743,14 @@ impl RegionKind {
|
||||
|
||||
/// Type utilities
|
||||
impl<'tcx> TyS<'tcx> {
|
||||
#[inline(always)]
|
||||
pub fn kind(&self) -> &TyKind<'tcx> {
|
||||
&self.kind
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_unit(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Tuple(ref tys) => tys.is_empty(),
|
||||
_ => false,
|
||||
}
|
||||
@ -1751,7 +1758,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_never(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Never => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -1766,7 +1773,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
pub fn conservative_is_privately_uninhabited(&self, tcx: TyCtxt<'tcx>) -> bool {
|
||||
// FIXME(varkor): we can make this less conversative by substituting concrete
|
||||
// type arguments.
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
ty::Never => true,
|
||||
ty::Adt(def, _) if def.is_union() => {
|
||||
// For now, `union`s are never considered uninhabited.
|
||||
@ -1806,12 +1813,28 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_primitive(&self) -> bool {
|
||||
self.kind.is_primitive()
|
||||
self.kind().is_primitive()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_adt(&self) -> bool {
|
||||
match self.kind() {
|
||||
Adt(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_ref(&self) -> bool {
|
||||
match self.kind() {
|
||||
Ref(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_ty_var(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Infer(TyVar(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -1819,7 +1842,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_ty_infer(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Infer(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -1827,23 +1850,23 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_phantom_data(&self) -> bool {
|
||||
if let Adt(def, _) = self.kind { def.is_phantom_data() } else { false }
|
||||
if let Adt(def, _) = self.kind() { def.is_phantom_data() } else { false }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_bool(&self) -> bool {
|
||||
self.kind == Bool
|
||||
*self.kind() == Bool
|
||||
}
|
||||
|
||||
/// Returns `true` if this type is a `str`.
|
||||
#[inline]
|
||||
pub fn is_str(&self) -> bool {
|
||||
self.kind == Str
|
||||
*self.kind() == Str
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_param(&self, index: u32) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
ty::Param(ref data) => data.index == index,
|
||||
_ => false,
|
||||
}
|
||||
@ -1851,8 +1874,8 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_slice(&self) -> bool {
|
||||
match self.kind {
|
||||
RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => match ty.kind {
|
||||
match self.kind() {
|
||||
RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => match ty.kind() {
|
||||
Slice(_) | Str => true,
|
||||
_ => false,
|
||||
},
|
||||
@ -1860,16 +1883,24 @@ impl<'tcx> TyS<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_array(&self) -> bool {
|
||||
match self.kind() {
|
||||
Array(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_simd(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Adt(def, _) => def.repr.simd(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sequence_element_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Array(ty, _) | Slice(ty) => ty,
|
||||
Str => tcx.mk_mach_uint(ast::UintTy::U8),
|
||||
_ => bug!("`sequence_element_type` called on non-sequence value: {}", self),
|
||||
@ -1877,7 +1908,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
}
|
||||
|
||||
pub fn simd_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Adt(def, substs) => def.non_enum_variant().fields[0].ty(tcx, substs),
|
||||
_ => bug!("`simd_type` called on invalid type"),
|
||||
}
|
||||
@ -1886,14 +1917,14 @@ impl<'tcx> TyS<'tcx> {
|
||||
pub fn simd_size(&self, _tcx: TyCtxt<'tcx>) -> u64 {
|
||||
// Parameter currently unused, but probably needed in the future to
|
||||
// allow `#[repr(simd)] struct Simd<T, const N: usize>([T; N]);`.
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Adt(def, _) => def.non_enum_variant().fields.len() as u64,
|
||||
_ => bug!("`simd_size` called on invalid type"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn simd_size_and_type(&self, tcx: TyCtxt<'tcx>) -> (u64, Ty<'tcx>) {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Adt(def, substs) => {
|
||||
let variant = def.non_enum_variant();
|
||||
(variant.fields.len() as u64, variant.fields[0].ty(tcx, substs))
|
||||
@ -1904,7 +1935,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_region_ptr(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Ref(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -1912,7 +1943,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_mutable_ptr(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
RawPtr(TypeAndMut { mutbl: hir::Mutability::Mut, .. })
|
||||
| Ref(_, _, hir::Mutability::Mut) => true,
|
||||
_ => false,
|
||||
@ -1921,7 +1952,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_unsafe_ptr(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
RawPtr(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -1935,7 +1966,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_box(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Adt(def, _) => def.is_box(),
|
||||
_ => false,
|
||||
}
|
||||
@ -1943,7 +1974,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
/// Panics if called on any type other than `Box<T>`.
|
||||
pub fn boxed_ty(&self) -> Ty<'tcx> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Adt(def, substs) if def.is_box() => substs.type_at(0),
|
||||
_ => bug!("`boxed_ty` is called on non-box type {:?}", self),
|
||||
}
|
||||
@ -1954,7 +1985,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
/// contents are abstract to rustc.)
|
||||
#[inline]
|
||||
pub fn is_scalar(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Bool
|
||||
| Char
|
||||
| Int(_)
|
||||
@ -1971,7 +2002,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
/// Returns `true` if this type is a floating point type.
|
||||
#[inline]
|
||||
pub fn is_floating_point(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Float(_) | Infer(FloatVar(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -1979,7 +2010,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_trait(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Dynamic(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -1987,7 +2018,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_enum(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Adt(adt_def, _) => adt_def.is_enum(),
|
||||
_ => false,
|
||||
}
|
||||
@ -1995,7 +2026,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_closure(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Closure(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2003,7 +2034,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_generator(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Generator(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2011,7 +2042,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_integral(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Infer(IntVar(_)) | Int(_) | Uint(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2019,7 +2050,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_fresh_ty(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Infer(FreshTy(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2027,7 +2058,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_fresh(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Infer(FreshTy(_)) => true,
|
||||
Infer(FreshIntTy(_)) => true,
|
||||
Infer(FreshFloatTy(_)) => true,
|
||||
@ -2037,7 +2068,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_char(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Char => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2050,7 +2081,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_signed(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Int(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2058,7 +2089,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_ptr_sized_integral(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2066,7 +2097,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_machine(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Int(..) | Uint(..) | Float(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2074,7 +2105,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn has_concrete_skeleton(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Param(_) | Infer(_) | Error(_) => false,
|
||||
_ => true,
|
||||
}
|
||||
@ -2085,28 +2116,28 @@ impl<'tcx> TyS<'tcx> {
|
||||
/// The parameter `explicit` indicates if this is an *explicit* dereference.
|
||||
/// Some types -- notably unsafe ptrs -- can only be dereferenced explicitly.
|
||||
pub fn builtin_deref(&self, explicit: bool) -> Option<TypeAndMut<'tcx>> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Adt(def, _) if def.is_box() => {
|
||||
Some(TypeAndMut { ty: self.boxed_ty(), mutbl: hir::Mutability::Not })
|
||||
}
|
||||
Ref(_, ty, mutbl) => Some(TypeAndMut { ty, mutbl }),
|
||||
RawPtr(mt) if explicit => Some(mt),
|
||||
Ref(_, ty, mutbl) => Some(TypeAndMut { ty, mutbl: *mutbl }),
|
||||
RawPtr(mt) if explicit => Some(*mt),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the type of `ty[i]`.
|
||||
pub fn builtin_index(&self) -> Option<Ty<'tcx>> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Array(ty, _) | Slice(ty) => Some(ty),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fn_sig(&self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
|
||||
match self.kind {
|
||||
FnDef(def_id, substs) => tcx.fn_sig(def_id).subst(tcx, substs),
|
||||
FnPtr(f) => f,
|
||||
match self.kind() {
|
||||
FnDef(def_id, substs) => tcx.fn_sig(*def_id).subst(tcx, substs),
|
||||
FnPtr(f) => *f,
|
||||
Error(_) => {
|
||||
// ignore errors (#54954)
|
||||
ty::Binder::dummy(FnSig::fake())
|
||||
@ -2120,7 +2151,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_fn(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
FnDef(..) | FnPtr(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2128,7 +2159,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_fn_ptr(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
FnPtr(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2136,7 +2167,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_impl_trait(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Opaque(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -2144,7 +2175,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn ty_adt_def(&self) -> Option<&'tcx AdtDef> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Adt(adt, _) => Some(adt),
|
||||
_ => None,
|
||||
}
|
||||
@ -2153,7 +2184,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
/// Iterates over tuple fields.
|
||||
/// Panics when called on anything but a tuple.
|
||||
pub fn tuple_fields(&self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Tuple(substs) => substs.iter().map(|field| field.expect_ty()),
|
||||
_ => bug!("tuple_fields called on non-tuple"),
|
||||
}
|
||||
@ -2164,10 +2195,10 @@ impl<'tcx> TyS<'tcx> {
|
||||
// FIXME: This requires the optimized MIR in the case of generators.
|
||||
#[inline]
|
||||
pub fn variant_range(&self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
TyKind::Adt(adt, _) => Some(adt.variant_range()),
|
||||
TyKind::Generator(def_id, substs, _) => {
|
||||
Some(substs.as_generator().variant_range(def_id, tcx))
|
||||
Some(substs.as_generator().variant_range(*def_id, tcx))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
@ -2183,7 +2214,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
variant_index: VariantIdx,
|
||||
) -> Option<Discr<'tcx>> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
TyKind::Adt(adt, _) if adt.variants.is_empty() => {
|
||||
bug!("discriminant_for_variant called on zero variant enum");
|
||||
}
|
||||
@ -2191,7 +2222,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
Some(adt.discriminant_for_variant(tcx, variant_index))
|
||||
}
|
||||
TyKind::Generator(def_id, substs, _) => {
|
||||
Some(substs.as_generator().discriminant_for_variant(def_id, tcx, variant_index))
|
||||
Some(substs.as_generator().discriminant_for_variant(*def_id, tcx, variant_index))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
@ -2199,7 +2230,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
/// Returns the type of the discriminant of this type.
|
||||
pub fn discriminant_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
ty::Adt(adt, _) if adt.is_enum() => adt.repr.discr_type().to_ty(tcx),
|
||||
ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx),
|
||||
_ => {
|
||||
@ -2222,7 +2253,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
/// inferred. Once upvar inference (in `src/librustc_typeck/check/upvar.rs`)
|
||||
/// is complete, that type variable will be unified.
|
||||
pub fn to_opt_closure_kind(&self) -> Option<ty::ClosureKind> {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
Int(int_ty) => match int_ty {
|
||||
ast::IntTy::I8 => Some(ty::ClosureKind::Fn),
|
||||
ast::IntTy::I16 => Some(ty::ClosureKind::FnMut),
|
||||
@ -2245,7 +2276,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
/// Returning true means the type is known to be sized. Returning
|
||||
/// `false` means nothing -- could be sized, might not be.
|
||||
pub fn is_trivially_sized(&self, tcx: TyCtxt<'tcx>) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
|
||||
| ty::Uint(_)
|
||||
| ty::Int(_)
|
||||
|
@ -486,7 +486,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
|
||||
return t;
|
||||
}
|
||||
|
||||
match t.kind {
|
||||
match *t.kind() {
|
||||
ty::Param(p) => self.ty_for_param(p, t),
|
||||
_ => t.super_fold_with(self),
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ pub struct Discr<'tcx> {
|
||||
|
||||
impl<'tcx> fmt::Display for Discr<'tcx> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.ty.kind {
|
||||
match *self.ty.kind() {
|
||||
ty::Int(ity) => {
|
||||
let size = ty::tls::with(|tcx| Integer::from_attr(&tcx, SignedInt(ity)).size());
|
||||
let x = self.val;
|
||||
@ -59,7 +59,7 @@ fn unsigned_max(size: Size) -> u128 {
|
||||
}
|
||||
|
||||
fn int_size_and_signed<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> (Size, bool) {
|
||||
let (int, signed) = match ty.kind {
|
||||
let (int, signed) = match *ty.kind() {
|
||||
Int(ity) => (Integer::from_attr(&tcx, SignedInt(ity)), true),
|
||||
Uint(uty) => (Integer::from_attr(&tcx, UnsignedInt(uty)), false),
|
||||
_ => bug!("non integer discriminant"),
|
||||
@ -174,10 +174,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn has_error_field(self, ty: Ty<'tcx>) -> bool {
|
||||
if let ty::Adt(def, substs) = ty.kind {
|
||||
if let ty::Adt(def, substs) = *ty.kind() {
|
||||
for field in def.all_fields() {
|
||||
let field_ty = field.ty(self, substs);
|
||||
if let Error(_) = field_ty.kind {
|
||||
if let Error(_) = field_ty.kind() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -225,7 +225,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
normalize: impl Fn(Ty<'tcx>) -> Ty<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
loop {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Adt(def, substs) => {
|
||||
if !def.is_struct() {
|
||||
break;
|
||||
@ -298,7 +298,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
) -> (Ty<'tcx>, Ty<'tcx>) {
|
||||
let (mut a, mut b) = (source, target);
|
||||
loop {
|
||||
match (&a.kind, &b.kind) {
|
||||
match (&a.kind(), &b.kind()) {
|
||||
(&Adt(a_def, a_substs), &Adt(b_def, b_substs))
|
||||
if a_def == b_def && a_def.is_struct() =>
|
||||
{
|
||||
@ -401,12 +401,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
// <P1, P2, P0>, and then look up which of the impl substs refer to
|
||||
// parameters marked as pure.
|
||||
|
||||
let impl_substs = match self.type_of(impl_def_id).kind {
|
||||
let impl_substs = match *self.type_of(impl_def_id).kind() {
|
||||
ty::Adt(def_, substs) if def_ == def => substs,
|
||||
_ => bug!(),
|
||||
};
|
||||
|
||||
let item_substs = match self.type_of(def.did).kind {
|
||||
let item_substs = match *self.type_of(def.did).kind() {
|
||||
ty::Adt(def_, substs) if def_ == def => substs,
|
||||
_ => bug!(),
|
||||
};
|
||||
@ -640,7 +640,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
/// Returns the maximum value for the given numeric type (including `char`s)
|
||||
/// or returns `None` if the type is not numeric.
|
||||
pub fn numeric_max_val(&'tcx self, tcx: TyCtxt<'tcx>) -> Option<&'tcx ty::Const<'tcx>> {
|
||||
let val = match self.kind {
|
||||
let val = match self.kind() {
|
||||
ty::Int(_) | ty::Uint(_) => {
|
||||
let (size, signed) = int_size_and_signed(tcx, self);
|
||||
let val = if signed { signed_max(size) as u128 } else { unsigned_max(size) };
|
||||
@ -659,7 +659,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
/// Returns the minimum value for the given numeric type (including `char`s)
|
||||
/// or returns `None` if the type is not numeric.
|
||||
pub fn numeric_min_val(&'tcx self, tcx: TyCtxt<'tcx>) -> Option<&'tcx ty::Const<'tcx>> {
|
||||
let val = match self.kind {
|
||||
let val = match self.kind() {
|
||||
ty::Int(_) | ty::Uint(_) => {
|
||||
let (size, signed) = int_size_and_signed(tcx, self);
|
||||
let val = if signed { truncate(signed_min(size) as u128, size) } else { 0 };
|
||||
@ -717,7 +717,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
/// Returning true means the type is known to be `Freeze`. Returning
|
||||
/// `false` means nothing -- could be `Freeze`, might not be.
|
||||
fn is_trivially_freeze(&self) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
ty::Int(_)
|
||||
| ty::Uint(_)
|
||||
| ty::Float(_)
|
||||
@ -793,7 +793,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
/// down, you will need to use a type visitor.
|
||||
#[inline]
|
||||
pub fn is_structural_eq_shallow(&'tcx self, tcx: TyCtxt<'tcx>) -> bool {
|
||||
match self.kind {
|
||||
match self.kind() {
|
||||
// Look for an impl of both `PartialStructuralEq` and `StructuralEq`.
|
||||
Adt(..) => tcx.has_structural_eq_impls(self),
|
||||
|
||||
@ -828,7 +828,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
}
|
||||
|
||||
pub fn same_type(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
|
||||
match (&a.kind, &b.kind) {
|
||||
match (&a.kind(), &b.kind()) {
|
||||
(&Adt(did_a, substs_a), &Adt(did_b, substs_b)) => {
|
||||
if did_a != did_b {
|
||||
return false;
|
||||
@ -860,7 +860,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
representable_cache: &mut FxHashMap<Ty<'tcx>, Representability>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Representability {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
Tuple(..) => {
|
||||
// Find non representable
|
||||
fold_repr(ty.tuple_fields().map(|ty| {
|
||||
@ -909,7 +909,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
}
|
||||
|
||||
fn same_struct_or_enum<'tcx>(ty: Ty<'tcx>, def: &'tcx ty::AdtDef) -> bool {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
Adt(ty_def, _) => ty_def == def,
|
||||
_ => false,
|
||||
}
|
||||
@ -947,7 +947,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
representable_cache: &mut FxHashMap<Ty<'tcx>, Representability>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Representability {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
Adt(def, _) => {
|
||||
{
|
||||
// Iterate through stack of previously seen types.
|
||||
@ -962,7 +962,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
// struct Bar<T> { x: Bar<Foo> }
|
||||
|
||||
if let Some(&seen_type) = iter.next() {
|
||||
if same_struct_or_enum(seen_type, def) {
|
||||
if same_struct_or_enum(seen_type, *def) {
|
||||
debug!("SelfRecursive: {:?} contains {:?}", seen_type, ty);
|
||||
return Representability::SelfRecursive(vec![sp]);
|
||||
}
|
||||
@ -1024,7 +1024,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
/// - `&'a *const &'b u8 -> *const &'b u8`
|
||||
pub fn peel_refs(&'tcx self) -> Ty<'tcx> {
|
||||
let mut ty = self;
|
||||
while let Ref(_, inner_ty, _) = ty.kind {
|
||||
while let Ref(_, inner_ty, _) = ty.kind() {
|
||||
ty = inner_ty;
|
||||
}
|
||||
ty
|
||||
@ -1070,7 +1070,7 @@ impl<'tcx> ExplicitSelf<'tcx> {
|
||||
{
|
||||
use self::ExplicitSelf::*;
|
||||
|
||||
match self_arg_ty.kind {
|
||||
match *self_arg_ty.kind() {
|
||||
_ if is_self_ty(self_arg_ty) => ByValue,
|
||||
ty::Ref(region, ty, mutbl) if is_self_ty(ty) => ByReference(region, mutbl),
|
||||
ty::RawPtr(ty::TypeAndMut { ty, mutbl }) if is_self_ty(ty) => ByRawPointer(mutbl),
|
||||
@ -1087,7 +1087,7 @@ pub fn needs_drop_components(
|
||||
ty: Ty<'tcx>,
|
||||
target_layout: &TargetDataLayout,
|
||||
) -> Result<SmallVec<[Ty<'tcx>; 2]>, AlwaysRequiresDrop> {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Infer(ty::FreshIntTy(_))
|
||||
| ty::Infer(ty::FreshFloatTy(_))
|
||||
| ty::Bool
|
||||
|
@ -98,7 +98,7 @@ impl<'tcx> super::TyS<'tcx> {
|
||||
// types as they are written).
|
||||
fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) {
|
||||
match parent.unpack() {
|
||||
GenericArgKind::Type(parent_ty) => match parent_ty.kind {
|
||||
GenericArgKind::Type(parent_ty) => match *parent_ty.kind() {
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
| ty::Int(_)
|
||||
|
@ -291,7 +291,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let ty =
|
||||
Place::ty_from(used_place.local, used_place.projection, self.body, self.infcx.tcx)
|
||||
.ty;
|
||||
let needs_note = match ty.kind {
|
||||
let needs_note = match ty.kind() {
|
||||
ty::Closure(id, _) => {
|
||||
let tables = self.infcx.tcx.typeck(id.expect_local());
|
||||
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(id.expect_local());
|
||||
@ -306,7 +306,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let ty = place.ty(self.body, self.infcx.tcx).ty;
|
||||
|
||||
if is_loop_move {
|
||||
if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind {
|
||||
if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
|
||||
// We have a `&mut` ref, we need to reborrow on each iteration (#62112).
|
||||
err.span_suggestion_verbose(
|
||||
span.shrink_to_lo(),
|
||||
@ -329,7 +329,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
Some(ref name) => format!("`{}`", name),
|
||||
None => "value".to_owned(),
|
||||
};
|
||||
if let ty::Param(param_ty) = ty.kind {
|
||||
if let ty::Param(param_ty) = ty.kind() {
|
||||
let tcx = self.infcx.tcx;
|
||||
let generics = tcx.generics_of(self.mir_def_id);
|
||||
let param = generics.type_param(¶m_ty, tcx);
|
||||
@ -997,7 +997,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
.opt_name(fn_hir_id)
|
||||
.map(|name| format!("function `{}`", name))
|
||||
.unwrap_or_else(|| {
|
||||
match &self.infcx.tcx.typeck(self.mir_def_id).node_type(fn_hir_id).kind
|
||||
match &self
|
||||
.infcx
|
||||
.tcx
|
||||
.typeck(self.mir_def_id)
|
||||
.node_type(fn_hir_id)
|
||||
.kind()
|
||||
{
|
||||
ty::Closure(..) => "enclosing closure",
|
||||
ty::Generator(..) => "enclosing generator",
|
||||
@ -1625,7 +1630,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
},
|
||||
ProjectionElem::Field(..) | ProjectionElem::Downcast(..) => {
|
||||
let base_ty = Place::ty_from(place.local, proj_base, self.body, tcx).ty;
|
||||
match base_ty.kind {
|
||||
match base_ty.kind() {
|
||||
ty::Adt(def, _) if def.has_dtor(tcx) => {
|
||||
// Report the outermost adt with a destructor
|
||||
match base_access {
|
||||
@ -1689,7 +1694,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
None
|
||||
} else {
|
||||
let ty = self.infcx.tcx.type_of(self.mir_def_id);
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
|
||||
self.mir_def_id.to_def_id(),
|
||||
self.infcx.tcx.fn_sig(self.mir_def_id),
|
||||
@ -1924,13 +1929,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
// 3. The return type is not a reference. In this case, we don't highlight
|
||||
// anything.
|
||||
let return_ty = sig.output();
|
||||
match return_ty.skip_binder().kind {
|
||||
match return_ty.skip_binder().kind() {
|
||||
ty::Ref(return_region, _, _) if return_region.has_name() && !is_closure => {
|
||||
// This is case 1 from above, return type is a named reference so we need to
|
||||
// search for relevant arguments.
|
||||
let mut arguments = Vec::new();
|
||||
for (index, argument) in sig.inputs().skip_binder().iter().enumerate() {
|
||||
if let ty::Ref(argument_region, _, _) = argument.kind {
|
||||
if let ty::Ref(argument_region, _, _) = argument.kind() {
|
||||
if argument_region == return_region {
|
||||
// Need to use the `rustc_middle::ty` types to compare against the
|
||||
// `return_region`. Then use the `rustc_hir` type to get only
|
||||
@ -1976,9 +1981,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
// Closure arguments are wrapped in a tuple, so we need to get the first
|
||||
// from that.
|
||||
if let ty::Tuple(elems) = argument_ty.kind {
|
||||
if let ty::Tuple(elems) = argument_ty.kind() {
|
||||
let argument_ty = elems.first()?.expect_ty();
|
||||
if let ty::Ref(_, _, _) = argument_ty.kind {
|
||||
if let ty::Ref(_, _, _) = argument_ty.kind() {
|
||||
return Some(AnnotatedBorrowFnSignature::Closure {
|
||||
argument_ty,
|
||||
argument_span,
|
||||
@ -1998,7 +2003,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let return_ty = sig.output().skip_binder();
|
||||
|
||||
// We expect the first argument to be a reference.
|
||||
match argument_ty.kind {
|
||||
match argument_ty.kind() {
|
||||
ty::Ref(_, _, _) => {}
|
||||
_ => return None,
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ impl BorrowExplanation {
|
||||
should_note_order,
|
||||
} => {
|
||||
let local_decl = &body.local_decls[dropped_local];
|
||||
let (dtor_desc, type_desc) = match local_decl.ty.kind {
|
||||
let (dtor_desc, type_desc) = match local_decl.ty.kind() {
|
||||
// If type is an ADT that implements Drop, then
|
||||
// simplify output by reporting just the ADT name.
|
||||
ty::Adt(adt, _substs) if adt.has_dtor(tcx) && !adt.is_box() => {
|
||||
@ -626,7 +626,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
if from == target {
|
||||
debug!("was_captured_by_trait_object: ty={:?}", ty);
|
||||
// Check the type for a trait object.
|
||||
return match ty.kind {
|
||||
return match ty.kind() {
|
||||
// `&dyn Trait`
|
||||
ty::Ref(_, ty, _) if ty.is_trait() => true,
|
||||
// `Box<dyn Trait>`
|
||||
|
@ -81,43 +81,41 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let terminator = self.body[location.block].terminator();
|
||||
debug!("add_moved_or_invoked_closure_note: terminator={:?}", terminator);
|
||||
if let TerminatorKind::Call {
|
||||
func:
|
||||
Operand::Constant(box Constant {
|
||||
literal: ty::Const { ty: &ty::TyS { kind: ty::FnDef(id, _), .. }, .. },
|
||||
..
|
||||
}),
|
||||
func: Operand::Constant(box Constant { literal: ty::Const { ty: const_ty, .. }, .. }),
|
||||
args,
|
||||
..
|
||||
} = &terminator.kind
|
||||
{
|
||||
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
|
||||
if self.infcx.tcx.parent(id) == self.infcx.tcx.lang_items().fn_once_trait() {
|
||||
let closure = match args.first() {
|
||||
Some(Operand::Copy(ref place)) | Some(Operand::Move(ref place))
|
||||
if target == place.local_or_deref_local() =>
|
||||
{
|
||||
place.local_or_deref_local().unwrap()
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
if let ty::FnDef(id, _) = *const_ty.kind() {
|
||||
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
|
||||
if self.infcx.tcx.parent(id) == self.infcx.tcx.lang_items().fn_once_trait() {
|
||||
let closure = match args.first() {
|
||||
Some(Operand::Copy(ref place)) | Some(Operand::Move(ref place))
|
||||
if target == place.local_or_deref_local() =>
|
||||
{
|
||||
place.local_or_deref_local().unwrap()
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
|
||||
debug!("add_moved_or_invoked_closure_note: closure={:?}", closure);
|
||||
if let ty::Closure(did, _) = self.body.local_decls[closure].ty.kind {
|
||||
let did = did.expect_local();
|
||||
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did);
|
||||
debug!("add_moved_or_invoked_closure_note: closure={:?}", closure);
|
||||
if let ty::Closure(did, _) = self.body.local_decls[closure].ty.kind() {
|
||||
let did = did.expect_local();
|
||||
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did);
|
||||
|
||||
if let Some((span, name)) =
|
||||
self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id)
|
||||
{
|
||||
diag.span_note(
|
||||
*span,
|
||||
&format!(
|
||||
"closure cannot be invoked more than once because it moves the \
|
||||
variable `{}` out of its environment",
|
||||
name,
|
||||
),
|
||||
);
|
||||
return;
|
||||
if let Some((span, name)) =
|
||||
self.infcx.tcx.typeck(did).closure_kind_origins().get(hir_id)
|
||||
{
|
||||
diag.span_note(
|
||||
*span,
|
||||
&format!(
|
||||
"closure cannot be invoked more than once because it moves the \
|
||||
variable `{}` out of its environment",
|
||||
name,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,7 +123,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
// Check if we are just moving a closure after it has been invoked.
|
||||
if let Some(target) = target {
|
||||
if let ty::Closure(did, _) = self.body.local_decls[target].ty.kind {
|
||||
if let ty::Closure(did, _) = self.body.local_decls[target].ty.kind() {
|
||||
let did = did.expect_local();
|
||||
let hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(did);
|
||||
|
||||
@ -365,7 +363,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
// If the type is a box, the field is described from the boxed type
|
||||
self.describe_field_from_ty(&ty.boxed_ty(), field, variant_index)
|
||||
} else {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Adt(def, _) => {
|
||||
let variant = if let Some(idx) = variant_index {
|
||||
assert!(def.is_enum());
|
||||
@ -496,7 +494,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
// We need to add synthesized lifetimes where appropriate. We do
|
||||
// this by hooking into the pretty printer and telling it to label the
|
||||
// lifetimes without names with the value `'0`.
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Ref(
|
||||
ty::RegionKind::ReLateBound(_, br)
|
||||
| ty::RegionKind::RePlaceholder(ty::PlaceholderRegion { name: br, .. }),
|
||||
@ -516,7 +514,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
let mut s = String::new();
|
||||
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, &mut s, Namespace::TypeNS);
|
||||
|
||||
let region = match ty.kind {
|
||||
let region = match ty.kind() {
|
||||
ty::Ref(region, _, _) => {
|
||||
match region {
|
||||
ty::RegionKind::ReLateBound(_, br)
|
||||
@ -680,7 +678,7 @@ impl BorrowedContentSource<'tcx> {
|
||||
BorrowedContentSource::DerefRawPointer => "a raw pointer".to_string(),
|
||||
BorrowedContentSource::DerefSharedRef => "a shared reference".to_string(),
|
||||
BorrowedContentSource::DerefMutableRef => "a mutable reference".to_string(),
|
||||
BorrowedContentSource::OverloadedDeref(ty) => match ty.kind {
|
||||
BorrowedContentSource::OverloadedDeref(ty) => match ty.kind() {
|
||||
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Rc, def.did) => {
|
||||
"an `Rc`".to_string()
|
||||
}
|
||||
@ -712,7 +710,7 @@ impl BorrowedContentSource<'tcx> {
|
||||
BorrowedContentSource::DerefMutableRef => {
|
||||
bug!("describe_for_immutable_place: DerefMutableRef isn't immutable")
|
||||
}
|
||||
BorrowedContentSource::OverloadedDeref(ty) => match ty.kind {
|
||||
BorrowedContentSource::OverloadedDeref(ty) => match ty.kind() {
|
||||
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Rc, def.did) => {
|
||||
"an `Rc`".to_string()
|
||||
}
|
||||
@ -726,7 +724,7 @@ impl BorrowedContentSource<'tcx> {
|
||||
}
|
||||
|
||||
fn from_call(func: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Option<Self> {
|
||||
match func.kind {
|
||||
match *func.kind() {
|
||||
ty::FnDef(def_id, substs) => {
|
||||
let trait_id = tcx.trait_of_item(def_id)?;
|
||||
|
||||
@ -812,7 +810,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
{
|
||||
let mut method_did = None;
|
||||
if let Operand::Constant(box Constant { literal: ty::Const { ty, .. }, .. }) = func {
|
||||
if let ty::FnDef(def_id, _) = ty.kind {
|
||||
if let ty::FnDef(def_id, _) = *ty.kind() {
|
||||
debug!("move_spans: fn = {:?}", def_id);
|
||||
if let Some(ty::AssocItem { fn_has_self_parameter, .. }) =
|
||||
self.infcx.tcx.opt_associated_item(def_id)
|
||||
|
@ -326,7 +326,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
debug!("report: ty={:?}", ty);
|
||||
let mut err = match ty.kind {
|
||||
let mut err = match ty.kind() {
|
||||
ty::Array(..) | ty::Slice(..) => {
|
||||
self.cannot_move_out_of_interior_noncopy(span, ty, None)
|
||||
}
|
||||
@ -385,7 +385,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
};
|
||||
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
|
||||
let def_id = match move_place.ty(self.body, self.infcx.tcx).ty.kind {
|
||||
let def_id = match *move_place.ty(self.body, self.infcx.tcx).ty.kind() {
|
||||
ty::Adt(self_def, _) => self_def.did,
|
||||
ty::Foreign(def_id)
|
||||
| ty::FnDef(def_id, _)
|
||||
|
@ -230,7 +230,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
// Otherwise, check if the name is the self kewyord - in which case
|
||||
// we have an explicit self. Do the same thing in this case and check
|
||||
// for a `self: &mut Self` to suggest removing the `&mut`.
|
||||
if let ty::Ref(_, _, hir::Mutability::Mut) = local_decl.ty.kind {
|
||||
if let ty::Ref(_, _, hir::Mutability::Mut) = local_decl.ty.kind() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
@ -509,7 +509,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
let def_id = hir.local_def_id(item_id);
|
||||
let tables = self.infcx.tcx.typeck(def_id);
|
||||
if let Some(ty::FnDef(def_id, _)) =
|
||||
tables.node_type_opt(func.hir_id).as_ref().map(|ty| &ty.kind)
|
||||
tables.node_type_opt(func.hir_id).as_ref().map(|ty| ty.kind())
|
||||
{
|
||||
let arg = match hir.get_if_local(*def_id) {
|
||||
Some(
|
||||
@ -687,8 +687,8 @@ fn annotate_struct_field(
|
||||
field: &mir::Field,
|
||||
) -> Option<(Span, String)> {
|
||||
// Expect our local to be a reference to a struct of some kind.
|
||||
if let ty::Ref(_, ty, _) = ty.kind {
|
||||
if let ty::Adt(def, _) = ty.kind {
|
||||
if let ty::Ref(_, ty, _) = ty.kind() {
|
||||
if let ty::Adt(def, _) = ty.kind() {
|
||||
let field = def.all_fields().nth(field.index())?;
|
||||
// Use the HIR types to construct the diagnostic message.
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(field.did.as_local()?);
|
||||
|
@ -364,13 +364,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
.struct_span_err(*span, "captured variable cannot escape `FnMut` closure body");
|
||||
|
||||
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
|
||||
if let ty::Opaque(def_id, _) = output_ty.kind {
|
||||
if let ty::Opaque(def_id, _) = *output_ty.kind() {
|
||||
output_ty = self.infcx.tcx.type_of(def_id)
|
||||
};
|
||||
|
||||
debug!("report_fnmut_error: output_ty={:?}", output_ty);
|
||||
|
||||
let message = match output_ty.kind {
|
||||
let message = match output_ty.kind() {
|
||||
ty::Closure(_, _) => {
|
||||
"returns a closure that contains a reference to a captured variable, which then \
|
||||
escapes the closure body"
|
||||
@ -571,13 +571,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
if let (Some(f), Some(ty::RegionKind::ReStatic)) =
|
||||
(self.to_error_region(fr), self.to_error_region(outlived_fr))
|
||||
{
|
||||
if let Some((&ty::TyS { kind: ty::Opaque(did, substs), .. }, _)) = self
|
||||
if let Some(&ty::Opaque(did, substs)) = self
|
||||
.infcx
|
||||
.tcx
|
||||
.is_suitable_region(f)
|
||||
.map(|r| r.def_id)
|
||||
.map(|id| self.infcx.tcx.return_type_impl_trait(id))
|
||||
.unwrap_or(None)
|
||||
.and_then(|id| self.infcx.tcx.return_type_impl_trait(id))
|
||||
.map(|(ty, _)| ty.kind())
|
||||
{
|
||||
// Check whether or not the impl trait return type is intended to capture
|
||||
// data with the static lifetime.
|
||||
|
@ -441,7 +441,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty<'_>)> = &mut vec![(ty, hir_ty)];
|
||||
|
||||
while let Some((ty, hir_ty)) = search_stack.pop() {
|
||||
match (&ty.kind, &hir_ty.kind) {
|
||||
match (&ty.kind(), &hir_ty.kind) {
|
||||
// Check if the `ty` is `&'X ..` where `'X`
|
||||
// is the region we are looking for -- if so, and we have a `&T`
|
||||
// on the RHS, then we want to highlight the `&` like so:
|
||||
|
@ -1758,7 +1758,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
{
|
||||
let place_ty =
|
||||
Place::ty_from(place_span.0.local, base_proj, self.body(), self.infcx.tcx);
|
||||
if let ty::Array(..) = place_ty.ty.kind {
|
||||
if let ty::Array(..) = place_ty.ty.kind() {
|
||||
let array_place = PlaceRef { local: place_span.0.local, projection: base_proj };
|
||||
self.check_if_subslice_element_is_moved(
|
||||
location,
|
||||
@ -1876,7 +1876,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
// be already initialized
|
||||
let tcx = self.infcx.tcx;
|
||||
let base_ty = Place::ty_from(place.local, proj_base, self.body(), tcx).ty;
|
||||
match base_ty.kind {
|
||||
match base_ty.kind() {
|
||||
ty::Adt(def, _) if def.has_dtor(tcx) => {
|
||||
self.check_if_path_or_subpath_is_moved(
|
||||
location, InitializationRequiringAction::Assignment,
|
||||
@ -1979,7 +1979,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
// of the union - we should error in that case.
|
||||
let tcx = this.infcx.tcx;
|
||||
if let ty::Adt(def, _) =
|
||||
Place::ty_from(base.local, base.projection, this.body(), tcx).ty.kind
|
||||
Place::ty_from(base.local, base.projection, this.body(), tcx).ty.kind()
|
||||
{
|
||||
if def.is_union() {
|
||||
if this.move_data.path_map[mpi].iter().any(|moi| {
|
||||
@ -2206,7 +2206,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
Place::ty_from(place.local, proj_base, self.body(), self.infcx.tcx).ty;
|
||||
|
||||
// Check the kind of deref to decide
|
||||
match base_ty.kind {
|
||||
match base_ty.kind() {
|
||||
ty::Ref(_, _, mutbl) => {
|
||||
match mutbl {
|
||||
// Shared borrowed data is never mutable
|
||||
|
@ -49,7 +49,7 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
|
||||
|
||||
if elem == ProjectionElem::Deref {
|
||||
let ty = Place::ty_from(self.local, proj_base, body, tcx).ty;
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Ref(_, _, hir::Mutability::Not) if i == 0 => {
|
||||
// For references to thread-local statics, we do need
|
||||
// to track the borrow.
|
||||
|
@ -210,7 +210,7 @@ fn place_components_conflict<'tcx>(
|
||||
let proj_base = &borrow_place.projection[..access_place.projection.len() + i];
|
||||
let base_ty = Place::ty_from(borrow_local, proj_base, body, tcx).ty;
|
||||
|
||||
match (elem, &base_ty.kind, access) {
|
||||
match (elem, &base_ty.kind(), access) {
|
||||
(_, _, Shallow(Some(ArtificialField::ArrayLength)))
|
||||
| (_, _, Shallow(Some(ArtificialField::ShallowBorrow))) => {
|
||||
// The array length is like additional fields on the
|
||||
@ -330,7 +330,7 @@ fn place_projection_conflict<'tcx>(
|
||||
Overlap::EqualOrDisjoint
|
||||
} else {
|
||||
let ty = Place::ty_from(pi1_local, pi1_proj_base, body, tcx).ty;
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Adt(def, _) if def.is_union() => {
|
||||
// Different fields of a union, we are basically stuck.
|
||||
debug!("place_element_conflict: STUCK-UNION");
|
||||
|
@ -121,7 +121,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
|
||||
// reference.
|
||||
|
||||
let ty = Place::ty_from(cursor.local, proj_base, self.body, self.tcx).ty;
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::RawPtr(_) | ty::Ref(_ /*rgn*/, _ /*ty*/, hir::Mutability::Not) => {
|
||||
// don't continue traversing over derefs of raw pointers or shared
|
||||
// borrows.
|
||||
|
@ -386,7 +386,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
if let ty::FnDef(def_id, substs) = constant.literal.ty.kind {
|
||||
if let ty::FnDef(def_id, substs) = *constant.literal.ty.kind() {
|
||||
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, substs);
|
||||
self.cx.normalize_and_prove_instantiated_predicates(
|
||||
instantiated_predicates,
|
||||
@ -412,7 +412,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
|
||||
// If we have a binding of the form `let ref x: T = ..`
|
||||
// then remove the outermost reference so we can check the
|
||||
// type annotation for the remaining type.
|
||||
if let ty::Ref(_, rty, _) = local_decl.ty.kind {
|
||||
if let ty::Ref(_, rty, _) = local_decl.ty.kind() {
|
||||
rty
|
||||
} else {
|
||||
bug!("{:?} with ref binding has wrong type {}", local, local_decl.ty);
|
||||
@ -646,7 +646,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||
}))
|
||||
}
|
||||
ProjectionElem::Subslice { from, to, from_end } => {
|
||||
PlaceTy::from_ty(match base_ty.kind {
|
||||
PlaceTy::from_ty(match base_ty.kind() {
|
||||
ty::Array(inner, _) => {
|
||||
assert!(!from_end, "array subslices should not use from_end");
|
||||
tcx.mk_array(inner, to - from)
|
||||
@ -658,7 +658,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||
_ => span_mirbug_and_err!(self, place, "slice of non-array {:?}", base_ty),
|
||||
})
|
||||
}
|
||||
ProjectionElem::Downcast(maybe_name, index) => match base_ty.kind {
|
||||
ProjectionElem::Downcast(maybe_name, index) => match base_ty.kind() {
|
||||
ty::Adt(adt_def, _substs) if adt_def.is_enum() => {
|
||||
if index.as_usize() >= adt_def.variants.len() {
|
||||
PlaceTy::from_ty(span_mirbug_and_err!(
|
||||
@ -738,7 +738,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||
let tcx = self.tcx();
|
||||
|
||||
let (variant, substs) = match base_ty {
|
||||
PlaceTy { ty, variant_index: Some(variant_index) } => match ty.kind {
|
||||
PlaceTy { ty, variant_index: Some(variant_index) } => match *ty.kind() {
|
||||
ty::Adt(adt_def, substs) => (&adt_def.variants[variant_index], substs),
|
||||
ty::Generator(def_id, substs, _) => {
|
||||
let mut variants = substs.as_generator().state_tys(def_id, tcx);
|
||||
@ -757,7 +757,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||
}
|
||||
_ => bug!("can't have downcast of non-adt non-generator type"),
|
||||
},
|
||||
PlaceTy { ty, variant_index: None } => match ty.kind {
|
||||
PlaceTy { ty, variant_index: None } => match *ty.kind() {
|
||||
ty::Adt(adt_def, substs) if !adt_def.is_enum() => {
|
||||
(&adt_def.variants[VariantIdx::new(0)], substs)
|
||||
}
|
||||
@ -1140,7 +1140,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
category: ConstraintCategory,
|
||||
) -> Fallible<()> {
|
||||
if let Err(terr) = self.sub_types(sub, sup, locations, category) {
|
||||
if let ty::Opaque(..) = sup.kind {
|
||||
if let ty::Opaque(..) = sup.kind() {
|
||||
// When you have `let x: impl Foo = ...` in a closure,
|
||||
// the resulting inferend values are stored with the
|
||||
// def-id of the base function.
|
||||
@ -1283,8 +1283,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
|
||||
for (&opaque_def_id, opaque_decl) in &opaque_type_map {
|
||||
let resolved_ty = infcx.resolve_vars_if_possible(&opaque_decl.concrete_ty);
|
||||
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind {
|
||||
def_id == opaque_def_id
|
||||
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
|
||||
*def_id == opaque_def_id
|
||||
} else {
|
||||
false
|
||||
};
|
||||
@ -1486,7 +1486,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
StatementKind::SetDiscriminant { ref place, variant_index } => {
|
||||
let place_type = place.ty(body, tcx).ty;
|
||||
let adt = match place_type.kind {
|
||||
let adt = match place_type.kind() {
|
||||
ty::Adt(adt, _) if adt.is_enum() => adt,
|
||||
_ => {
|
||||
span_bug!(
|
||||
@ -1602,7 +1602,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
TerminatorKind::Call { ref func, ref args, ref destination, from_hir_call, .. } => {
|
||||
let func_ty = func.ty(body, tcx);
|
||||
debug!("check_terminator: call, func_ty={:?}", func_ty);
|
||||
let sig = match func_ty.kind {
|
||||
let sig = match func_ty.kind() {
|
||||
ty::FnDef(..) | ty::FnPtr(_) => func_ty.fn_sig(tcx),
|
||||
_ => {
|
||||
span_mirbug!(self, term, "call to non-function {:?}", func_ty);
|
||||
@ -2093,7 +2093,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
|
||||
CastKind::Pointer(PointerCast::ClosureFnPointer(unsafety)) => {
|
||||
let sig = match op.ty(body, tcx).kind {
|
||||
let sig = match op.ty(body, tcx).kind() {
|
||||
ty::Closure(_, substs) => substs.as_closure().sig(),
|
||||
_ => bug!(),
|
||||
};
|
||||
@ -2161,7 +2161,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
|
||||
CastKind::Pointer(PointerCast::MutToConstPointer) => {
|
||||
let ty_from = match op.ty(body, tcx).kind {
|
||||
let ty_from = match op.ty(body, tcx).kind() {
|
||||
ty::RawPtr(ty::TypeAndMut {
|
||||
ty: ty_from,
|
||||
mutbl: hir::Mutability::Mut,
|
||||
@ -2176,7 +2176,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
return;
|
||||
}
|
||||
};
|
||||
let ty_to = match ty.kind {
|
||||
let ty_to = match ty.kind() {
|
||||
ty::RawPtr(ty::TypeAndMut {
|
||||
ty: ty_to,
|
||||
mutbl: hir::Mutability::Not,
|
||||
@ -2211,11 +2211,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
CastKind::Pointer(PointerCast::ArrayToPointer) => {
|
||||
let ty_from = op.ty(body, tcx);
|
||||
|
||||
let opt_ty_elem = match ty_from.kind {
|
||||
let opt_ty_elem = match ty_from.kind() {
|
||||
ty::RawPtr(ty::TypeAndMut {
|
||||
mutbl: hir::Mutability::Not,
|
||||
ty: array_ty,
|
||||
}) => match array_ty.kind {
|
||||
}) => match array_ty.kind() {
|
||||
ty::Array(ty_elem, _) => Some(ty_elem),
|
||||
_ => None,
|
||||
},
|
||||
@ -2235,7 +2235,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
};
|
||||
|
||||
let ty_to = match ty.kind {
|
||||
let ty_to = match ty.kind() {
|
||||
ty::RawPtr(ty::TypeAndMut {
|
||||
mutbl: hir::Mutability::Not,
|
||||
ty: ty_to,
|
||||
@ -2301,7 +2301,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
right,
|
||||
) => {
|
||||
let ty_left = left.ty(body, tcx);
|
||||
match ty_left.kind {
|
||||
match ty_left.kind() {
|
||||
// Types with regions are comparable if they have a common super-type.
|
||||
ty::RawPtr(_) | ty::FnPtr(_) => {
|
||||
let ty_right = right.ty(body, tcx);
|
||||
@ -2512,7 +2512,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
let base_ty = Place::ty_from(borrowed_place.local, proj_base, body, tcx).ty;
|
||||
|
||||
debug!("add_reborrow_constraint - base_ty = {:?}", base_ty);
|
||||
match base_ty.kind {
|
||||
match base_ty.kind() {
|
||||
ty::Ref(ref_region, _, mutbl) => {
|
||||
constraints.outlives_constraints.push(OutlivesConstraint {
|
||||
sup: ref_region.to_region_vid(),
|
||||
|
@ -524,7 +524,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
let defining_ty =
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, &defining_ty);
|
||||
|
||||
match defining_ty.kind {
|
||||
match *defining_ty.kind() {
|
||||
ty::Closure(def_id, substs) => DefiningTy::Closure(def_id, substs),
|
||||
ty::Generator(def_id, substs, movability) => {
|
||||
DefiningTy::Generator(def_id, substs, movability)
|
||||
@ -603,7 +603,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
// flattens this tuple.
|
||||
let (&output, tuplized_inputs) = inputs_and_output.split_last().unwrap();
|
||||
assert_eq!(tuplized_inputs.len(), 1, "multiple closure inputs");
|
||||
let inputs = match tuplized_inputs[0].kind {
|
||||
let inputs = match tuplized_inputs[0].kind() {
|
||||
ty::Tuple(inputs) => inputs,
|
||||
_ => bug!("closure inputs not a tuple: {:?}", tuplized_inputs[0]),
|
||||
};
|
||||
|
@ -117,8 +117,8 @@ pub(super) fn op_to_const<'tcx>(
|
||||
// `Undef` situation.
|
||||
let try_as_immediate = match op.layout.abi {
|
||||
Abi::Scalar(..) => true,
|
||||
Abi::ScalarPair(..) => match op.layout.ty.kind {
|
||||
ty::Ref(_, inner, _) => match inner.kind {
|
||||
Abi::ScalarPair(..) => match op.layout.ty.kind() {
|
||||
ty::Ref(_, inner, _) => match *inner.kind() {
|
||||
ty::Slice(elem) => elem == ecx.tcx.types.u8,
|
||||
ty::Str => true,
|
||||
_ => false,
|
||||
@ -250,7 +250,7 @@ pub fn const_eval_validated_provider<'tcx>(
|
||||
// Catch such calls and evaluate them instead of trying to load a constant's MIR.
|
||||
if let ty::InstanceDef::Intrinsic(def_id) = key.value.instance.def {
|
||||
let ty = key.value.instance.ty(tcx, key.param_env);
|
||||
let substs = match ty.kind {
|
||||
let substs = match ty.kind() {
|
||||
ty::FnDef(_, substs) => substs,
|
||||
_ => bug!("intrinsic with type {:?}", ty),
|
||||
};
|
||||
|
@ -44,7 +44,7 @@ pub(crate) fn destructure_const<'tcx>(
|
||||
let op = ecx.const_to_op(val, None).unwrap();
|
||||
|
||||
// We go to `usize` as we cannot allocate anything bigger anyway.
|
||||
let (field_count, variant, down) = match val.ty.kind {
|
||||
let (field_count, variant, down) = match val.ty.kind() {
|
||||
ty::Array(_, len) => (usize::try_from(len.eval_usize(tcx, param_env)).unwrap(), None, op),
|
||||
ty::Adt(def, _) if def.variants.is_empty() => {
|
||||
return mir::DestructuredConst { variant: None, fields: tcx.arena.alloc_slice(&[]) };
|
||||
|
@ -53,7 +53,7 @@ fn place_contents_drop_state_cannot_differ<'tcx>(
|
||||
place: mir::Place<'tcx>,
|
||||
) -> bool {
|
||||
let ty = place.ty(body, tcx).ty;
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Array(..) => {
|
||||
debug!(
|
||||
"place_contents_drop_state_cannot_differ place: {:?} ty: {:?} => false",
|
||||
|
@ -559,7 +559,7 @@ fn switch_on_enum_discriminant(
|
||||
Some(mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(discriminated))))
|
||||
if *lhs == switch_on =>
|
||||
{
|
||||
match &discriminated.ty(body, tcx).ty.kind {
|
||||
match &discriminated.ty(body, tcx).ty.kind() {
|
||||
ty::Adt(def, _) => Some((*discriminated, def)),
|
||||
|
||||
// `Rvalue::Discriminant` is also used to get the active yield point for a
|
||||
|
@ -110,7 +110,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
||||
let body = self.builder.body;
|
||||
let tcx = self.builder.tcx;
|
||||
let place_ty = Place::ty_from(place.local, proj_base, body, tcx).ty;
|
||||
match place_ty.kind {
|
||||
match place_ty.kind() {
|
||||
ty::Ref(..) | ty::RawPtr(..) => {
|
||||
let proj = &place.projection[..i + 1];
|
||||
return Err(MoveError::cannot_move_out_of(
|
||||
@ -480,7 +480,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
||||
}
|
||||
};
|
||||
let base_ty = base_place.ty(self.builder.body, self.builder.tcx).ty;
|
||||
let len: u64 = match base_ty.kind {
|
||||
let len: u64 = match base_ty.kind() {
|
||||
ty::Array(_, size) => {
|
||||
let length = size.eval_usize(self.builder.tcx, self.builder.param_env);
|
||||
length
|
||||
@ -525,7 +525,9 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
||||
// of the union so it is marked as initialized again.
|
||||
if let [proj_base @ .., ProjectionElem::Field(_, _)] = place.projection {
|
||||
if let ty::Adt(def, _) =
|
||||
Place::ty_from(place.local, proj_base, self.builder.body, self.builder.tcx).ty.kind
|
||||
Place::ty_from(place.local, proj_base, self.builder.body, self.builder.tcx)
|
||||
.ty
|
||||
.kind()
|
||||
{
|
||||
if def.is_union() {
|
||||
place = PlaceRef { local: place.local, projection: proj_base }
|
||||
|
@ -47,7 +47,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
|
||||
Pointer(PointerCast::ReifyFnPointer) => {
|
||||
// The src operand does not matter, just its type
|
||||
match src.layout.ty.kind {
|
||||
match *src.layout.ty.kind() {
|
||||
ty::FnDef(def_id, substs) => {
|
||||
// All reifications must be monomorphic, bail out otherwise.
|
||||
ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
|
||||
@ -76,7 +76,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
|
||||
Pointer(PointerCast::UnsafeFnPointer) => {
|
||||
let src = self.read_immediate(src)?;
|
||||
match cast_ty.kind {
|
||||
match cast_ty.kind() {
|
||||
ty::FnPtr(_) => {
|
||||
// No change to value
|
||||
self.write_immediate(*src, dest)?;
|
||||
@ -87,7 +87,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
|
||||
Pointer(PointerCast::ClosureFnPointer(_)) => {
|
||||
// The src operand does not matter, just its type
|
||||
match src.layout.ty.kind {
|
||||
match *src.layout.ty.kind() {
|
||||
ty::Closure(def_id, substs) => {
|
||||
// All reifications must be monomorphic, bail out otherwise.
|
||||
ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
|
||||
@ -116,7 +116,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
use rustc_middle::ty::TyKind::*;
|
||||
trace!("Casting {:?}: {:?} to {:?}", *src, src.layout.ty, cast_ty);
|
||||
|
||||
match src.layout.ty.kind {
|
||||
match src.layout.ty.kind() {
|
||||
// Floating point
|
||||
Float(FloatTy::F32) => {
|
||||
return Ok(self.cast_from_float(src.to_scalar()?.to_f32()?, cast_ty).into());
|
||||
@ -196,9 +196,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let v = if signed { self.sign_extend(v, src_layout) } else { v };
|
||||
trace!("cast_from_scalar: {}, {} -> {}", v, src_layout.ty, cast_ty);
|
||||
use rustc_middle::ty::TyKind::*;
|
||||
match cast_ty.kind {
|
||||
match *cast_ty.kind() {
|
||||
Int(_) | Uint(_) | RawPtr(_) => {
|
||||
let size = match cast_ty.kind {
|
||||
let size = match *cast_ty.kind() {
|
||||
Int(t) => Integer::from_attr(self, attr::IntType::SignedInt(t)).size(),
|
||||
Uint(t) => Integer::from_attr(self, attr::IntType::UnsignedInt(t)).size(),
|
||||
RawPtr(_) => self.pointer_size(),
|
||||
@ -228,7 +228,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
F: Float + Into<Scalar<M::PointerTag>> + FloatConvert<Single> + FloatConvert<Double>,
|
||||
{
|
||||
use rustc_middle::ty::TyKind::*;
|
||||
match dest_ty.kind {
|
||||
match *dest_ty.kind() {
|
||||
// float -> uint
|
||||
Uint(t) => {
|
||||
let size = Integer::from_attr(self, attr::IntType::UnsignedInt(t)).size();
|
||||
@ -267,7 +267,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let (src_pointee_ty, dest_pointee_ty) =
|
||||
self.tcx.struct_lockstep_tails_erasing_lifetimes(source_ty, cast_ty, self.param_env);
|
||||
|
||||
match (&src_pointee_ty.kind, &dest_pointee_ty.kind) {
|
||||
match (&src_pointee_ty.kind(), &dest_pointee_ty.kind()) {
|
||||
(&ty::Array(_, length), &ty::Slice(_)) => {
|
||||
let ptr = self.read_immediate(src)?.to_scalar()?;
|
||||
// u64 cast is from usize to u64, which is always good
|
||||
@ -303,7 +303,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
dest: PlaceTy<'tcx, M::PointerTag>,
|
||||
) -> InterpResult<'tcx> {
|
||||
trace!("Unsizing {:?} of type {} into {:?}", *src, src.layout.ty, cast_ty.ty);
|
||||
match (&src.layout.ty.kind, &cast_ty.ty.kind) {
|
||||
match (&src.layout.ty.kind(), &cast_ty.ty.kind()) {
|
||||
(&ty::Ref(_, s, _), &ty::Ref(_, c, _) | &ty::RawPtr(TypeAndMut { ty: c, .. }))
|
||||
| (&ty::RawPtr(TypeAndMut { ty: s, .. }), &ty::RawPtr(TypeAndMut { ty: c, .. })) => {
|
||||
self.unsize_into_ptr(src, dest, s, c)
|
||||
|
@ -534,7 +534,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
if !layout.is_unsized() {
|
||||
return Ok(Some((layout.size, layout.align.abi)));
|
||||
}
|
||||
match layout.ty.kind {
|
||||
match layout.ty.kind() {
|
||||
ty::Adt(..) | ty::Tuple(..) => {
|
||||
// First get the size of all statically known fields.
|
||||
// Don't use type_of::sizing_type_of because that expects t to be sized,
|
||||
|
@ -195,13 +195,13 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir
|
||||
// Raw pointers (and boxes) are handled by the `leftover_relocations` logic.
|
||||
let tcx = self.ecx.tcx;
|
||||
let ty = mplace.layout.ty;
|
||||
if let ty::Ref(_, referenced_ty, ref_mutability) = ty.kind {
|
||||
if let ty::Ref(_, referenced_ty, ref_mutability) = *ty.kind() {
|
||||
let value = self.ecx.read_immediate(mplace.into())?;
|
||||
let mplace = self.ecx.ref_to_mplace(value)?;
|
||||
assert_eq!(mplace.layout.ty, referenced_ty);
|
||||
// Handle trait object vtables.
|
||||
if let ty::Dynamic(..) =
|
||||
tcx.struct_tail_erasing_lifetimes(referenced_ty, self.ecx.param_env).kind
|
||||
tcx.struct_tail_erasing_lifetimes(referenced_ty, self.ecx.param_env).kind()
|
||||
{
|
||||
// Validation will error (with a better message) on an invalid vtable pointer
|
||||
// so we can safely not do anything if this is not a real pointer.
|
||||
@ -253,7 +253,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir
|
||||
// This helps to prevent users from accidentally exploiting UB that they
|
||||
// caused (by somehow getting a mutable reference in a `const`).
|
||||
if ref_mutability == Mutability::Mut {
|
||||
match referenced_ty.kind {
|
||||
match referenced_ty.kind() {
|
||||
ty::Array(_, n) if n.eval_usize(*tcx, self.ecx.param_env) == 0 => {}
|
||||
ty::Slice(_)
|
||||
if mplace.meta.unwrap_meta().to_machine_usize(self.ecx)?
|
||||
|
@ -76,7 +76,7 @@ crate fn eval_nullary_intrinsic<'tcx>(
|
||||
ConstValue::from_u64(tcx.type_id_hash(tp_ty))
|
||||
}
|
||||
sym::variant_count => {
|
||||
if let ty::Adt(ref adt, _) = tp_ty.kind {
|
||||
if let ty::Adt(ref adt, _) = tp_ty.kind() {
|
||||
ConstValue::from_machine_usize(adt.variants.len() as u64, &tcx)
|
||||
} else {
|
||||
ConstValue::from_machine_usize(0u64, &tcx)
|
||||
|
@ -32,7 +32,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||
}
|
||||
|
||||
fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
// Types without identity.
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
|
@ -662,7 +662,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let discr_val = self.cast_from_scalar(tag_bits, tag_layout, discr_layout.ty);
|
||||
let discr_bits = discr_val.assert_bits(discr_layout.size);
|
||||
// Convert discriminant to variant index, and catch invalid discriminants.
|
||||
let index = match op.layout.ty.kind {
|
||||
let index = match *op.layout.ty.kind() {
|
||||
ty::Adt(adt, _) => {
|
||||
adt.discriminants(*self.tcx).find(|(_, var)| var.val == discr_bits)
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
right.layout.ty
|
||||
);
|
||||
|
||||
match left.layout.ty.kind {
|
||||
match left.layout.ty.kind() {
|
||||
ty::Char => {
|
||||
assert_eq!(left.layout.ty, right.layout.ty);
|
||||
let left = left.to_scalar()?;
|
||||
@ -368,7 +368,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let val = val.to_scalar()?;
|
||||
trace!("Running unary op {:?}: {:?} ({:?})", un_op, val, layout.ty);
|
||||
|
||||
match layout.ty.kind {
|
||||
match layout.ty.kind() {
|
||||
ty::Bool => {
|
||||
let val = val.to_bool()?;
|
||||
let res = match un_op {
|
||||
|
@ -202,7 +202,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
|
||||
pub(super) fn len(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
|
||||
if self.layout.is_unsized() {
|
||||
// We need to consult `meta` metadata
|
||||
match self.layout.ty.kind {
|
||||
match self.layout.ty.kind() {
|
||||
ty::Slice(..) | ty::Str => self.mplace.meta.unwrap_meta().to_machine_usize(cx),
|
||||
_ => bug!("len not supported on unsized type {:?}", self.layout.ty),
|
||||
}
|
||||
@ -218,7 +218,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
|
||||
|
||||
#[inline]
|
||||
pub(super) fn vtable(self) -> Scalar<Tag> {
|
||||
match self.layout.ty.kind {
|
||||
match self.layout.ty.kind() {
|
||||
ty::Dynamic(..) => self.mplace.meta.unwrap_meta(),
|
||||
_ => bug!("vtable not supported on type {:?}", self.layout.ty),
|
||||
}
|
||||
@ -498,7 +498,7 @@ where
|
||||
|
||||
// Compute meta and new layout
|
||||
let inner_len = actual_to.checked_sub(from).unwrap();
|
||||
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
|
||||
// implement this.
|
||||
ty::Array(inner, _) => (MemPlaceMeta::None, self.tcx.mk_array(inner, inner_len)),
|
||||
|
@ -55,7 +55,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let old_stack = self.frame_idx();
|
||||
let old_loc = self.frame().loc;
|
||||
let func = self.eval_operand(func, None)?;
|
||||
let (fn_val, abi) = match func.layout.ty.kind {
|
||||
let (fn_val, abi) = match *func.layout.ty.kind() {
|
||||
ty::FnPtr(sig) => {
|
||||
let caller_abi = sig.abi();
|
||||
let fn_ptr = self.read_scalar(func)?.check_init()?;
|
||||
@ -222,7 +222,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
{
|
||||
let callee_abi = {
|
||||
let instance_ty = instance.ty(*self.tcx, self.param_env);
|
||||
match instance_ty.kind {
|
||||
match instance_ty.kind() {
|
||||
ty::FnDef(..) => instance_ty.fn_sig(*self.tcx).abi(),
|
||||
ty::Closure(..) => Abi::RustCall,
|
||||
ty::Generator(..) => Abi::Rust,
|
||||
@ -431,7 +431,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
// implementation fail -- a problem shared by rustc.
|
||||
let place = self.force_allocation(place)?;
|
||||
|
||||
let (instance, place) = match place.layout.ty.kind {
|
||||
let (instance, place) = match place.layout.ty.kind() {
|
||||
ty::Dynamic(..) => {
|
||||
// Dropping a trait object.
|
||||
self.unpack_dyn_trait(place)?
|
||||
|
@ -33,7 +33,7 @@ where
|
||||
return false;
|
||||
}
|
||||
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Param(_) => true,
|
||||
ty::Closure(def_id, substs)
|
||||
| ty::Generator(def_id, substs, ..)
|
||||
@ -59,7 +59,7 @@ where
|
||||
// `ty::Param`/`ty::ConstKind::Param`.
|
||||
(false, true) if cfg!(debug_assertions) => match subst.unpack() {
|
||||
ty::subst::GenericArgKind::Type(ty) => {
|
||||
assert!(matches!(ty.kind, ty::Param(_)))
|
||||
assert!(matches!(ty.kind(), ty::Param(_)))
|
||||
}
|
||||
ty::subst::GenericArgKind::Const(ct) => {
|
||||
assert!(matches!(ct.val, ty::ConstKind::Param(_)))
|
||||
|
@ -214,7 +214,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||
match layout.variants {
|
||||
Variants::Multiple { tag_field, .. } => {
|
||||
if tag_field == field {
|
||||
return match layout.ty.kind {
|
||||
return match layout.ty.kind() {
|
||||
ty::Adt(def, ..) if def.is_enum() => PathElem::EnumTag,
|
||||
ty::Generator(..) => PathElem::GeneratorTag,
|
||||
_ => bug!("non-variant type {:?}", layout.ty),
|
||||
@ -225,7 +225,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||
}
|
||||
|
||||
// Now we know we are projecting to a field, so figure out which one.
|
||||
match layout.ty.kind {
|
||||
match layout.ty.kind() {
|
||||
// generators and closures.
|
||||
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
|
||||
let mut name = None;
|
||||
@ -303,7 +303,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||
pointee: TyAndLayout<'tcx>,
|
||||
) -> InterpResult<'tcx> {
|
||||
let tail = self.ecx.tcx.struct_tail_erasing_lifetimes(pointee.ty, self.ecx.param_env);
|
||||
match tail.kind {
|
||||
match tail.kind() {
|
||||
ty::Dynamic(..) => {
|
||||
let vtable = meta.unwrap_meta();
|
||||
// Direct call to `check_ptr_access_align` checks alignment even on CTFE machines.
|
||||
@ -477,7 +477,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||
) -> InterpResult<'tcx, bool> {
|
||||
// Go over all the primitive types
|
||||
let ty = value.layout.ty;
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Bool => {
|
||||
let value = self.ecx.read_scalar(value)?;
|
||||
try_validation!(
|
||||
@ -692,7 +692,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
|
||||
variant_id: VariantIdx,
|
||||
new_op: OpTy<'tcx, M::PointerTag>,
|
||||
) -> InterpResult<'tcx> {
|
||||
let name = match old_op.layout.ty.kind {
|
||||
let name = match old_op.layout.ty.kind() {
|
||||
ty::Adt(adt, _) => PathElem::Variant(adt.variants[variant_id].ident.name),
|
||||
// Generators also have variants
|
||||
ty::Generator(..) => PathElem::GeneratorState(variant_id),
|
||||
@ -762,7 +762,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
|
||||
op: OpTy<'tcx, M::PointerTag>,
|
||||
fields: impl Iterator<Item = InterpResult<'tcx, Self::V>>,
|
||||
) -> InterpResult<'tcx> {
|
||||
match op.layout.ty.kind {
|
||||
match op.layout.ty.kind() {
|
||||
ty::Str => {
|
||||
let mplace = op.assert_mem_place(self.ecx); // strings are never immediate
|
||||
let len = mplace.len(self.ecx)?;
|
||||
@ -779,7 +779,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
|
||||
// FIXME(wesleywiser) This logic could be extended further to arbitrary structs
|
||||
// or tuples made up of integer/floating point types or inhabited ZSTs with no
|
||||
// padding.
|
||||
match tys.kind {
|
||||
match tys.kind() {
|
||||
ty::Int(..) | ty::Uint(..) | ty::Float(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ macro_rules! make_value_visitor {
|
||||
trace!("walk_value: type: {}", v.layout().ty);
|
||||
|
||||
// Special treatment for special types, where the (static) layout is not sufficient.
|
||||
match v.layout().ty.kind {
|
||||
match *v.layout().ty.kind() {
|
||||
// If it is a trait object, switch to the real type that was used to create it.
|
||||
ty::Dynamic(..) => {
|
||||
// immediate trait objects are not a thing
|
||||
|
@ -575,7 +575,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
||||
) => {
|
||||
let source_ty = operand.ty(self.body, self.tcx);
|
||||
let source_ty = self.monomorphize(source_ty);
|
||||
match source_ty.kind {
|
||||
match *source_ty.kind() {
|
||||
ty::Closure(def_id, substs) => {
|
||||
let instance = Instance::resolve_closure(
|
||||
self.tcx,
|
||||
@ -716,7 +716,7 @@ fn visit_fn_use<'tcx>(
|
||||
source: Span,
|
||||
output: &mut Vec<Spanned<MonoItem<'tcx>>>,
|
||||
) {
|
||||
if let ty::FnDef(def_id, substs) = ty.kind {
|
||||
if let ty::FnDef(def_id, substs) = *ty.kind() {
|
||||
let instance = if is_direct_call {
|
||||
ty::Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap().unwrap()
|
||||
} else {
|
||||
@ -853,7 +853,7 @@ fn find_vtable_types_for_unsizing<'tcx>(
|
||||
return false;
|
||||
}
|
||||
let tail = tcx.struct_tail_erasing_lifetimes(ty, param_env);
|
||||
match tail.kind {
|
||||
match tail.kind() {
|
||||
ty::Foreign(..) => false,
|
||||
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
|
||||
_ => bug!("unexpected unsized tail: {:?}", tail),
|
||||
@ -866,7 +866,7 @@ fn find_vtable_types_for_unsizing<'tcx>(
|
||||
}
|
||||
};
|
||||
|
||||
match (&source_ty.kind, &target_ty.kind) {
|
||||
match (&source_ty.kind(), &target_ty.kind()) {
|
||||
(&ty::Ref(_, a, _), &ty::Ref(_, b, _) | &ty::RawPtr(ty::TypeAndMut { ty: b, .. }))
|
||||
| (&ty::RawPtr(ty::TypeAndMut { ty: a, .. }), &ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
|
||||
ptr_vtable(a, b)
|
||||
@ -922,7 +922,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
|
||||
) {
|
||||
assert!(!trait_ty.has_escaping_bound_vars() && !impl_ty.has_escaping_bound_vars());
|
||||
|
||||
if let ty::Dynamic(ref trait_ty, ..) = trait_ty.kind {
|
||||
if let ty::Dynamic(ref trait_ty, ..) = trait_ty.kind() {
|
||||
if let Some(principal) = trait_ty.principal() {
|
||||
let poly_trait_ref = principal.with_self_ty(tcx, impl_ty);
|
||||
assert!(!poly_trait_ref.has_escaping_bound_vars());
|
||||
|
@ -288,7 +288,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
||||
return false;
|
||||
}
|
||||
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Closure(def_id, substs) | ty::Generator(def_id, substs, ..) => {
|
||||
debug!("visit_ty: def_id={:?}", def_id);
|
||||
// Avoid cycle errors with generators.
|
||||
@ -337,7 +337,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> {
|
||||
return false;
|
||||
}
|
||||
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Param(param) => !self.unused_parameters.contains(param.index).unwrap_or(false),
|
||||
_ => ty.super_visit_with(self),
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
|
||||
debug!("build_drop_shim(def_id={:?}, ty={:?})", def_id, ty);
|
||||
|
||||
// Check if this is a generator, if so, return the drop glue for it
|
||||
if let Some(&ty::TyS { kind: ty::Generator(gen_def_id, substs, _), .. }) = ty {
|
||||
if let Some(&ty::Generator(gen_def_id, substs, _)) = ty.map(|ty| ty.kind()) {
|
||||
let body = &**tcx.optimized_mir(gen_def_id).generator_drop.as_ref().unwrap();
|
||||
return body.subst(tcx, substs);
|
||||
}
|
||||
@ -312,7 +312,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
|
||||
let dest = Place::return_place();
|
||||
let src = tcx.mk_place_deref(Place::from(Local::new(1 + 0)));
|
||||
|
||||
match self_ty.kind {
|
||||
match self_ty.kind() {
|
||||
_ if is_copy => builder.copy_shim(),
|
||||
ty::Array(ty, len) => {
|
||||
let len = len.eval_usize(tcx, param_env);
|
||||
@ -853,7 +853,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
|
||||
let sig = tcx.fn_sig(ctor_id).no_bound_vars().expect("LBR in ADT constructor signature");
|
||||
let sig = tcx.normalize_erasing_regions(param_env, sig);
|
||||
|
||||
let (adt_def, substs) = match sig.output().kind {
|
||||
let (adt_def, substs) = match sig.output().kind() {
|
||||
ty::Adt(adt_def, substs) => (adt_def, substs),
|
||||
_ => bug!("unexpected type for ADT ctor {:?}", sig.output()),
|
||||
};
|
||||
|
@ -35,7 +35,7 @@ fn is_stable(place: PlaceRef<'_>) -> bool {
|
||||
|
||||
/// Determine whether this type may be a reference (or box), and thus needs retagging.
|
||||
fn may_be_reference(ty: Ty<'tcx>) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
// Primitive types that are not references
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
|
@ -170,7 +170,7 @@ where
|
||||
// Special-case reborrows to be more like a copy of the reference.
|
||||
if let &[ref proj_base @ .., ProjectionElem::Deref] = place.projection.as_ref() {
|
||||
let base_ty = Place::ty_from(place.local, proj_base, cx.body, cx.tcx).ty;
|
||||
if let ty::Ref(..) = base_ty.kind {
|
||||
if let ty::Ref(..) = base_ty.kind() {
|
||||
return in_place::<Q, _>(
|
||||
cx,
|
||||
in_local,
|
||||
|
@ -321,7 +321,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
|
||||
Rvalue::Ref(_, kind @ BorrowKind::Mut { .. }, ref place)
|
||||
| Rvalue::Ref(_, kind @ BorrowKind::Unique, ref place) => {
|
||||
let ty = place.ty(self.body, self.tcx).ty;
|
||||
let is_allowed = match ty.kind {
|
||||
let is_allowed = match ty.kind() {
|
||||
// Inside a `static mut`, `&mut [...]` is allowed.
|
||||
ty::Array(..) | ty::Slice(_)
|
||||
if self.const_kind() == hir::ConstContext::Static(hir::Mutability::Mut) =>
|
||||
@ -374,7 +374,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
|
||||
}
|
||||
|
||||
Rvalue::BinaryOp(op, ref lhs, _) => {
|
||||
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.body, self.tcx).kind {
|
||||
if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.body, self.tcx).kind() {
|
||||
assert!(
|
||||
op == BinOp::Eq
|
||||
|| op == BinOp::Ne
|
||||
@ -426,7 +426,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
|
||||
match elem {
|
||||
ProjectionElem::Deref => {
|
||||
let base_ty = Place::ty_from(place_local, proj_base, self.body, self.tcx).ty;
|
||||
if let ty::RawPtr(_) = base_ty.kind {
|
||||
if let ty::RawPtr(_) = base_ty.kind() {
|
||||
if proj_base.is_empty() {
|
||||
if let (local, []) = (place_local, proj_base) {
|
||||
let decl = &self.body.local_decls[local];
|
||||
@ -498,7 +498,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
|
||||
TerminatorKind::Call { func, .. } => {
|
||||
let fn_ty = func.ty(self.body, self.tcx);
|
||||
|
||||
let (def_id, substs) = match fn_ty.kind {
|
||||
let (def_id, substs) = match *fn_ty.kind() {
|
||||
ty::FnDef(def_id, substs) => (def_id, substs),
|
||||
|
||||
ty::FnPtr(_) => {
|
||||
@ -647,7 +647,7 @@ fn place_as_reborrow(
|
||||
// This is sufficient to prevent an access to a `static mut` from being marked as a
|
||||
// reborrow, even if the check above were to disappear.
|
||||
let inner_ty = Place::ty_from(place.local, inner, body, tcx).ty;
|
||||
match inner_ty.kind {
|
||||
match inner_ty.kind() {
|
||||
ty::Ref(..) => Some(inner),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -91,8 +91,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
|
||||
)
|
||||
}
|
||||
|
||||
if let ty::FnDef(func_id, _) = func_ty.kind {
|
||||
self.check_target_features(func_id);
|
||||
if let ty::FnDef(func_id, _) = func_ty.kind() {
|
||||
self.check_target_features(*func_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
let base_ty = Place::ty_from(place.local, proj_base, self.body, self.tcx).ty;
|
||||
match base_ty.kind {
|
||||
match base_ty.kind() {
|
||||
ty::RawPtr(..) => self.require_unsafe(
|
||||
UnsafetyViolationKind::GeneralAndConstFn,
|
||||
UnsafetyViolationDetails::DerefOfRawPointer,
|
||||
@ -394,7 +394,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
|
||||
ProjectionElem::Field(..) => {
|
||||
let ty =
|
||||
Place::ty_from(place.local, proj_base, &self.body.local_decls, self.tcx).ty;
|
||||
if let ty::Adt(def, _) = ty.kind {
|
||||
if let ty::Adt(def, _) = ty.kind() {
|
||||
if self.tcx.layout_scalar_valid_range(def.did)
|
||||
!= (Bound::Unbounded, Bound::Unbounded)
|
||||
{
|
||||
|
@ -832,7 +832,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||
// FIXME: enable the general case stated above ^.
|
||||
let ty = &value.layout.ty;
|
||||
// Only do it for tuples
|
||||
if let ty::Tuple(substs) = ty.kind {
|
||||
if let ty::Tuple(substs) = ty.kind() {
|
||||
// Only do it if tuple is also a pair with two scalars
|
||||
if substs.len() == 2 {
|
||||
let alloc = self.use_ecx(|this| {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user