mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Avoid taking reference of &TyKind
This commit is contained in:
parent
89103466d7
commit
48f43fa0ed
@ -290,7 +290,7 @@ impl<'infcx, 'tcx> crate::MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
|||||||
ty: Ty<'_>,
|
ty: Ty<'_>,
|
||||||
is_index: Option<bool>,
|
is_index: Option<bool>,
|
||||||
) -> Diag<'infcx> {
|
) -> Diag<'infcx> {
|
||||||
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::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array",
|
||||||
(&ty::Slice(_), _) => "slice",
|
(&ty::Slice(_), _) => "slice",
|
||||||
_ => span_bug!(move_from_span, "this path should not cause illegal move"),
|
_ => span_bug!(move_from_span, "this path should not cause illegal move"),
|
||||||
|
@ -201,7 +201,7 @@ fn place_components_conflict<'tcx>(
|
|||||||
|
|
||||||
let base_ty = base.ty(body, tcx).ty;
|
let base_ty = base.ty(body, tcx).ty;
|
||||||
|
|
||||||
match (elem, &base_ty.kind(), access) {
|
match (elem, base_ty.kind(), access) {
|
||||||
(_, _, Shallow(Some(ArtificialField::ArrayLength)))
|
(_, _, Shallow(Some(ArtificialField::ArrayLength)))
|
||||||
| (_, _, Shallow(Some(ArtificialField::FakeBorrow))) => {
|
| (_, _, Shallow(Some(ArtificialField::FakeBorrow))) => {
|
||||||
// The array length is like additional fields on the
|
// The array length is like additional fields on the
|
||||||
|
@ -388,7 +388,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
let (src_pointee_ty, dest_pointee_ty) =
|
let (src_pointee_ty, dest_pointee_ty) =
|
||||||
self.tcx.struct_lockstep_tails_for_codegen(source_ty, cast_ty, self.param_env);
|
self.tcx.struct_lockstep_tails_for_codegen(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(_)) => {
|
(&ty::Array(_, length), &ty::Slice(_)) => {
|
||||||
let ptr = self.read_pointer(src)?;
|
let ptr = self.read_pointer(src)?;
|
||||||
let val = Immediate::new_slice(
|
let val = Immediate::new_slice(
|
||||||
@ -478,9 +478,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||||||
dest: &PlaceTy<'tcx, M::Provenance>,
|
dest: &PlaceTy<'tcx, M::Provenance>,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
trace!("Unsizing {:?} of type {} into {}", *src, src.layout.ty, cast_ty.ty);
|
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(c, _))
|
(&ty::Ref(_, s, _), &ty::Ref(_, c, _) | &ty::RawPtr(c, _))
|
||||||
| (&ty::RawPtr(s, _), &ty::RawPtr(c, _)) => self.unsize_into_ptr(src, dest, *s, *c),
|
| (&ty::RawPtr(s, _), &ty::RawPtr(c, _)) => self.unsize_into_ptr(src, dest, s, c),
|
||||||
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
|
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
|
||||||
assert_eq!(def_a, def_b); // implies same number of fields
|
assert_eq!(def_a, def_b); // implies same number of fields
|
||||||
|
|
||||||
|
@ -608,7 +608,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
|
|
||||||
let mut bound_span_label = |self_ty: Ty<'_>, obligation: &str, quiet: &str| {
|
let mut bound_span_label = |self_ty: Ty<'_>, obligation: &str, quiet: &str| {
|
||||||
let msg = format!("`{}`", if obligation.len() > 50 { quiet } else { obligation });
|
let msg = format!("`{}`", if obligation.len() > 50 { quiet } else { obligation });
|
||||||
match &self_ty.kind() {
|
match self_ty.kind() {
|
||||||
// Point at the type that couldn't satisfy the bound.
|
// Point at the type that couldn't satisfy the bound.
|
||||||
ty::Adt(def, _) => {
|
ty::Adt(def, _) => {
|
||||||
bound_spans.get_mut_or_insert_default(tcx.def_span(def.did())).push(msg)
|
bound_spans.get_mut_or_insert_default(tcx.def_span(def.did())).push(msg)
|
||||||
|
@ -1057,7 +1057,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
|
|
||||||
// Find the type of the associated item, and the trait where the associated
|
// Find the type of the associated item, and the trait where the associated
|
||||||
// item is declared.
|
// item is declared.
|
||||||
let bound = match (&qself_ty.kind(), qself_res) {
|
let bound = match (qself_ty.kind(), qself_res) {
|
||||||
(_, Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. }) => {
|
(_, Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. }) => {
|
||||||
// `Self` in an impl of a trait -- we have a concrete self type and a
|
// `Self` in an impl of a trait -- we have a concrete self type and a
|
||||||
// trait reference.
|
// trait reference.
|
||||||
|
@ -2975,7 +2975,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let mut suffix_suggestion = sugg.clone();
|
let mut suffix_suggestion = sugg.clone();
|
||||||
suffix_suggestion.push((
|
suffix_suggestion.push((
|
||||||
if matches!(
|
if matches!(
|
||||||
(&expected_ty.kind(), &checked_ty.kind()),
|
(expected_ty.kind(), checked_ty.kind()),
|
||||||
(ty::Int(_) | ty::Uint(_), ty::Float(_))
|
(ty::Int(_) | ty::Uint(_), ty::Float(_))
|
||||||
) {
|
) {
|
||||||
// Remove fractional part from literal, for example `42.0f32` into `42`
|
// Remove fractional part from literal, for example `42.0f32` into `42`
|
||||||
@ -3077,7 +3077,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
err.multipart_suggestion_verbose(msg, suggestion, Applicability::MachineApplicable);
|
err.multipart_suggestion_verbose(msg, suggestion, Applicability::MachineApplicable);
|
||||||
};
|
};
|
||||||
|
|
||||||
match (&expected_ty.kind(), &checked_ty.kind()) {
|
match (expected_ty.kind(), checked_ty.kind()) {
|
||||||
(ty::Int(exp), ty::Int(found)) => {
|
(ty::Int(exp), ty::Int(found)) => {
|
||||||
let (f2e_is_fallible, e2f_is_fallible) = match (exp.bit_width(), found.bit_width())
|
let (f2e_is_fallible, e2f_is_fallible) = match (exp.bit_width(), found.bit_width())
|
||||||
{
|
{
|
||||||
|
@ -1012,7 +1012,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
};
|
};
|
||||||
let mut bound_span_label = |self_ty: Ty<'_>, obligation: &str, quiet: &str| {
|
let mut bound_span_label = |self_ty: Ty<'_>, obligation: &str, quiet: &str| {
|
||||||
let msg = format!("`{}`", if obligation.len() > 50 { quiet } else { obligation });
|
let msg = format!("`{}`", if obligation.len() > 50 { quiet } else { obligation });
|
||||||
match &self_ty.kind() {
|
match self_ty.kind() {
|
||||||
// Point at the type that couldn't satisfy the bound.
|
// Point at the type that couldn't satisfy the bound.
|
||||||
ty::Adt(def, _) => {
|
ty::Adt(def, _) => {
|
||||||
bound_spans.get_mut_or_insert_default(tcx.def_span(def.did())).push(msg)
|
bound_spans.get_mut_or_insert_default(tcx.def_span(def.did())).push(msg)
|
||||||
|
@ -1336,7 +1336,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// More generally, the expected type wants a tuple variant with one field of an
|
// More generally, the expected type wants a tuple variant with one field of an
|
||||||
// N-arity-tuple, e.g., `V_i((p_0, .., p_N))`. Meanwhile, the user supplied a pattern
|
// N-arity-tuple, e.g., `V_i((p_0, .., p_N))`. Meanwhile, the user supplied a pattern
|
||||||
// with the subpatterns directly in the tuple variant pattern, e.g., `V_i(p_0, .., p_N)`.
|
// with the subpatterns directly in the tuple variant pattern, e.g., `V_i(p_0, .., p_N)`.
|
||||||
let missing_parentheses = match (&expected.kind(), fields, had_err) {
|
let missing_parentheses = match (expected.kind(), fields, had_err) {
|
||||||
// #67037: only do this if we could successfully type-check the expected type against
|
// #67037: only do this if we could successfully type-check the expected type against
|
||||||
// the tuple struct pattern. Otherwise the args could get out of range on e.g.,
|
// the tuple struct pattern. Otherwise the args could get out of range on e.g.,
|
||||||
// `let P() = U;` where `P != U` with `struct P<T>(T);`.
|
// `let P() = U;` where `P != U` with `struct P<T>(T);`.
|
||||||
|
@ -1104,7 +1104,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_never(this: TyAndLayout<'tcx>) -> bool {
|
fn is_never(this: TyAndLayout<'tcx>) -> bool {
|
||||||
this.ty.kind() == &ty::Never
|
matches!(this.ty.kind(), ty::Never)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_tuple(this: TyAndLayout<'tcx>) -> bool {
|
fn is_tuple(this: TyAndLayout<'tcx>) -> bool {
|
||||||
|
@ -296,7 +296,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
) -> (Ty<'tcx>, Ty<'tcx>) {
|
) -> (Ty<'tcx>, Ty<'tcx>) {
|
||||||
let (mut a, mut b) = (source, target);
|
let (mut a, mut b) = (source, target);
|
||||||
loop {
|
loop {
|
||||||
match (&a.kind(), &b.kind()) {
|
match (a.kind(), b.kind()) {
|
||||||
(&ty::Adt(a_def, a_args), &ty::Adt(b_def, b_args))
|
(&ty::Adt(a_def, a_args), &ty::Adt(b_def, b_args))
|
||||||
if a_def == b_def && a_def.is_struct() =>
|
if a_def == b_def && a_def.is_struct() =>
|
||||||
{
|
{
|
||||||
|
@ -127,7 +127,7 @@ fn lit_to_mir_constant<'tcx>(
|
|||||||
Ok(ConstValue::Scalar(Scalar::from_uint(result, width)))
|
Ok(ConstValue::Scalar(Scalar::from_uint(result, width)))
|
||||||
};
|
};
|
||||||
|
|
||||||
let value = match (lit, &ty.kind()) {
|
let value = match (lit, ty.kind()) {
|
||||||
(ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() => {
|
(ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() => {
|
||||||
let s = s.as_str();
|
let s = s.as_str();
|
||||||
let allocation = Allocation::from_bytes_byte_aligned_immutable(s.as_bytes());
|
let allocation = Allocation::from_bytes_byte_aligned_immutable(s.as_bytes());
|
||||||
|
@ -29,7 +29,7 @@ pub(crate) fn lit_to_const<'tcx>(
|
|||||||
.unwrap_or_else(|| bug!("expected to create ScalarInt from uint {:?}", result)))
|
.unwrap_or_else(|| bug!("expected to create ScalarInt from uint {:?}", result)))
|
||||||
};
|
};
|
||||||
|
|
||||||
let valtree = match (lit, &ty.kind()) {
|
let valtree = match (lit, ty.kind()) {
|
||||||
(ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() => {
|
(ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() => {
|
||||||
let str_bytes = s.as_str().as_bytes();
|
let str_bytes = s.as_str().as_bytes();
|
||||||
ty::ValTree::from_raw_bytes(tcx, str_bytes)
|
ty::ValTree::from_raw_bytes(tcx, str_bytes)
|
||||||
|
@ -1035,9 +1035,9 @@ 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(b, _))
|
(&ty::Ref(_, a, _), &ty::Ref(_, b, _) | &ty::RawPtr(b, _))
|
||||||
| (&ty::RawPtr(a, _), &ty::RawPtr(b, _)) => ptr_vtable(*a, *b),
|
| (&ty::RawPtr(a, _), &ty::RawPtr(b, _)) => ptr_vtable(a, b),
|
||||||
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
|
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
|
||||||
ptr_vtable(source_ty.boxed_ty(), target_ty.boxed_ty())
|
ptr_vtable(source_ty.boxed_ty(), target_ty.boxed_ty())
|
||||||
}
|
}
|
||||||
|
@ -382,7 +382,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
if !expected_inner.is_fn() || !found_inner.is_fn() {
|
if !expected_inner.is_fn() || !found_inner.is_fn() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match (&expected_inner.kind(), &found_inner.kind()) {
|
match (expected_inner.kind(), found_inner.kind()) {
|
||||||
(ty::FnPtr(sig_tys, hdr), ty::FnDef(did, args)) => {
|
(ty::FnPtr(sig_tys, hdr), ty::FnDef(did, args)) => {
|
||||||
let sig = sig_tys.with(*hdr);
|
let sig = sig_tys.with(*hdr);
|
||||||
let expected_sig = &(self.normalize_fn_sig)(sig);
|
let expected_sig = &(self.normalize_fn_sig)(sig);
|
||||||
|
Loading…
Reference in New Issue
Block a user