Change ty.kind to a method

This commit is contained in:
LeSeulArtichaut
2020-08-03 00:49:11 +02:00
parent ef55a0a92f
commit 3e14b684dd
189 changed files with 947 additions and 899 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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,
}

View File

@@ -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)
{

View File

@@ -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| {

View File

@@ -726,12 +726,12 @@ fn sanitize_witness<'tcx>(
saved_locals: &GeneratorSavedLocals,
) {
let allowed_upvars = tcx.erase_regions(upvars);
let allowed = match witness.kind {
let allowed = match witness.kind() {
ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(&s),
_ => {
tcx.sess.delay_span_bug(
body.span,
&format!("unexpected generator witness type {:?}", witness.kind),
&format!("unexpected generator witness type {:?}", witness.kind()),
);
return;
}
@@ -1252,7 +1252,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
let gen_ty = body.local_decls.raw[1].ty;
// Get the interior types and substs which typeck computed
let (upvars, interior, discr_ty, movable) = match gen_ty.kind {
let (upvars, interior, discr_ty, movable) = match *gen_ty.kind() {
ty::Generator(_, substs, movability) => {
let substs = substs.as_generator();
(

View File

@@ -197,7 +197,7 @@ impl Inliner<'tcx> {
// Only consider direct calls to functions
let terminator = bb_data.terminator();
if let TerminatorKind::Call { func: ref op, .. } = terminator.kind {
if let ty::FnDef(callee_def_id, substs) = op.ty(caller_body, self.tcx).kind {
if let ty::FnDef(callee_def_id, substs) = *op.ty(caller_body, self.tcx).kind() {
let instance =
Instance::resolve(self.tcx, param_env, callee_def_id, substs).ok().flatten()?;
@@ -342,7 +342,7 @@ impl Inliner<'tcx> {
}
TerminatorKind::Call { func: Operand::Constant(ref f), cleanup, .. } => {
if let ty::FnDef(def_id, _) = f.literal.ty.kind {
if let ty::FnDef(def_id, _) = *f.literal.ty.kind() {
// Don't give intrinsics the extra penalty for calls
let f = tcx.fn_sig(def_id);
if f.abi() == Abi::RustIntrinsic || f.abi() == Abi::PlatformIntrinsic {
@@ -574,7 +574,7 @@ impl Inliner<'tcx> {
assert!(args.next().is_none());
let tuple = Place::from(tuple);
let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body, tcx).ty.kind {
let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body, tcx).ty.kind() {
s
} else {
bug!("Closure arguments are not passed as a tuple");

View File

@@ -91,7 +91,7 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
{
// The dereferenced place must have type `&_`.
let ty = Place::ty_from(local, proj_base, self.body, self.tcx).ty;
if let ty::Ref(_, _, Mutability::Not) = ty.kind {
if let ty::Ref(_, _, Mutability::Not) = ty.kind() {
self.optimizations.and_stars.insert(location);
}
}
@@ -99,7 +99,7 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
if let Rvalue::Len(ref place) = *rvalue {
let place_ty = place.ty(&self.body.local_decls, self.tcx).ty;
if let ty::Array(_, len) = place_ty.kind {
if let ty::Array(_, len) = place_ty.kind() {
let span = self.body.source_info(location).span;
let constant = Constant { span, literal: len, user_ty: None };
self.optimizations.arrays_lengths.insert(location, constant);

View File

@@ -220,7 +220,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
match terminator.kind {
TerminatorKind::Call { ref func, .. } => {
if let ty::FnDef(def_id, _) = func.ty(self.ccx.body, self.ccx.tcx).kind {
if let ty::FnDef(def_id, _) = *func.ty(self.ccx.body, self.ccx.tcx).kind() {
let fn_sig = self.ccx.tcx.fn_sig(def_id);
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = fn_sig.abi() {
let name = self.ccx.tcx.item_name(def_id);
@@ -368,11 +368,11 @@ impl<'tcx> Validator<'_, 'tcx> {
== Some(hir::ConstContext::Static(hir::Mutability::Mut))
{
// Inside a `static mut`, &mut [...] is also allowed.
match ty.kind {
match ty.kind() {
ty::Array(..) | ty::Slice(_) => {}
_ => return Err(Unpromotable),
}
} else if let ty::Array(_, len) = ty.kind {
} else if let ty::Array(_, len) = ty.kind() {
// FIXME(eddyb) the `self.is_non_const_fn` condition
// seems unnecessary, given that this is merely a ZST.
match len.try_eval_usize(self.tcx, self.param_env) {
@@ -613,7 +613,7 @@ impl<'tcx> Validator<'_, 'tcx> {
}
Rvalue::BinaryOp(op, ref lhs, _) if self.const_kind.is_none() => {
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
@@ -656,7 +656,7 @@ impl<'tcx> Validator<'_, 'tcx> {
// so are allowed.
if let [proj_base @ .., ProjectionElem::Deref] = place.projection.as_ref() {
let base_ty = Place::ty_from(place.local, proj_base, self.body, self.tcx).ty;
if let ty::Ref(..) = base_ty.kind {
if let ty::Ref(..) = base_ty.kind() {
return self.validate_place(PlaceRef {
local: place.local,
projection: proj_base,
@@ -675,11 +675,11 @@ impl<'tcx> Validator<'_, 'tcx> {
// is allowed right now, and only in functions.
if self.const_kind == Some(hir::ConstContext::Static(hir::Mutability::Mut)) {
// Inside a `static mut`, &mut [...] is also allowed.
match ty.kind {
match ty.kind() {
ty::Array(..) | ty::Slice(_) => {}
_ => return Err(Unpromotable),
}
} else if let ty::Array(_, len) = ty.kind {
} else if let ty::Array(_, len) = ty.kind() {
// FIXME(eddyb): We only return `Unpromotable` for `&mut []` inside a
// const context which seems unnecessary given that this is merely a ZST.
match len.try_eval_usize(self.tcx, self.param_env) {
@@ -695,7 +695,7 @@ impl<'tcx> Validator<'_, 'tcx> {
let mut place = place.as_ref();
if let [proj_base @ .., ProjectionElem::Deref] = &place.projection {
let base_ty = Place::ty_from(place.local, proj_base, self.body, self.tcx).ty;
if let ty::Ref(..) = base_ty.kind {
if let ty::Ref(..) = base_ty.kind() {
place = PlaceRef { local: place.local, projection: proj_base };
}
}
@@ -749,7 +749,7 @@ impl<'tcx> Validator<'_, 'tcx> {
let fn_ty = callee.ty(self.body, self.tcx);
if !self.explicit && self.const_kind.is_none() {
if let ty::FnDef(def_id, _) = fn_ty.kind {
if let ty::FnDef(def_id, _) = *fn_ty.kind() {
// Never promote runtime `const fn` calls of
// functions without `#[rustc_promotable]`.
if !self.tcx.is_promotable_const_fn(def_id) {
@@ -758,7 +758,7 @@ impl<'tcx> Validator<'_, 'tcx> {
}
}
let is_const_fn = match fn_ty.kind {
let is_const_fn = match *fn_ty.kind() {
ty::FnDef(def_id, _) => {
is_const_fn(self.tcx, def_id)
|| is_unstable_const_fn(self.tcx, def_id).is_some()

View File

@@ -44,7 +44,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
continue;
}
match pred.self_ty().kind {
match pred.self_ty().kind() {
ty::Param(ref p) => {
// Allow `T: ?const Trait`
if constness == hir::Constness::NotConst
@@ -106,7 +106,7 @@ fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> Mc
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => continue,
};
match ty.kind {
match ty.kind() {
ty::Ref(_, _, hir::Mutability::Mut) => {
if !feature_allowed(tcx, fn_def_id, sym::const_mut_refs) {
return Err((span, "mutable references in const fn are unstable".into()));
@@ -203,7 +203,7 @@ fn check_rvalue(
));
};
let unsized_ty = tcx.struct_tail_erasing_lifetimes(pointee_ty, tcx.param_env(def_id));
if let ty::Slice(_) | ty::Str = unsized_ty.kind {
if let ty::Slice(_) | ty::Str = unsized_ty.kind() {
check_operand(tcx, op, span, def_id, body)?;
// Casting/coercing things to slices is fine.
Ok(())
@@ -406,7 +406,7 @@ fn check_terminator(
fn_span: _,
} => {
let fn_ty = func.ty(body, tcx);
if let ty::FnDef(fn_def_id, _) = fn_ty.kind {
if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() {
// Allow unstable const if we opt in by using #[allow_internal_unstable]
// on function or macro declaration.
if !crate::const_eval::is_min_const_fn(tcx, fn_def_id)

View File

@@ -180,7 +180,7 @@ enum PeekCallKind {
impl PeekCallKind {
fn from_arg_ty(arg: Ty<'_>) -> Self {
match arg.kind {
match arg.kind() {
ty::Ref(_, _, _) => PeekCallKind::ByRef,
_ => PeekCallKind::ByVal,
}
@@ -205,7 +205,7 @@ impl PeekCall {
if let mir::TerminatorKind::Call { func: Operand::Constant(func), args, .. } =
&terminator.kind
{
if let ty::FnDef(def_id, substs) = func.literal.ty.kind {
if let ty::FnDef(def_id, substs) = *func.literal.ty.kind() {
let sig = tcx.fn_sig(def_id);
let name = tcx.item_name(def_id);
if sig.abi() != Abi::RustIntrinsic || name != sym::rustc_peek {

View File

@@ -682,7 +682,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
variant_index: &VariantIdx,
side_to_choose| {
let place_type = place.ty(self.body, self.tcx).ty;
let adt = match place_type.kind {
let adt = match *place_type.kind() {
ty::Adt(adt, _) if adt.is_enum() => adt,
_ => return StatementEquality::NotEqual,
};

View File

@@ -331,7 +331,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}
TerminatorKind::Call { func, destination, cleanup, .. } => {
let func_ty = func.ty(&self.body.local_decls, self.tcx);
match func_ty.kind {
match func_ty.kind() {
ty::FnPtr(..) | ty::FnDef(..) => {}
_ => self.fail(
location,