Change ty.kind to a method
This commit is contained in:
parent
ef55a0a92f
commit
3e14b684dd
189 changed files with 947 additions and 899 deletions
|
@ -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| {
|
||||
|
|
|
@ -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();
|
||||
(
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -47,7 +47,7 @@ where
|
|||
ProjectionElem::Deref => break,
|
||||
ProjectionElem::Field(..) => {
|
||||
let ty = Place::ty_from(place.local, proj_base, local_decls, tcx).ty;
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Adt(def, _) if def.repr.packed() => return true,
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> {
|
|||
ty: Ty<'_>,
|
||||
is_index: Option<bool>,
|
||||
) -> DiagnosticBuilder<'cx> {
|
||||
let type_name = match (&ty.kind, is_index) {
|
||||
let type_name = match (&ty.kind(), is_index) {
|
||||
(&ty::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array",
|
||||
(&ty::Slice(_), _) => "slice",
|
||||
_ => span_bug!(move_from_span, "this path should not cause illegal move"),
|
||||
|
|
|
@ -858,7 +858,7 @@ where
|
|||
/// ADT, both in the success case or if one of the destructors fail.
|
||||
fn open_drop(&mut self) -> BasicBlock {
|
||||
let ty = self.place_ty(self.place);
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Closure(_, substs) => {
|
||||
let tys: Vec<_> = substs.as_closure().upvar_tys().collect();
|
||||
self.open_drop_for_tuple(&tys)
|
||||
|
|
|
@ -398,7 +398,7 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
|
|||
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
|
||||
self.super_constant(constant, location);
|
||||
let Constant { span, user_ty, literal } = constant;
|
||||
match literal.ty.kind {
|
||||
match literal.ty.kind() {
|
||||
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char => {}
|
||||
// Unit type
|
||||
ty::Tuple(tys) if tys.is_empty() => {}
|
||||
|
@ -416,7 +416,7 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
|
|||
fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, _: Location) {
|
||||
self.super_const(constant);
|
||||
let ty::Const { ty, val, .. } = constant;
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => {}
|
||||
// Unit type
|
||||
ty::Tuple(tys) if tys.is_empty() => {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue