Change ty.kind to a method
This commit is contained in:
parent
ef55a0a92f
commit
3e14b684dd
189 changed files with 947 additions and 899 deletions
|
@ -367,7 +367,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let tcx = self.hir.tcx();
|
||||
let place_ty =
|
||||
Place::ty_from(base_place.local, &base_place.projection, &self.local_decls, tcx);
|
||||
if let ty::Slice(_) = place_ty.ty.kind {
|
||||
if let ty::Slice(_) = place_ty.ty.kind() {
|
||||
// We need to create fake borrows to ensure that the bounds
|
||||
// check that we just did stays valid. Since we can't assign to
|
||||
// unsized values, we only need to ensure that none of the
|
||||
|
@ -406,7 +406,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
&self.local_decls,
|
||||
tcx,
|
||||
);
|
||||
match index_ty.ty.kind {
|
||||
match index_ty.ty.kind() {
|
||||
// The previous index expression has already
|
||||
// done any index expressions needed here.
|
||||
ty::Slice(_) => break,
|
||||
|
|
|
@ -168,7 +168,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
exit_block.unit()
|
||||
}
|
||||
ExprKind::Call { ty, fun, args, from_hir_call, fn_span } => {
|
||||
let intrinsic = match ty.kind {
|
||||
let intrinsic = match *ty.kind() {
|
||||
ty::FnDef(def_id, _) => {
|
||||
let f = ty.fn_sig(this.hir.tcx());
|
||||
if f.abi() == Abi::RustIntrinsic || f.abi() == Abi::PlatformIntrinsic {
|
||||
|
|
|
@ -154,7 +154,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
|
||||
PatKind::Range(PatRange { lo, hi, end }) => {
|
||||
let (range, bias) = match lo.ty.kind {
|
||||
let (range, bias) = match *lo.ty.kind() {
|
||||
ty::Char => {
|
||||
(Some(('\u{0000}' as u128, '\u{10FFFF}' as u128, Size::from_bits(32))), 0)
|
||||
}
|
||||
|
|
|
@ -215,7 +215,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
|
||||
TestKind::SwitchInt { switch_ty, ref options } => {
|
||||
let target_blocks = make_target_blocks(self);
|
||||
let terminator = if switch_ty.kind == ty::Bool {
|
||||
let terminator = if *switch_ty.kind() == ty::Bool {
|
||||
assert!(!options.is_empty() && options.len() <= 2);
|
||||
if let [first_bb, second_bb] = *target_blocks {
|
||||
let (true_bb, false_bb) = match options[0] {
|
||||
|
@ -368,8 +368,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
// We want to do this even when the scrutinee is a reference to an
|
||||
// array, so we can call `<[u8]>::eq` rather than having to find an
|
||||
// `<[u8; N]>::eq`.
|
||||
let unsize = |ty: Ty<'tcx>| match ty.kind {
|
||||
ty::Ref(region, rty, _) => match rty.kind {
|
||||
let unsize = |ty: Ty<'tcx>| match ty.kind() {
|
||||
ty::Ref(region, rty, _) => match rty.kind() {
|
||||
ty::Array(inner_ty, n) => Some((region, inner_ty, n)),
|
||||
_ => None,
|
||||
},
|
||||
|
@ -407,7 +407,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
let deref_ty = match ty.kind {
|
||||
let deref_ty = match *ty.kind() {
|
||||
ty::Ref(_, deref_ty, _) => deref_ty,
|
||||
_ => bug!("non_scalar_compare called on non-reference type: {}", ty),
|
||||
};
|
||||
|
|
|
@ -31,7 +31,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
suffix: &'pat [Pat<'tcx>],
|
||||
) {
|
||||
let tcx = self.hir.tcx();
|
||||
let (min_length, exact_size) = match place.ty(&self.local_decls, tcx).ty.kind {
|
||||
let (min_length, exact_size) = match place.ty(&self.local_decls, tcx).ty.kind() {
|
||||
ty::Array(_, length) => {
|
||||
(length.eval_usize(tcx, self.hir.param_env).try_into().unwrap(), true)
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
|
|||
let body = tcx.hir().body(body_id);
|
||||
let ty = tcx.type_of(fn_def_id);
|
||||
let mut abi = fn_sig.abi;
|
||||
let implicit_argument = match ty.kind {
|
||||
let implicit_argument = match ty.kind() {
|
||||
ty::Closure(..) => {
|
||||
// HACK(eddyb) Avoid having RustCall on closures,
|
||||
// as it adds unnecessary (and wrong) auto-tupling.
|
||||
|
@ -159,7 +159,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
|
|||
|
||||
let (yield_ty, return_ty) = if body.generator_kind.is_some() {
|
||||
let gen_ty = tcx.typeck_body(body_id).node_type(id);
|
||||
let gen_sig = match gen_ty.kind {
|
||||
let gen_sig = match gen_ty.kind() {
|
||||
ty::Generator(_, gen_substs, ..) => gen_substs.as_generator().sig(),
|
||||
_ => span_bug!(tcx.hir().span(id), "generator w/o generator type: {:?}", ty),
|
||||
};
|
||||
|
@ -228,7 +228,7 @@ fn liberated_closure_env_ty(
|
|||
) -> Ty<'_> {
|
||||
let closure_ty = tcx.typeck_body(body_id).node_type(closure_expr_id);
|
||||
|
||||
let (closure_def_id, closure_substs) = match closure_ty.kind {
|
||||
let (closure_def_id, closure_substs) = match *closure_ty.kind() {
|
||||
ty::Closure(closure_def_id, closure_substs) => (closure_def_id, closure_substs),
|
||||
_ => bug!("closure expr does not have closure type: {:?}", closure_ty),
|
||||
};
|
||||
|
@ -840,11 +840,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let closure_env_arg = Local::new(1);
|
||||
let mut closure_env_projs = vec![];
|
||||
let mut closure_ty = self.local_decls[closure_env_arg].ty;
|
||||
if let ty::Ref(_, ty, _) = closure_ty.kind {
|
||||
if let ty::Ref(_, ty, _) = closure_ty.kind() {
|
||||
closure_env_projs.push(ProjectionElem::Deref);
|
||||
closure_ty = ty;
|
||||
}
|
||||
let upvar_substs = match closure_ty.kind {
|
||||
let upvar_substs = match closure_ty.kind() {
|
||||
ty::Closure(_, substs) => ty::UpvarSubsts::Closure(substs),
|
||||
ty::Generator(_, substs, _) => ty::UpvarSubsts::Generator(substs),
|
||||
_ => span_bug!(self.fn_span, "upvars with non-closure env ty {:?}", closure_ty),
|
||||
|
|
|
@ -70,7 +70,7 @@ impl<'mir, 'tcx> Search<'mir, 'tcx> {
|
|||
let param_env = tcx.param_env(def_id);
|
||||
|
||||
let func_ty = func.ty(body, tcx);
|
||||
if let ty::FnDef(fn_def_id, substs) = func_ty.kind {
|
||||
if let ty::FnDef(fn_def_id, substs) = *func_ty.kind() {
|
||||
let (call_fn_id, call_substs) =
|
||||
if let Ok(Some(instance)) = Instance::resolve(tcx, param_env, fn_def_id, substs) {
|
||||
(instance.def_id(), instance.substs)
|
||||
|
|
|
@ -2,7 +2,7 @@ use rustc_ast as ast;
|
|||
use rustc_middle::mir::interpret::{
|
||||
truncate, Allocation, ConstValue, LitToConstError, LitToConstInput, Scalar,
|
||||
};
|
||||
use rustc_middle::ty::{self, ParamEnv, TyCtxt, TyS};
|
||||
use rustc_middle::ty::{self, ParamEnv, TyCtxt};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_target::abi::Size;
|
||||
|
||||
|
@ -21,19 +21,21 @@ crate fn lit_to_const<'tcx>(
|
|||
Ok(ConstValue::Scalar(Scalar::from_uint(result, width)))
|
||||
};
|
||||
|
||||
let lit = match (lit, &ty.kind) {
|
||||
(ast::LitKind::Str(s, _), ty::Ref(_, TyS { kind: ty::Str, .. }, _)) => {
|
||||
let lit = match (lit, &ty.kind()) {
|
||||
(ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() => {
|
||||
let s = s.as_str();
|
||||
let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes());
|
||||
let allocation = tcx.intern_const_alloc(allocation);
|
||||
ConstValue::Slice { data: allocation, start: 0, end: s.len() }
|
||||
}
|
||||
(ast::LitKind::ByteStr(data), ty::Ref(_, TyS { kind: ty::Slice(_), .. }, _)) => {
|
||||
(ast::LitKind::ByteStr(data), ty::Ref(_, inner_ty, _))
|
||||
if matches!(inner_ty.kind(), ty::Slice(_)) =>
|
||||
{
|
||||
let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>);
|
||||
let allocation = tcx.intern_const_alloc(allocation);
|
||||
ConstValue::Slice { data: allocation, start: 0, end: data.len() }
|
||||
}
|
||||
(ast::LitKind::ByteStr(data), ty::Ref(_, TyS { kind: ty::Array(_, _), .. }, _)) => {
|
||||
(ast::LitKind::ByteStr(data), ty::Ref(_, inner_ty, _)) if inner_ty.is_array() => {
|
||||
let id = tcx.allocate_bytes(data);
|
||||
ConstValue::Scalar(Scalar::Ptr(id.into()))
|
||||
}
|
||||
|
|
|
@ -313,7 +313,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
hir::ExprKind::Struct(ref qpath, ref fields, ref base) => match expr_ty.kind {
|
||||
hir::ExprKind::Struct(ref qpath, ref fields, ref base) => match expr_ty.kind() {
|
||||
ty::Adt(adt, substs) => match adt.adt_kind() {
|
||||
AdtKind::Struct | AdtKind::Union => {
|
||||
let user_provided_types = cx.typeck_results().user_provided_types();
|
||||
|
@ -363,7 +363,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
|
|||
|
||||
hir::ExprKind::Closure(..) => {
|
||||
let closure_ty = cx.typeck_results().expr_ty(expr);
|
||||
let (def_id, substs, movability) = match closure_ty.kind {
|
||||
let (def_id, substs, movability) = match *closure_ty.kind() {
|
||||
ty::Closure(def_id, substs) => (def_id, UpvarSubsts::Closure(substs), None),
|
||||
ty::Generator(def_id, substs, movability) => {
|
||||
(def_id, UpvarSubsts::Generator(substs), Some(movability))
|
||||
|
@ -818,7 +818,7 @@ fn convert_path_expr<'a, 'tcx>(
|
|||
let user_provided_type = user_provided_types.get(expr.hir_id).copied();
|
||||
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);
|
||||
let ty = cx.typeck_results().node_type(expr.hir_id);
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
// A unit struct/variant which is used as a value.
|
||||
// We return a completely different ExprKind here to account for this special case.
|
||||
ty::Adt(adt_def, substs) => ExprKind::Adt {
|
||||
|
@ -899,7 +899,7 @@ fn convert_var<'tcx>(
|
|||
});
|
||||
let region = cx.tcx.mk_region(region);
|
||||
|
||||
let self_expr = if let ty::Closure(_, closure_substs) = closure_ty.kind {
|
||||
let self_expr = if let ty::Closure(_, closure_substs) = closure_ty.kind() {
|
||||
match cx.infcx.closure_kind(closure_substs).unwrap() {
|
||||
ty::ClosureKind::Fn => {
|
||||
let ref_closure_ty = cx.tcx.mk_ref(
|
||||
|
@ -1027,7 +1027,7 @@ fn overloaded_place<'a, 'tcx>(
|
|||
// Reconstruct the output assuming it's a reference with the
|
||||
// same region and mutability as the receiver. This holds for
|
||||
// `Deref(Mut)::Deref(_mut)` and `Index(Mut)::index(_mut)`.
|
||||
let (region, mutbl) = match recv_ty.kind {
|
||||
let (region, mutbl) = match *recv_ty.kind() {
|
||||
ty::Ref(region, _, mutbl) => (region, mutbl),
|
||||
_ => span_bug!(expr.span, "overloaded_place: receiver is not a reference"),
|
||||
};
|
||||
|
|
|
@ -327,7 +327,7 @@ impl<'tcx> LiteralExpander<'tcx> {
|
|||
crty: Ty<'tcx>,
|
||||
) -> ConstValue<'tcx> {
|
||||
debug!("fold_const_value_deref {:?} {:?} {:?}", val, rty, crty);
|
||||
match (val, &crty.kind, &rty.kind) {
|
||||
match (val, &crty.kind(), &rty.kind()) {
|
||||
// the easy case, deref a reference
|
||||
(ConstValue::Scalar(p), x, y) if x == y => {
|
||||
match p {
|
||||
|
@ -368,41 +368,35 @@ impl<'tcx> LiteralExpander<'tcx> {
|
|||
|
||||
impl<'tcx> PatternFolder<'tcx> for LiteralExpander<'tcx> {
|
||||
fn fold_pattern(&mut self, pat: &Pat<'tcx>) -> Pat<'tcx> {
|
||||
debug!("fold_pattern {:?} {:?} {:?}", pat, pat.ty.kind, pat.kind);
|
||||
match (&pat.ty.kind, &*pat.kind) {
|
||||
(
|
||||
&ty::Ref(_, rty, _),
|
||||
&PatKind::Constant {
|
||||
value:
|
||||
Const {
|
||||
val: ty::ConstKind::Value(val),
|
||||
ty: ty::TyS { kind: ty::Ref(_, crty, _), .. },
|
||||
},
|
||||
},
|
||||
) => Pat {
|
||||
ty: pat.ty,
|
||||
span: pat.span,
|
||||
kind: box PatKind::Deref {
|
||||
subpattern: Pat {
|
||||
ty: rty,
|
||||
debug!("fold_pattern {:?} {:?} {:?}", pat, pat.ty.kind(), pat.kind);
|
||||
match (pat.ty.kind(), &*pat.kind) {
|
||||
(&ty::Ref(_, rty, _), &PatKind::Constant { value: Const { val, ty: const_ty } })
|
||||
if const_ty.is_ref() =>
|
||||
{
|
||||
let crty =
|
||||
if let ty::Ref(_, crty, _) = const_ty.kind() { crty } else { unreachable!() };
|
||||
if let ty::ConstKind::Value(val) = val {
|
||||
Pat {
|
||||
ty: pat.ty,
|
||||
span: pat.span,
|
||||
kind: box PatKind::Constant {
|
||||
value: Const::from_value(
|
||||
self.tcx,
|
||||
self.fold_const_value_deref(*val, rty, crty),
|
||||
rty,
|
||||
),
|
||||
kind: box PatKind::Deref {
|
||||
subpattern: Pat {
|
||||
ty: rty,
|
||||
span: pat.span,
|
||||
kind: box PatKind::Constant {
|
||||
value: Const::from_value(
|
||||
self.tcx,
|
||||
self.fold_const_value_deref(*val, rty, crty),
|
||||
rty,
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
(
|
||||
&ty::Ref(_, rty, _),
|
||||
&PatKind::Constant {
|
||||
value: Const { val, ty: ty::TyS { kind: ty::Ref(_, crty, _), .. } },
|
||||
},
|
||||
) => bug!("cannot deref {:#?}, {} -> {}", val, crty, rty),
|
||||
}
|
||||
} else {
|
||||
bug!("cannot deref {:#?}, {} -> {}", val, crty, rty)
|
||||
}
|
||||
}
|
||||
|
||||
(_, &PatKind::Binding { subpattern: Some(ref s), .. }) => s.fold_with(self),
|
||||
(_, &PatKind::AscribeUserType { subpattern: ref s, .. }) => s.fold_with(self),
|
||||
|
@ -639,7 +633,7 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
|
|||
|
||||
/// Returns whether the given type is an enum from another crate declared `#[non_exhaustive]`.
|
||||
crate fn is_foreign_non_exhaustive_enum(&self, ty: Ty<'tcx>) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Adt(def, ..) => {
|
||||
def.is_enum() && def.is_variant_list_non_exhaustive() && !def.did.is_local()
|
||||
}
|
||||
|
@ -920,14 +914,14 @@ impl<'tcx> Constructor<'tcx> {
|
|||
let mut subpatterns = fields.all_patterns();
|
||||
|
||||
let pat = match self {
|
||||
Single | Variant(_) => match ty.kind {
|
||||
Single | Variant(_) => match ty.kind() {
|
||||
ty::Adt(..) | ty::Tuple(..) => {
|
||||
let subpatterns = subpatterns
|
||||
.enumerate()
|
||||
.map(|(i, p)| FieldPat { field: Field::new(i), pattern: p })
|
||||
.collect();
|
||||
|
||||
if let ty::Adt(adt, substs) = ty.kind {
|
||||
if let ty::Adt(adt, substs) = ty.kind() {
|
||||
if adt.is_enum() {
|
||||
PatKind::Variant {
|
||||
adt_def: adt,
|
||||
|
@ -1074,7 +1068,7 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
|
|||
let wildcard_from_ty = |ty| &*cx.pattern_arena.alloc(Pat::wildcard_from_ty(ty));
|
||||
|
||||
let ret = match constructor {
|
||||
Single | Variant(_) => match ty.kind {
|
||||
Single | Variant(_) => match ty.kind() {
|
||||
ty::Tuple(ref fs) => {
|
||||
Fields::wildcards_from_tys(cx, fs.into_iter().map(|ty| ty.expect_ty()))
|
||||
}
|
||||
|
@ -1125,7 +1119,7 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
|
|||
}
|
||||
_ => Fields::empty(),
|
||||
},
|
||||
Slice(slice) => match ty.kind {
|
||||
Slice(slice) => match *ty.kind() {
|
||||
ty::Slice(ty) | ty::Array(ty, _) => {
|
||||
let arity = slice.arity();
|
||||
Fields::wildcards_from_tys(cx, (0..arity).map(|_| ty))
|
||||
|
@ -1443,7 +1437,7 @@ fn all_constructors<'a, 'tcx>(
|
|||
.unwrap(),
|
||||
)
|
||||
};
|
||||
match pcx.ty.kind {
|
||||
match *pcx.ty.kind() {
|
||||
ty::Bool => {
|
||||
[true, false].iter().map(|&b| ConstantValue(ty::Const::from_bool(cx.tcx, b))).collect()
|
||||
}
|
||||
|
@ -1558,7 +1552,7 @@ struct IntRange<'tcx> {
|
|||
impl<'tcx> IntRange<'tcx> {
|
||||
#[inline]
|
||||
fn is_integral(ty: Ty<'_>) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Char | ty::Int(_) | ty::Uint(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
|
@ -1580,7 +1574,7 @@ impl<'tcx> IntRange<'tcx> {
|
|||
|
||||
#[inline]
|
||||
fn integral_size_and_signed_bias(tcx: TyCtxt<'tcx>, ty: Ty<'_>) -> Option<(Size, u128)> {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Char => Some((Size::from_bytes(4), 0)),
|
||||
ty::Int(ity) => {
|
||||
let size = Integer::from_attr(&tcx, SignedInt(ity)).size();
|
||||
|
@ -1658,7 +1652,7 @@ impl<'tcx> IntRange<'tcx> {
|
|||
|
||||
// The return value of `signed_bias` should be XORed with an endpoint to encode/decode it.
|
||||
fn signed_bias(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> u128 {
|
||||
match ty.kind {
|
||||
match *ty.kind() {
|
||||
ty::Int(ity) => {
|
||||
let bits = Integer::from_attr(&tcx, SignedInt(ity)).size().bits() as u128;
|
||||
1u128 << (bits - 1)
|
||||
|
@ -2070,7 +2064,7 @@ fn pat_constructor<'tcx>(
|
|||
if let Some(int_range) = IntRange::from_const(tcx, param_env, value, pat.span) {
|
||||
Some(IntRange(int_range))
|
||||
} else {
|
||||
match (value.val, &value.ty.kind) {
|
||||
match (value.val, &value.ty.kind()) {
|
||||
(_, ty::Array(_, n)) => {
|
||||
let len = n.eval_usize(tcx, param_env);
|
||||
Some(Slice(Slice { array_len: Some(len), kind: FixedLen(len) }))
|
||||
|
@ -2102,7 +2096,7 @@ fn pat_constructor<'tcx>(
|
|||
}
|
||||
PatKind::Array { ref prefix, ref slice, ref suffix }
|
||||
| PatKind::Slice { ref prefix, ref slice, ref suffix } => {
|
||||
let array_len = match pat.ty.kind {
|
||||
let array_len = match pat.ty.kind() {
|
||||
ty::Array(_, length) => Some(length.eval_usize(tcx, param_env)),
|
||||
ty::Slice(_) => None,
|
||||
_ => span_bug!(pat.span, "bad ty {:?} for slice pattern", pat.ty),
|
||||
|
@ -2141,7 +2135,7 @@ fn slice_pat_covered_by_const<'tcx>(
|
|||
)
|
||||
};
|
||||
|
||||
let data: &[u8] = match (const_val_val, &const_val.ty.kind) {
|
||||
let data: &[u8] = match (const_val_val, &const_val.ty.kind()) {
|
||||
(ConstValue::ByRef { offset, alloc, .. }, ty::Array(t, n)) => {
|
||||
assert_eq!(*t, tcx.types.u8);
|
||||
let n = n.eval_usize(tcx, param_env);
|
||||
|
@ -2561,7 +2555,7 @@ fn specialize_one_pattern<'p, 'tcx>(
|
|||
// elements don't necessarily point to memory, they are usually
|
||||
// just integers. The only time they should be pointing to memory
|
||||
// is when they are subslices of nonzero slices.
|
||||
let (alloc, offset, n, ty) = match value.ty.kind {
|
||||
let (alloc, offset, n, ty) = match value.ty.kind() {
|
||||
ty::Array(t, n) => {
|
||||
let n = n.eval_usize(cx.tcx, cx.param_env);
|
||||
// Shortcut for `n == 0` where no matter what `alloc` and `offset` we produce,
|
||||
|
|
|
@ -289,7 +289,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa
|
|||
cx.typeck_results.extract_binding_mode(cx.tcx.sess, p.hir_id, p.span)
|
||||
{
|
||||
let pat_ty = cx.typeck_results.pat_ty(p).peel_refs();
|
||||
if let ty::Adt(edef, _) = pat_ty.kind {
|
||||
if let ty::Adt(edef, _) = pat_ty.kind() {
|
||||
if edef.is_enum()
|
||||
&& edef.variants.iter().any(|variant| {
|
||||
variant.ident == ident && variant.ctor_kind == CtorKind::Const
|
||||
|
@ -442,7 +442,7 @@ fn check_exhaustive<'p, 'tcx>(
|
|||
// In the absence of the `exhaustive_patterns` feature, empty matches are not detected by
|
||||
// `is_useful` to exhaustively match uninhabited types, so we manually check here.
|
||||
if is_empty_match && !cx.tcx.features().exhaustive_patterns {
|
||||
let scrutinee_is_visibly_uninhabited = match scrut_ty.kind {
|
||||
let scrutinee_is_visibly_uninhabited = match scrut_ty.kind() {
|
||||
ty::Never => true,
|
||||
ty::Adt(def, _) => {
|
||||
def.is_enum()
|
||||
|
@ -462,7 +462,7 @@ fn check_exhaustive<'p, 'tcx>(
|
|||
Err(err) => err,
|
||||
};
|
||||
|
||||
let non_empty_enum = match scrut_ty.kind {
|
||||
let non_empty_enum = match scrut_ty.kind() {
|
||||
ty::Adt(def, _) => def.is_enum() && !def.variants.is_empty(),
|
||||
_ => false,
|
||||
};
|
||||
|
@ -541,7 +541,7 @@ fn adt_defined_here(
|
|||
witnesses: &[super::Pat<'_>],
|
||||
) {
|
||||
let ty = ty.peel_refs();
|
||||
if let ty::Adt(def, _) = ty.kind {
|
||||
if let ty::Adt(def, _) = ty.kind() {
|
||||
if let Some(sp) = cx.tcx.hir().span_if_local(def.did) {
|
||||
err.span_label(sp, format!("`{}` defined here", ty));
|
||||
}
|
||||
|
@ -556,7 +556,7 @@ fn adt_defined_here(
|
|||
|
||||
fn maybe_point_at_variant(ty: Ty<'_>, patterns: &[super::Pat<'_>]) -> Vec<Span> {
|
||||
let mut covered = vec![];
|
||||
if let ty::Adt(def, _) = ty.kind {
|
||||
if let ty::Adt(def, _) = ty.kind() {
|
||||
// Don't point at variants that have already been covered due to other patterns to avoid
|
||||
// visual clutter.
|
||||
for pattern in patterns {
|
||||
|
|
|
@ -217,7 +217,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
.collect()
|
||||
};
|
||||
|
||||
let kind = match cv.ty.kind {
|
||||
let kind = match cv.ty.kind() {
|
||||
ty::Float(_) => {
|
||||
tcx.struct_span_lint_hir(
|
||||
lint::builtin::ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
|
||||
|
@ -247,11 +247,9 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
PatKind::Wild
|
||||
}
|
||||
// keep old code until future-compat upgraded to errors.
|
||||
ty::Ref(_, adt_ty @ ty::TyS { kind: ty::Adt(_, _), .. }, _)
|
||||
if !self.type_marked_structural(adt_ty) =>
|
||||
{
|
||||
ty::Ref(_, adt_ty, _) if adt_ty.is_adt() && !self.type_marked_structural(adt_ty) => {
|
||||
let adt_def =
|
||||
if let ty::Adt(adt_def, _) = adt_ty.kind { adt_def } else { unreachable!() };
|
||||
if let ty::Adt(adt_def, _) = adt_ty.kind() { adt_def } else { unreachable!() };
|
||||
|
||||
debug!(
|
||||
"adt_def {:?} has !type_marked_structural for adt_ty: {:?}",
|
||||
|
|
|
@ -237,7 +237,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
|
|||
Some(&adt_def.variants[variant_index])
|
||||
}
|
||||
_ => {
|
||||
if let ty::Adt(adt, _) = self.ty.kind {
|
||||
if let ty::Adt(adt, _) = self.ty.kind() {
|
||||
if !adt.is_enum() {
|
||||
Some(&adt.variants[VariantIdx::new(0)])
|
||||
} else {
|
||||
|
@ -302,7 +302,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
|
|||
Ok(())
|
||||
}
|
||||
PatKind::Deref { ref subpattern } => {
|
||||
match self.ty.kind {
|
||||
match self.ty.kind() {
|
||||
ty::Adt(def, _) if def.is_box() => write!(f, "box ")?,
|
||||
ty::Ref(_, _, mutbl) => {
|
||||
write!(f, "&{}", mutbl.prefix_str())?;
|
||||
|
@ -559,7 +559,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
hir::PatKind::Tuple(ref pats, ddpos) => {
|
||||
let tys = match ty.kind {
|
||||
let tys = match ty.kind() {
|
||||
ty::Tuple(ref tys) => tys,
|
||||
_ => span_bug!(pat.span, "unexpected type for tuple pattern: {:?}", ty),
|
||||
};
|
||||
|
@ -588,7 +588,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
// x's type, which is &T, where we want T (the type being matched).
|
||||
let var_ty = ty;
|
||||
if let ty::BindByReference(_) = bm {
|
||||
if let ty::Ref(_, rty, _) = ty.kind {
|
||||
if let ty::Ref(_, rty, _) = ty.kind() {
|
||||
ty = rty;
|
||||
} else {
|
||||
bug!("`ref {}` has wrong type {}", ident, ty);
|
||||
|
@ -608,7 +608,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
|
||||
hir::PatKind::TupleStruct(ref qpath, ref pats, ddpos) => {
|
||||
let res = self.typeck_results.qpath_res(qpath, pat.hir_id);
|
||||
let adt_def = match ty.kind {
|
||||
let adt_def = match ty.kind() {
|
||||
ty::Adt(adt_def, _) => adt_def,
|
||||
_ => span_bug!(pat.span, "tuple struct pattern not applied to an ADT {:?}", ty),
|
||||
};
|
||||
|
@ -670,7 +670,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
let prefix = self.lower_patterns(prefix);
|
||||
let slice = self.lower_opt_pattern(slice);
|
||||
let suffix = self.lower_patterns(suffix);
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
// Matching a slice, `[T]`.
|
||||
ty::Slice(..) => PatKind::Slice { prefix, slice, suffix },
|
||||
// Fixed-length array, `[T; len]`.
|
||||
|
@ -704,7 +704,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
let enum_id = self.tcx.parent(variant_id).unwrap();
|
||||
let adt_def = self.tcx.adt_def(enum_id);
|
||||
if adt_def.is_enum() {
|
||||
let substs = match ty.kind {
|
||||
let substs = match ty.kind() {
|
||||
ty::Adt(_, substs) | ty::FnDef(_, substs) => substs,
|
||||
ty::Error(_) => {
|
||||
// Avoid ICE (#50585)
|
||||
|
@ -1058,7 +1058,7 @@ crate fn compare_const_vals<'tcx>(
|
|||
|
||||
if let (Some(a), Some(b)) = (a_bits, b_bits) {
|
||||
use rustc_apfloat::Float;
|
||||
return match ty.kind {
|
||||
return match *ty.kind() {
|
||||
ty::Float(ast::FloatTy::F32) => {
|
||||
let l = ::rustc_apfloat::ieee::Single::from_bits(a);
|
||||
let r = ::rustc_apfloat::ieee::Single::from_bits(b);
|
||||
|
@ -1081,7 +1081,7 @@ crate fn compare_const_vals<'tcx>(
|
|||
};
|
||||
}
|
||||
|
||||
if let ty::Str = ty.kind {
|
||||
if let ty::Str = ty.kind() {
|
||||
if let (
|
||||
ty::ConstKind::Value(a_val @ ConstValue::Slice { .. }),
|
||||
ty::ConstKind::Value(b_val @ ConstValue::Slice { .. }),
|
||||
|
|
|
@ -17,7 +17,7 @@ crate trait UserAnnotatedTyHelpers<'tcx> {
|
|||
let mut user_ty = *user_provided_types.get(hir_id)?;
|
||||
debug!("user_subts_applied_to_ty_of_hir_id: user_ty={:?}", user_ty);
|
||||
let ty = self.typeck_results().node_type(hir_id);
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Adt(adt_def, ..) => {
|
||||
if let UserType::TypeOf(ref mut did, _) = &mut user_ty.value {
|
||||
*did = adt_def.did;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue