diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 8159f76b421..15f2e0e56d8 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -572,20 +572,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::Ref(_, bk, place) => { let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| { - Ty::new_ref( - tcx, - tcx.lifetimes.re_erased, - ty::TypeAndMut { ty, mutbl: bk.to_mutbl_lossy() }, - ) + Ty::new_ref(tcx, tcx.lifetimes.re_erased, ty, bk.to_mutbl_lossy()) }; self.codegen_place_to_pointer(bx, place, mk_ref) } mir::Rvalue::CopyForDeref(place) => self.codegen_operand(bx, &Operand::Copy(place)), mir::Rvalue::AddressOf(mutability, place) => { - let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| { - Ty::new_ptr(tcx, ty::TypeAndMut { ty, mutbl: mutability }) - }; + let mk_ptr = + move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| Ty::new_ptr(tcx, ty, mutability); self.codegen_place_to_pointer(bx, place, mk_ptr) } diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index d8fbc11654e..0b526a8c977 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -191,7 +191,7 @@ pub fn check_intrinsic_type( ty::BoundRegion { var: ty::BoundVar::from_u32(2), kind: ty::BrEnv }, ); let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]); - (Ty::new_ref(tcx, env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty) + (Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty) }) }; diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 109e00d4f24..b0c9f1bed43 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2299,14 +2299,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { self.lower_delegation_ty(*sig_id, *idx, hir_ty.span) } hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.lower_ty(ty)), - hir::TyKind::Ptr(mt) => { - Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.lower_ty(mt.ty), mutbl: mt.mutbl }) - } + hir::TyKind::Ptr(mt) => Ty::new_ptr(tcx, self.lower_ty(mt.ty), mt.mutbl), hir::TyKind::Ref(region, mt) => { let r = self.lower_lifetime(region, None); debug!(?r); let t = self.lower_ty_common(mt.ty, true, false); - Ty::new_ref(tcx, r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl }) + Ty::new_ref(tcx, r, t, mt.mutbl) } hir::TyKind::Never => tcx.types.never, hir::TyKind::Tup(fields) => { diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 2b015c4e2d0..1a20c4c93d0 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -334,11 +334,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() { if let ty::RawPtr(TypeAndMut { ty: expr_ty, .. }) = *self.expr_ty.kind() && fcx.can_coerce( - Ty::new_ref( - fcx.tcx, - fcx.tcx.lifetimes.re_erased, - TypeAndMut { ty: expr_ty, mutbl }, - ), + Ty::new_ref(fcx.tcx, fcx.tcx.lifetimes.re_erased, expr_ty, mutbl), self.cast_ty, ) { @@ -354,7 +350,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { if !sugg_mutref && sugg == None && fcx.can_coerce( - Ty::new_ref(fcx.tcx, reg, TypeAndMut { ty: self.expr_ty, mutbl }), + Ty::new_ref(fcx.tcx, reg, self.expr_ty, mutbl), self.cast_ty, ) { @@ -362,11 +358,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { } } else if let ty::RawPtr(TypeAndMut { mutbl, .. }) = *self.cast_ty.kind() && fcx.can_coerce( - Ty::new_ref( - fcx.tcx, - fcx.tcx.lifetimes.re_erased, - TypeAndMut { ty: self.expr_ty, mutbl }, - ), + Ty::new_ref(fcx.tcx, fcx.tcx.lifetimes.re_erased, self.expr_ty, mutbl), self.cast_ty, ) { @@ -861,7 +853,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { // from a region pointer to a vector. // Coerce to a raw pointer so that we generate AddressOf in MIR. - let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr); + let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr.ty, m_expr.mutbl); fcx.coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None) .unwrap_or_else(|_| { bug!( diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index a218b4ec7a5..508851d7a09 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -55,7 +55,7 @@ use rustc_middle::ty::adjustment::{ use rustc_middle::ty::error::TypeError; use rustc_middle::ty::relate::RelateResult; use rustc_middle::ty::visit::TypeVisitableExt; -use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeAndMut}; +use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt}; use rustc_session::parse::feature_err; use rustc_span::symbol::sym; use rustc_span::DesugaringKind; @@ -440,10 +440,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let derefd_ty_a = Ty::new_ref( self.tcx, r, - TypeAndMut { - ty: referent_ty, - mutbl: mutbl_b, // [1] above - }, + referent_ty, + mutbl_b, // [1] above ); match self.unify(derefd_ty_a, b) { Ok(ok) => { @@ -558,11 +556,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { Adjustment { kind: Adjust::Deref(None), target: ty_a }, Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)), - target: Ty::new_ref( - self.tcx, - r_borrow, - ty::TypeAndMut { mutbl: mutbl_b, ty: ty_a }, - ), + target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b), }, )) } @@ -573,7 +567,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { Adjustment { kind: Adjust::Deref(None), target: ty_a }, Adjustment { kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)), - target: Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: mt_b, ty: ty_a }), + target: Ty::new_ptr(self.tcx, ty_a, mt_b), }, )) } @@ -990,7 +984,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { coerce_mutbls(mt_a.mutbl, mutbl_b)?; // Check that the types which they point at are compatible. - let a_unsafe = Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: mutbl_b, ty: mt_a.ty }); + let a_unsafe = Ty::new_ptr(self.tcx, mt_a.ty, mutbl_b); // Although references and unsafe ptrs have the same // representation, we still register an Adjust::DerefRef so that // regionck knows that the region for `a` must be valid here. diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index bd1d7d122d1..125de52a6da 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -442,12 +442,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = self.check_expr_with_expectation_and_needs(oprnd, hint, Needs::maybe_mut_place(mutbl)); - let tm = ty::TypeAndMut { ty, mutbl }; match kind { - _ if tm.ty.references_error() => Ty::new_misc_error(self.tcx), + _ if ty.references_error() => Ty::new_misc_error(self.tcx), hir::BorrowKind::Raw => { self.check_named_place_expr(oprnd); - Ty::new_ptr(self.tcx, tm) + Ty::new_ptr(self.tcx, ty, mutbl) } hir::BorrowKind::Ref => { // Note: at this point, we cannot say what the best lifetime @@ -465,7 +464,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // whose address was taken can actually be made to live as long // as it needs to live. let region = self.next_region_var(infer::AddrOfRegion(expr.span)); - Ty::new_ref(self.tcx, region, tm) + Ty::new_ref(self.tcx, region, ty, mutbl) } } } @@ -3225,7 +3224,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.demand_coerce(expr, ty, fnptr_ty, None, AllowTwoPhase::No); } ty::Ref(_, base_ty, mutbl) => { - let ptr_ty = Ty::new_ptr(self.tcx, ty::TypeAndMut { ty: base_ty, mutbl }); + let ptr_ty = Ty::new_ptr(self.tcx, base_ty, mutbl); self.demand_coerce(expr, ty, ptr_ty, None, AllowTwoPhase::No); } _ => {} diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index d949772f1a3..f5b6dd162b3 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -268,11 +268,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { adjustment::Adjust::Deref(overloaded) => { // Equivalent to *expr or something similar. let base = if let Some(deref) = overloaded { - let ref_ty = Ty::new_ref( - self.tcx(), - deref.region, - ty::TypeAndMut { ty: target, mutbl: deref.mutbl }, - ); + let ref_ty = Ty::new_ref(self.tcx(), deref.region, target, deref.mutbl); self.cat_rvalue(expr.hir_id, ref_ty) } else { previous()? @@ -479,7 +475,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { let ty::Ref(region, _, mutbl) = *base_ty.kind() else { span_bug!(expr.span, "cat_overloaded_place: base is not a reference"); }; - let ref_ty = Ty::new_ref(self.tcx(), region, ty::TypeAndMut { ty: place_ty, mutbl }); + let ref_ty = Ty::new_ref(self.tcx(), region, place_ty, mutbl); let base = self.cat_rvalue(expr.hir_id, ref_ty); self.cat_deref(expr, base) diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 3eab0c50e34..4a37794fef7 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -188,7 +188,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // Type we're wrapping in a reference, used later for unsizing let base_ty = target; - target = Ty::new_ref(self.tcx, region, ty::TypeAndMut { mutbl, ty: target }); + target = Ty::new_ref(self.tcx, region, target, mutbl); // Method call receivers are the primary use case // for two-phase borrows. @@ -208,11 +208,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { base_ty ) }; - target = Ty::new_ref( - self.tcx, - region, - ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty }, - ); + target = Ty::new_ref(self.tcx, region, unsized_ty, mutbl.into()); adjustments.push(Adjustment { kind: Adjust::Pointer(PointerCoercion::Unsize), target, diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index 3b26a791f65..e9752d7a4a8 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -200,11 +200,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(span) = result.illegal_sized_bound { let mut needs_mut = false; if let ty::Ref(region, t_type, mutability) = self_ty.kind() { - let trait_type = Ty::new_ref( - self.tcx, - *region, - ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() }, - ); + let trait_type = Ty::new_ref(self.tcx, *region, *t_type, mutability.invert()); // We probe again to see if there might be a borrow mutability discrepancy. match self.lookup_probe( segment.ident, diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 72e8e86d8c8..bb39a585ae5 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1213,7 +1213,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // In general, during probing we erase regions. let region = tcx.lifetimes.re_erased; - let autoref_ty = Ty::new_ref(tcx, region, ty::TypeAndMut { ty: self_ty, mutbl }); + let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl); self.pick_method(autoref_ty, unstable_candidates).map(|r| { r.map(|mut pick| { pick.autoderefs = step.autoderefs; diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index f3615c03215..cfbe6b18745 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -304,11 +304,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() { if needs_mut { - let trait_type = Ty::new_ref( - self.tcx, - *region, - ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() }, - ); + let trait_type = + Ty::new_ref(self.tcx, *region, *t_type, mutability.invert()); let msg = format!("you need `{trait_type}` instead of `{rcvr_ty}`"); let mut kind = &self_expr.kind; while let hir::ExprKind::AddrOf(_, _, expr) diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index 8969030d683..b17b312a797 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -508,11 +508,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { suggest_deref_binop(&mut err, *lhs_deref_ty); } else { let lhs_inv_mutbl = mutbl.invert(); - let lhs_inv_mutbl_ty = Ty::new_ref( - self.tcx, - *region, - ty::TypeAndMut { ty: *lhs_deref_ty, mutbl: lhs_inv_mutbl }, - ); + let lhs_inv_mutbl_ty = + Ty::new_ref(self.tcx, *region, *lhs_deref_ty, lhs_inv_mutbl); suggest_different_borrow( &mut err, @@ -524,11 +521,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Ref(region, rhs_deref_ty, mutbl) = rhs_ty.kind() { let rhs_inv_mutbl = mutbl.invert(); - let rhs_inv_mutbl_ty = Ty::new_ref( - self.tcx, - *region, - ty::TypeAndMut { ty: *rhs_deref_ty, mutbl: rhs_inv_mutbl }, - ); + let rhs_inv_mutbl_ty = + Ty::new_ref(self.tcx, *region, *rhs_deref_ty, rhs_inv_mutbl); suggest_different_borrow( &mut err, diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index dad43cb8abe..5ddd0f8be25 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -2057,8 +2057,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Create a reference type with a fresh region variable. fn new_ref_ty(&self, span: Span, mutbl: hir::Mutability, ty: Ty<'tcx>) -> Ty<'tcx> { let region = self.next_region_var(infer::PatternRegion(span)); - let mt = ty::TypeAndMut { ty, mutbl }; - Ty::new_ref(self.tcx, region, mt) + Ty::new_ref(self.tcx, region, ty, mutbl) } fn try_resolve_slice_ty_to_array_ty( diff --git a/compiler/rustc_hir_typeck/src/place_op.rs b/compiler/rustc_hir_typeck/src/place_op.rs index 6c5715b323c..f29dc39b7be 100644 --- a/compiler/rustc_hir_typeck/src/place_op.rs +++ b/compiler/rustc_hir_typeck/src/place_op.rs @@ -162,11 +162,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() { adjustments.push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)), - target: Ty::new_ref( - self.tcx, - *region, - ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: adjusted_ty }, - ), + target: Ty::new_imm_ref(self.tcx, *region, adjusted_ty), }); } else { span_bug!(expr.span, "input to index is not a ref?"); @@ -400,11 +396,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { allow_two_phase_borrow: AllowTwoPhase::No, }; adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)); - adjustment.target = Ty::new_ref( - self.tcx, - *region, - ty::TypeAndMut { ty: source, mutbl: mutbl.into() }, - ); + adjustment.target = Ty::new_ref(self.tcx, *region, source, mutbl.into()); } source = adjustment.target; } diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index b71e88a1579..adebd0b8cee 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -1780,11 +1780,9 @@ fn apply_capture_kind_on_capture_ty<'tcx>( ) -> Ty<'tcx> { match capture_kind { ty::UpvarCapture::ByValue => ty, - ty::UpvarCapture::ByRef(kind) => Ty::new_ref( - tcx, - region.unwrap(), - ty::TypeAndMut { ty: ty, mutbl: kind.to_mutbl_lossy() }, - ), + ty::UpvarCapture::ByRef(kind) => { + Ty::new_ref(tcx, region.unwrap(), ty, kind.to_mutbl_lossy()) + } } } diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 0ad257d02bd..f8c1f478833 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1046,10 +1046,10 @@ fn get_nullable_type<'tcx>( } ty::Int(ty) => Ty::new_int(tcx, ty), ty::Uint(ty) => Ty::new_uint(tcx, ty), - ty::RawPtr(ty_mut) => Ty::new_ptr(tcx, ty_mut), + ty::RawPtr(ty_mut) => Ty::new_ptr(tcx, ty_mut.ty, ty_mut.mutbl), // As these types are always non-null, the nullable equivalent of // `Option` of these types are their raw pointer counterparts. - ty::Ref(_region, ty, mutbl) => Ty::new_ptr(tcx, ty::TypeAndMut { ty, mutbl }), + ty::Ref(_region, ty, mutbl) => Ty::new_ptr(tcx, ty, mutbl), // There is no nullable equivalent for Rust's function pointers, // you must use an `Option _>` to represent it. ty::FnPtr(..) => ty, diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index 0c29fe57d4f..ac41b6c5732 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -170,11 +170,11 @@ impl<'tcx> Rvalue<'tcx> { Rvalue::ThreadLocalRef(did) => tcx.thread_local_ptr_ty(did), Rvalue::Ref(reg, bk, ref place) => { let place_ty = place.ty(local_decls, tcx).ty; - Ty::new_ref(tcx, reg, ty::TypeAndMut { ty: place_ty, mutbl: bk.to_mutbl_lossy() }) + Ty::new_ref(tcx, reg, place_ty, bk.to_mutbl_lossy()) } Rvalue::AddressOf(mutability, ref place) => { let place_ty = place.ty(local_decls, tcx).ty; - Ty::new_ptr(tcx, ty::TypeAndMut { ty: place_ty, mutbl: mutability }) + Ty::new_ptr(tcx, place_ty, mutability) } Rvalue::Len(..) => tcx.types.usize, Rvalue::Cast(.., ty) => ty, diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 764ee8d5652..a04a0d17d00 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -460,7 +460,7 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>( let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?; - Ok(Ty::new_ptr(tcx, ty::TypeAndMut { mutbl: a_mutbl, ty })) + Ok(Ty::new_ptr(tcx, ty, a_mutbl)) } (&ty::Ref(a_r, a_ty, a_mutbl), &ty::Ref(b_r, b_ty, b_mutbl)) => { @@ -478,7 +478,7 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>( let r = relation.relate(a_r, b_r)?; let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?; - Ok(Ty::new_ref(tcx, r, ty::TypeAndMut { mutbl: a_mutbl, ty })) + Ok(Ty::new_ref(tcx, r, ty, a_mutbl)) } (&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => { diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 6e0a9eb86dd..113e0c29c08 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1587,33 +1587,38 @@ impl<'tcx> Ty<'tcx> { } #[inline] - pub fn new_ref(tcx: TyCtxt<'tcx>, r: Region<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> { - Ty::new(tcx, Ref(r, tm.ty, tm.mutbl)) + pub fn new_ref( + tcx: TyCtxt<'tcx>, + r: Region<'tcx>, + ty: Ty<'tcx>, + mutbl: ty::Mutability, + ) -> Ty<'tcx> { + Ty::new(tcx, Ref(r, ty, mutbl)) } #[inline] pub fn new_mut_ref(tcx: TyCtxt<'tcx>, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { - Ty::new_ref(tcx, r, TypeAndMut { ty, mutbl: hir::Mutability::Mut }) + Ty::new_ref(tcx, r, ty, hir::Mutability::Mut) } #[inline] pub fn new_imm_ref(tcx: TyCtxt<'tcx>, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { - Ty::new_ref(tcx, r, TypeAndMut { ty, mutbl: hir::Mutability::Not }) + Ty::new_ref(tcx, r, ty, hir::Mutability::Not) } #[inline] - pub fn new_ptr(tcx: TyCtxt<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> { - Ty::new(tcx, RawPtr(tm)) + pub fn new_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, mutbl: ty::Mutability) -> Ty<'tcx> { + Ty::new(tcx, RawPtr(ty::TypeAndMut { ty, mutbl })) } #[inline] pub fn new_mut_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { - Ty::new_ptr(tcx, TypeAndMut { ty, mutbl: hir::Mutability::Mut }) + Ty::new_ptr(tcx, ty, hir::Mutability::Mut) } #[inline] pub fn new_imm_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { - Ty::new_ptr(tcx, TypeAndMut { ty, mutbl: hir::Mutability::Not }) + Ty::new_ptr(tcx, ty, hir::Mutability::Not) } #[inline] diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 52d32a3b626..1e508ffc1e7 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -125,11 +125,7 @@ impl<'tcx> Cx<'tcx> { expr = Expr { temp_lifetime, - ty: Ty::new_ref( - self.tcx, - deref.region, - ty::TypeAndMut { ty: expr.ty, mutbl: deref.mutbl }, - ), + ty: Ty::new_ref(self.tcx, deref.region, expr.ty, deref.mutbl), span, kind: ExprKind::Borrow { borrow_kind: deref.mutbl.to_borrow_kind(), @@ -1021,7 +1017,7 @@ impl<'tcx> Cx<'tcx> { let ty::Ref(region, _, mutbl) = *self.thir[args[0]].ty.kind() else { span_bug!(span, "overloaded_place: receiver is not a reference"); }; - let ref_ty = Ty::new_ref(self.tcx, region, ty::TypeAndMut { ty: place_ty, mutbl }); + let ref_ty = Ty::new_ref(self.tcx, region, place_ty, mutbl); // construct the complete expression `foo()` for the overloaded call, // which will yield the &T type diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 87dff49e0be..872f60ad565 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -94,7 +94,7 @@ use rustc_middle::mir::interpret::GlobalAlloc; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeAndMut}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::def_id::DefId; use rustc_span::DUMMY_SP; use rustc_target::abi::{self, Abi, Size, VariantIdx, FIRST_VARIANT}; @@ -451,11 +451,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { AddressKind::Ref(bk) => Ty::new_ref( self.tcx, self.tcx.lifetimes.re_erased, - ty::TypeAndMut { ty: mplace.layout.ty, mutbl: bk.to_mutbl_lossy() }, + mplace.layout.ty, + bk.to_mutbl_lossy(), ), - AddressKind::Address(mutbl) => { - Ty::new_ptr(self.tcx, TypeAndMut { ty: mplace.layout.ty, mutbl }) - } + AddressKind::Address(mutbl) => Ty::new_ptr(self.tcx, mplace.layout.ty, mutbl), }; let layout = self.ecx.layout_of(ty).ok()?; ImmTy::from_immediate(pointer, layout).into() diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index 9fe8c34a8bf..cbc04a9b39d 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -820,11 +820,8 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let ty = local_decls[place.local].ty; let span = statement.source_info.span; - let ref_ty = Ty::new_ref( - tcx, - tcx.lifetimes.re_erased, - ty::TypeAndMut { ty, mutbl: borrow_kind.to_mutbl_lossy() }, - ); + let ref_ty = + Ty::new_ref(tcx, tcx.lifetimes.re_erased, ty, borrow_kind.to_mutbl_lossy()); let mut projection = vec![PlaceElem::Deref]; projection.extend(place.projection); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 00d00496947..05c0fbed589 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -31,8 +31,8 @@ use rustc_middle::traits::IsConstable; use rustc_middle::ty::error::TypeError::{self, Sorts}; use rustc_middle::ty::{ self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, GenericArgs, - InferTy, IsSuggestable, ToPredicate, Ty, TyCtxt, TypeAndMut, TypeFoldable, TypeFolder, - TypeSuperFoldable, TypeVisitableExt, TypeckResults, + InferTy, IsSuggestable, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, + TypeVisitableExt, TypeckResults, }; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::{kw, sym, Ident, Symbol}; @@ -482,7 +482,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if let Some(steps) = autoderef.into_iter().enumerate().find_map(|(steps, (ty, obligations))| { // Re-add the `&` - let ty = Ty::new_ref(self.tcx, region, TypeAndMut { ty, mutbl }); + let ty = Ty::new_ref(self.tcx, region, ty, mutbl); // Remapping bound vars here let real_trait_pred_and_ty = real_trait_pred