Skip to content

Commit 2fbd0ec

Browse files
Ty::new_ref and Ty::new_ptr stop using TypeAndMut
1 parent 5ac67dd commit 2fbd0ec

File tree

23 files changed

+68
-125
lines changed

23 files changed

+68
-125
lines changed

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -572,20 +572,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
572572

573573
mir::Rvalue::Ref(_, bk, place) => {
574574
let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
575-
Ty::new_ref(
576-
tcx,
577-
tcx.lifetimes.re_erased,
578-
ty::TypeAndMut { ty, mutbl: bk.to_mutbl_lossy() },
579-
)
575+
Ty::new_ref(tcx, tcx.lifetimes.re_erased, ty, bk.to_mutbl_lossy())
580576
};
581577
self.codegen_place_to_pointer(bx, place, mk_ref)
582578
}
583579

584580
mir::Rvalue::CopyForDeref(place) => self.codegen_operand(bx, &Operand::Copy(place)),
585581
mir::Rvalue::AddressOf(mutability, place) => {
586-
let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
587-
Ty::new_ptr(tcx, ty::TypeAndMut { ty, mutbl: mutability })
588-
};
582+
let mk_ptr =
583+
move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| Ty::new_ptr(tcx, ty, mutability);
589584
self.codegen_place_to_pointer(bx, place, mk_ptr)
590585
}
591586

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,14 +2239,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
22392239
self.ty_from_delegation(*sig_id, *idx, ast_ty.span)
22402240
}
22412241
hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.ast_ty_to_ty(ty)),
2242-
hir::TyKind::Ptr(mt) => {
2243-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl })
2244-
}
2242+
hir::TyKind::Ptr(mt) => Ty::new_ptr(tcx, self.ast_ty_to_ty(mt.ty), mt.mutbl),
22452243
hir::TyKind::Ref(region, mt) => {
22462244
let r = self.ast_region_to_region(region, None);
22472245
debug!(?r);
22482246
let t = self.ast_ty_to_ty_inner(mt.ty, true, false);
2249-
Ty::new_ref(tcx, r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl })
2247+
Ty::new_ref(tcx, r, t, mt.mutbl)
22502248
}
22512249
hir::TyKind::Never => tcx.types.never,
22522250
hir::TyKind::Tup(fields) => {

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub fn check_intrinsic_type(
191191
ty::BoundRegion { var: ty::BoundVar::from_u32(2), kind: ty::BrEnv },
192192
);
193193
let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]);
194-
(Ty::new_ref(tcx, env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty)
194+
(Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty)
195195
})
196196
};
197197

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
334334
if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() {
335335
if let ty::RawPtr(TypeAndMut { ty: expr_ty, .. }) = *self.expr_ty.kind()
336336
&& fcx.can_coerce(
337-
Ty::new_ref(
338-
fcx.tcx,
339-
fcx.tcx.lifetimes.re_erased,
340-
TypeAndMut { ty: expr_ty, mutbl },
341-
),
337+
Ty::new_ref(fcx.tcx, fcx.tcx.lifetimes.re_erased, expr_ty, mutbl),
342338
self.cast_ty,
343339
)
344340
{
@@ -354,19 +350,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
354350
if !sugg_mutref
355351
&& sugg == None
356352
&& fcx.can_coerce(
357-
Ty::new_ref(fcx.tcx, reg, TypeAndMut { ty: self.expr_ty, mutbl }),
353+
Ty::new_ref(fcx.tcx, reg, self.expr_ty, mutbl),
358354
self.cast_ty,
359355
)
360356
{
361357
sugg = Some((format!("&{}", mutbl.prefix_str()), false));
362358
}
363359
} else if let ty::RawPtr(TypeAndMut { mutbl, .. }) = *self.cast_ty.kind()
364360
&& fcx.can_coerce(
365-
Ty::new_ref(
366-
fcx.tcx,
367-
fcx.tcx.lifetimes.re_erased,
368-
TypeAndMut { ty: self.expr_ty, mutbl },
369-
),
361+
Ty::new_ref(fcx.tcx, fcx.tcx.lifetimes.re_erased, self.expr_ty, mutbl),
370362
self.cast_ty,
371363
)
372364
{
@@ -861,7 +853,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
861853
// from a region pointer to a vector.
862854

863855
// Coerce to a raw pointer so that we generate AddressOf in MIR.
864-
let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr);
856+
let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr.ty, m_expr.mutbl);
865857
fcx.coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None)
866858
.unwrap_or_else(|_| {
867859
bug!(

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use rustc_middle::ty::adjustment::{
5555
use rustc_middle::ty::error::TypeError;
5656
use rustc_middle::ty::relate::RelateResult;
5757
use rustc_middle::ty::visit::TypeVisitableExt;
58-
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeAndMut};
58+
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt};
5959
use rustc_session::parse::feature_err;
6060
use rustc_span::symbol::sym;
6161
use rustc_span::DesugaringKind;
@@ -440,10 +440,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
440440
let derefd_ty_a = Ty::new_ref(
441441
self.tcx,
442442
r,
443-
TypeAndMut {
444-
ty: referent_ty,
445-
mutbl: mutbl_b, // [1] above
446-
},
443+
referent_ty,
444+
mutbl_b, // [1] above
447445
);
448446
match self.unify(derefd_ty_a, b) {
449447
Ok(ok) => {
@@ -558,11 +556,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
558556
Adjustment { kind: Adjust::Deref(None), target: ty_a },
559557
Adjustment {
560558
kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)),
561-
target: Ty::new_ref(
562-
self.tcx,
563-
r_borrow,
564-
ty::TypeAndMut { mutbl: mutbl_b, ty: ty_a },
565-
),
559+
target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b),
566560
},
567561
))
568562
}
@@ -573,7 +567,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
573567
Adjustment { kind: Adjust::Deref(None), target: ty_a },
574568
Adjustment {
575569
kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)),
576-
target: Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: mt_b, ty: ty_a }),
570+
target: Ty::new_ptr(self.tcx, ty_a, mt_b),
577571
},
578572
))
579573
}
@@ -990,7 +984,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
990984
coerce_mutbls(mt_a.mutbl, mutbl_b)?;
991985

992986
// Check that the types which they point at are compatible.
993-
let a_unsafe = Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: mutbl_b, ty: mt_a.ty });
987+
let a_unsafe = Ty::new_ptr(self.tcx, mt_a.ty, mutbl_b);
994988
// Although references and unsafe ptrs have the same
995989
// representation, we still register an Adjust::DerefRef so that
996990
// regionck knows that the region for `a` must be valid here.

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
442442
let ty =
443443
self.check_expr_with_expectation_and_needs(oprnd, hint, Needs::maybe_mut_place(mutbl));
444444

445-
let tm = ty::TypeAndMut { ty, mutbl };
446445
match kind {
447-
_ if tm.ty.references_error() => Ty::new_misc_error(self.tcx),
446+
_ if ty.references_error() => Ty::new_misc_error(self.tcx),
448447
hir::BorrowKind::Raw => {
449448
self.check_named_place_expr(oprnd);
450-
Ty::new_ptr(self.tcx, tm)
449+
Ty::new_ptr(self.tcx, ty, mutbl)
451450
}
452451
hir::BorrowKind::Ref => {
453452
// Note: at this point, we cannot say what the best lifetime
@@ -465,7 +464,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
465464
// whose address was taken can actually be made to live as long
466465
// as it needs to live.
467466
let region = self.next_region_var(infer::AddrOfRegion(expr.span));
468-
Ty::new_ref(self.tcx, region, tm)
467+
Ty::new_ref(self.tcx, region, ty, mutbl)
469468
}
470469
}
471470
}
@@ -3225,7 +3224,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32253224
self.demand_coerce(expr, ty, fnptr_ty, None, AllowTwoPhase::No);
32263225
}
32273226
ty::Ref(_, base_ty, mutbl) => {
3228-
let ptr_ty = Ty::new_ptr(self.tcx, ty::TypeAndMut { ty: base_ty, mutbl });
3227+
let ptr_ty = Ty::new_ptr(self.tcx, base_ty, mutbl);
32293228
self.demand_coerce(expr, ty, ptr_ty, None, AllowTwoPhase::No);
32303229
}
32313230
_ => {}

compiler/rustc_hir_typeck/src/mem_categorization.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
268268
adjustment::Adjust::Deref(overloaded) => {
269269
// Equivalent to *expr or something similar.
270270
let base = if let Some(deref) = overloaded {
271-
let ref_ty = Ty::new_ref(
272-
self.tcx(),
273-
deref.region,
274-
ty::TypeAndMut { ty: target, mutbl: deref.mutbl },
275-
);
271+
let ref_ty = Ty::new_ref(self.tcx(), deref.region, target, deref.mutbl);
276272
self.cat_rvalue(expr.hir_id, ref_ty)
277273
} else {
278274
previous()?
@@ -479,7 +475,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
479475
let ty::Ref(region, _, mutbl) = *base_ty.kind() else {
480476
span_bug!(expr.span, "cat_overloaded_place: base is not a reference");
481477
};
482-
let ref_ty = Ty::new_ref(self.tcx(), region, ty::TypeAndMut { ty: place_ty, mutbl });
478+
let ref_ty = Ty::new_ref(self.tcx(), region, place_ty, mutbl);
483479

484480
let base = self.cat_rvalue(expr.hir_id, ref_ty);
485481
self.cat_deref(expr, base)

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
188188
// Type we're wrapping in a reference, used later for unsizing
189189
let base_ty = target;
190190

191-
target = Ty::new_ref(self.tcx, region, ty::TypeAndMut { mutbl, ty: target });
191+
target = Ty::new_ref(self.tcx, region, target, mutbl);
192192

193193
// Method call receivers are the primary use case
194194
// for two-phase borrows.
@@ -208,11 +208,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
208208
base_ty
209209
)
210210
};
211-
target = Ty::new_ref(
212-
self.tcx,
213-
region,
214-
ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty },
215-
);
211+
target = Ty::new_ref(self.tcx, region, unsized_ty, mutbl.into());
216212
adjustments.push(Adjustment {
217213
kind: Adjust::Pointer(PointerCoercion::Unsize),
218214
target,

compiler/rustc_hir_typeck/src/method/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
200200
if let Some(span) = result.illegal_sized_bound {
201201
let mut needs_mut = false;
202202
if let ty::Ref(region, t_type, mutability) = self_ty.kind() {
203-
let trait_type = Ty::new_ref(
204-
self.tcx,
205-
*region,
206-
ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() },
207-
);
203+
let trait_type = Ty::new_ref(self.tcx, *region, *t_type, mutability.invert());
208204
// We probe again to see if there might be a borrow mutability discrepancy.
209205
match self.lookup_probe(
210206
segment.ident,

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12131213
// In general, during probing we erase regions.
12141214
let region = tcx.lifetimes.re_erased;
12151215

1216-
let autoref_ty = Ty::new_ref(tcx, region, ty::TypeAndMut { ty: self_ty, mutbl });
1216+
let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl);
12171217
self.pick_method(autoref_ty, unstable_candidates).map(|r| {
12181218
r.map(|mut pick| {
12191219
pick.autoderefs = step.autoderefs;

0 commit comments

Comments
 (0)