Skip to content

Commit 81e7e80

Browse files
Eagerly convert some ctors to use their specialized ctors
1 parent 24db8ea commit 81e7e80

File tree

12 files changed

+31
-86
lines changed

12 files changed

+31
-86
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -663,11 +663,7 @@ pub(crate) fn codegen_drop<'tcx>(
663663

664664
let arg_value = drop_place.place_ref(
665665
fx,
666-
fx.layout_of(Ty::new_ref(
667-
fx.tcx,
668-
fx.tcx.lifetimes.re_erased,
669-
TypeAndMut { ty, mutbl: crate::rustc_hir::Mutability::Mut },
670-
)),
666+
fx.layout_of(Ty::new_mut_ref(fx.tcx, fx.tcx.lifetimes.re_erased, ty)),
671667
);
672668
let arg_value = adjust_arg_for_abi(fx, arg_value, &fn_abi.args[0], true);
673669

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
414414
calculate_debuginfo_offset(bx, var.projection, base);
415415

416416
// Create a variable which will be a pointer to the actual value
417-
let ptr_ty = Ty::new_ptr(
418-
bx.tcx(),
419-
ty::TypeAndMut { mutbl: mir::Mutability::Mut, ty: place.layout.ty },
420-
);
417+
let ptr_ty = Ty::new_mut_ptr(bx.tcx(), place.layout.ty);
421418
let ptr_layout = bx.layout_of(ptr_ty);
422419
let alloca = PlaceRef::alloca(bx, ptr_layout);
423420
bx.set_var_name(alloca.llval, &(var.name.to_string() + ".dbg.spill"));

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,9 @@ pub fn check_intrinsic_type(
240240
sym::prefetch_read_data
241241
| sym::prefetch_write_data
242242
| sym::prefetch_read_instruction
243-
| sym::prefetch_write_instruction => (
244-
1,
245-
0,
246-
vec![
247-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
248-
tcx.types.i32,
249-
],
250-
Ty::new_unit(tcx),
251-
),
243+
| sym::prefetch_write_instruction => {
244+
(1, 0, vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.i32], Ty::new_unit(tcx))
245+
}
252246
sym::needs_drop => (1, 0, vec![], tcx.types.bool),
253247

254248
sym::type_name => (1, 0, vec![], Ty::new_static_str(tcx)),
@@ -257,28 +251,22 @@ pub fn check_intrinsic_type(
257251
sym::arith_offset => (
258252
1,
259253
0,
260-
vec![
261-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
262-
tcx.types.isize,
263-
],
264-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
254+
vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.isize],
255+
Ty::new_imm_ptr(tcx, param(0)),
265256
),
266257
sym::ptr_mask => (
267258
1,
268259
0,
269-
vec![
270-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
271-
tcx.types.usize,
272-
],
273-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
260+
vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.usize],
261+
Ty::new_imm_ptr(tcx, param(0)),
274262
),
275263

276264
sym::copy | sym::copy_nonoverlapping => (
277265
1,
278266
0,
279267
vec![
280-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
281-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
268+
Ty::new_imm_ptr(tcx, param(0)),
269+
Ty::new_mut_ptr(tcx, param(0)),
282270
tcx.types.usize,
283271
],
284272
Ty::new_unit(tcx),
@@ -287,8 +275,8 @@ pub fn check_intrinsic_type(
287275
1,
288276
0,
289277
vec![
290-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
291-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
278+
Ty::new_mut_ptr(tcx, param(0)),
279+
Ty::new_imm_ptr(tcx, param(0)),
292280
tcx.types.usize,
293281
],
294282
Ty::new_unit(tcx),
@@ -300,11 +288,7 @@ pub fn check_intrinsic_type(
300288
sym::write_bytes | sym::volatile_set_memory => (
301289
1,
302290
0,
303-
vec![
304-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
305-
tcx.types.u8,
306-
tcx.types.usize,
307-
],
291+
vec![Ty::new_mut_ptr(tcx, param(0)), tcx.types.u8, tcx.types.usize],
308292
Ty::new_unit(tcx),
309293
),
310294

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
346346
} else if let ty::Ref(expr_reg, expr_ty, expr_mutbl) = *self.expr_ty.kind()
347347
&& expr_mutbl == Mutability::Not
348348
&& mutbl == Mutability::Mut
349-
&& fcx.can_coerce(
350-
Ty::new_ref(
351-
fcx.tcx,
352-
expr_reg,
353-
TypeAndMut { ty: expr_ty, mutbl: Mutability::Mut },
354-
),
355-
self.cast_ty,
356-
)
349+
&& fcx.can_coerce(Ty::new_mut_ref(fcx.tcx, expr_reg, expr_ty), self.cast_ty)
357350
{
358351
sugg_mutref = true;
359352
}

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
223223
target = match target.kind() {
224224
&ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => {
225225
assert!(mutbl.is_mut());
226-
Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: hir::Mutability::Not, ty })
226+
Ty::new_imm_ptr(self.tcx, ty)
227227
}
228228
other => panic!("Cannot adjust receiver type {other:?} to const ptr"),
229229
};

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,8 +1242,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12421242
return None;
12431243
};
12441244

1245-
let const_self_ty = ty::TypeAndMut { ty, mutbl: hir::Mutability::Not };
1246-
let const_ptr_ty = Ty::new_ptr(self.tcx, const_self_ty);
1245+
let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
12471246
self.pick_method(const_ptr_ty, unstable_candidates).map(|r| {
12481247
r.map(|mut pick| {
12491248
pick.autoderefs = step.autoderefs;

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_hir as hir;
21
use rustc_hir::lang_items::LangItem;
32
use rustc_index::Idx;
43
use rustc_middle::mir::patch::MirPatch;
@@ -629,11 +628,7 @@ where
629628
let drop_fn = tcx.associated_item_def_ids(drop_trait)[0];
630629
let ty = self.place_ty(self.place);
631630

632-
let ref_ty = Ty::new_ref(
633-
tcx,
634-
tcx.lifetimes.re_erased,
635-
ty::TypeAndMut { ty, mutbl: hir::Mutability::Mut },
636-
);
631+
let ref_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, ty);
637632
let ref_place = self.new_temp(ref_ty);
638633
let unit_temp = Place::from(self.new_temp(Ty::new_unit(tcx)));
639634

@@ -700,7 +695,7 @@ where
700695
let move_ = |place: Place<'tcx>| Operand::Move(place);
701696
let tcx = self.tcx();
702697

703-
let ptr_ty = Ty::new_ptr(tcx, ty::TypeAndMut { ty: ety, mutbl: hir::Mutability::Mut });
698+
let ptr_ty = Ty::new_mut_ptr(tcx, ety);
704699
let ptr = Place::from(self.new_temp(ptr_ty));
705700
let can_go = Place::from(self.new_temp(tcx.types.bool));
706701
let one = self.constant_usize(1);

compiler/rustc_mir_transform/src/check_alignment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::mir::{
55
interpret::Scalar,
66
visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor},
77
};
8-
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeAndMut};
8+
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
99
use rustc_session::Session;
1010

1111
pub struct CheckAlignment;
@@ -157,7 +157,7 @@ fn insert_alignment_check<'tcx>(
157157
new_block: BasicBlock,
158158
) {
159159
// Cast the pointer to a *const ()
160-
let const_raw_ptr = Ty::new_ptr(tcx, TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Not });
160+
let const_raw_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit);
161161
let rvalue = Rvalue::Cast(CastKind::PtrToPtr, Operand::Copy(pointer), const_raw_ptr);
162162
let thin_ptr = local_decls.push(LocalDecl::with_source_info(const_raw_ptr, source_info)).into();
163163
block_data

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
570570
fn make_coroutine_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
571571
let coroutine_ty = body.local_decls.raw[1].ty;
572572

573-
let ref_coroutine_ty = Ty::new_ref(
574-
tcx,
575-
tcx.lifetimes.re_erased,
576-
ty::TypeAndMut { ty: coroutine_ty, mutbl: Mutability::Mut },
577-
);
573+
let ref_coroutine_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, coroutine_ty);
578574

579575
// Replace the by value coroutine argument
580576
body.local_decls.raw[1].ty = ref_coroutine_ty;
@@ -1265,10 +1261,8 @@ fn create_coroutine_drop_shim<'tcx>(
12651261
make_coroutine_state_argument_indirect(tcx, &mut body);
12661262

12671263
// Change the coroutine argument from &mut to *mut
1268-
body.local_decls[SELF_ARG] = LocalDecl::with_source_info(
1269-
Ty::new_ptr(tcx, ty::TypeAndMut { ty: coroutine_ty, mutbl: hir::Mutability::Mut }),
1270-
source_info,
1271-
);
1264+
body.local_decls[SELF_ARG] =
1265+
LocalDecl::with_source_info(Ty::new_mut_ptr(tcx, coroutine_ty), source_info);
12721266

12731267
// Make sure we remove dead blocks to remove
12741268
// unrelated code from the resume part of the function

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,8 @@ impl<'tcx> CloneShimBuilder<'tcx> {
539539
const_: Const::zero_sized(func_ty),
540540
}));
541541

542-
let ref_loc = self.make_place(
543-
Mutability::Not,
544-
Ty::new_ref(
545-
tcx,
546-
tcx.lifetimes.re_erased,
547-
ty::TypeAndMut { ty, mutbl: hir::Mutability::Not },
548-
),
549-
);
542+
let ref_loc =
543+
self.make_place(Mutability::Not, Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, ty));
550544

551545
// `let ref_loc: &ty = &src;`
552546
let statement = self.make_statement(StatementKind::Assign(Box::new((
@@ -771,11 +765,7 @@ fn build_call_shim<'tcx>(
771765
// let rcvr = &mut rcvr;
772766
let ref_rcvr = local_decls.push(
773767
LocalDecl::new(
774-
Ty::new_ref(
775-
tcx,
776-
tcx.lifetimes.re_erased,
777-
ty::TypeAndMut { ty: sig.inputs()[0], mutbl: hir::Mutability::Mut },
778-
),
768+
Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, sig.inputs()[0]),
779769
span,
780770
)
781771
.immutable(),

src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,9 @@ fn check_other_call_arg<'tcx>(
336336
&& let Some((n_refs, receiver_ty)) = if n_refs > 0 || is_copy(cx, receiver_ty) {
337337
Some((n_refs, receiver_ty))
338338
} else if trait_predicate.def_id() != deref_trait_id {
339-
Some((1, Ty::new_ref(cx.tcx,
339+
Some((1, Ty::new_imm_ref(cx.tcx,
340340
cx.tcx.lifetimes.re_erased,
341-
ty::TypeAndMut {
342-
ty: receiver_ty,
343-
mutbl: Mutability::Not,
344-
},
341+
receiver_ty,
345342
)))
346343
} else {
347344
None

src/tools/miri/src/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
374374
fn new(layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, &'tcx LayoutError<'tcx>> {
375375
let tcx = layout_cx.tcx;
376376
let mut_raw_ptr =
377-
Ty::new_ptr(tcx, TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Mut });
377+
Ty::new_mut_ptr(tcx, tcx.types.unit);
378378
let const_raw_ptr =
379-
Ty::new_ptr(tcx, TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Not });
379+
Ty::new_imm_ptr(tcx, tcx.types.unit);
380380
Ok(Self {
381381
unit: layout_cx.layout_of(Ty::new_unit(tcx))?,
382382
i8: layout_cx.layout_of(tcx.types.i8)?,

0 commit comments

Comments
 (0)