Skip to content

Commit 9b2b02a

Browse files
committed
Auto merge of #78313 - lcnr:somebody-fold-me, r=nikomatsakis
TypeFoldable: take self by value Implements rust-lang/compiler-team#371 which is currently still in FCP. r? `@nikomatsakis`
2 parents c6a6105 + 7f45668 commit 9b2b02a

File tree

164 files changed

+896
-853
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+896
-853
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
216216
assert!(!inst.substs.needs_infer());
217217
let fn_sig = tcx.normalize_erasing_late_bound_regions(
218218
ParamEnv::reveal_all(),
219-
&fn_sig_for_fn_abi(tcx, inst),
219+
fn_sig_for_fn_abi(tcx, inst),
220220
);
221221
if fn_sig.c_variadic && !support_vararg {
222222
tcx.sess.span_fatal(
@@ -372,7 +372,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
372372
.mir
373373
.args_iter()
374374
.map(|local| {
375-
let arg_ty = fx.monomorphize(&fx.mir.local_decls[local].ty);
375+
let arg_ty = fx.monomorphize(fx.mir.local_decls[local].ty);
376376

377377
// Adapted from https://github.com./rust-lang/rust/blob/145155dc96757002c7b2e9de8489416e2fdbbd57/src/librustc_codegen_llvm/mir/mod.rs#L442-L482
378378
if Some(local) == fx.mir.spread_arg {
@@ -470,7 +470,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
470470
}
471471

472472
for local in fx.mir.vars_and_temps_iter() {
473-
let ty = fx.monomorphize(&fx.mir.local_decls[local].ty);
473+
let ty = fx.monomorphize(fx.mir.local_decls[local].ty);
474474
let layout = fx.layout_of(ty);
475475

476476
let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
@@ -492,10 +492,10 @@ pub(crate) fn codegen_terminator_call<'tcx>(
492492
args: &[Operand<'tcx>],
493493
destination: Option<(Place<'tcx>, BasicBlock)>,
494494
) {
495-
let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.tcx));
495+
let fn_ty = fx.monomorphize(func.ty(fx.mir, fx.tcx));
496496
let fn_sig = fx
497497
.tcx
498-
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
498+
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), fn_ty.fn_sig(fx.tcx));
499499

500500
let destination = destination.map(|(place, bb)| (codegen_place(fx, place), bb));
501501

@@ -711,7 +711,7 @@ pub(crate) fn codegen_drop<'tcx>(
711711
let drop_fn_ty = drop_fn.ty(fx.tcx, ParamEnv::reveal_all());
712712
let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(
713713
ParamEnv::reveal_all(),
714-
&drop_fn_ty.fn_sig(fx.tcx),
714+
drop_fn_ty.fn_sig(fx.tcx),
715715
);
716716
assert_eq!(fn_sig.output(), fx.tcx.mk_unit());
717717

compiler/rustc_codegen_cranelift/src/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Module>) -> IndexVec<Local, S
1717
.local_decls
1818
.iter()
1919
.map(|local_decl| {
20-
let ty = fx.monomorphize(&local_decl.ty);
20+
let ty = fx.monomorphize(local_decl.ty);
2121
if fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some() {
2222
SsaKind::Ssa
2323
} else {

compiler/rustc_codegen_cranelift/src/base.rs

+27-28
Original file line numberDiff line numberDiff line change
@@ -445,43 +445,43 @@ fn codegen_stmt<'tcx>(
445445
StatementKind::Assign(to_place_and_rval) => {
446446
let lval = codegen_place(fx, to_place_and_rval.0);
447447
let dest_layout = lval.layout();
448-
match &to_place_and_rval.1 {
449-
Rvalue::Use(operand) => {
448+
match to_place_and_rval.1 {
449+
Rvalue::Use(ref operand) => {
450450
let val = codegen_operand(fx, operand);
451451
lval.write_cvalue(fx, val);
452452
}
453453
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
454-
let place = codegen_place(fx, *place);
454+
let place = codegen_place(fx, place);
455455
let ref_ = place.place_ref(fx, lval.layout());
456456
lval.write_cvalue(fx, ref_);
457457
}
458458
Rvalue::ThreadLocalRef(def_id) => {
459-
let val = crate::constant::codegen_tls_ref(fx, *def_id, lval.layout());
459+
let val = crate::constant::codegen_tls_ref(fx, def_id, lval.layout());
460460
lval.write_cvalue(fx, val);
461461
}
462-
Rvalue::BinaryOp(bin_op, lhs, rhs) => {
462+
Rvalue::BinaryOp(bin_op, ref lhs, ref rhs) => {
463463
let lhs = codegen_operand(fx, lhs);
464464
let rhs = codegen_operand(fx, rhs);
465465

466-
let res = crate::num::codegen_binop(fx, *bin_op, lhs, rhs);
466+
let res = crate::num::codegen_binop(fx, bin_op, lhs, rhs);
467467
lval.write_cvalue(fx, res);
468468
}
469-
Rvalue::CheckedBinaryOp(bin_op, lhs, rhs) => {
469+
Rvalue::CheckedBinaryOp(bin_op, ref lhs, ref rhs) => {
470470
let lhs = codegen_operand(fx, lhs);
471471
let rhs = codegen_operand(fx, rhs);
472472

473473
let res = if !fx.tcx.sess.overflow_checks() {
474474
let val =
475-
crate::num::codegen_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
475+
crate::num::codegen_int_binop(fx, bin_op, lhs, rhs).load_scalar(fx);
476476
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
477477
CValue::by_val_pair(val, is_overflow, lval.layout())
478478
} else {
479-
crate::num::codegen_checked_int_binop(fx, *bin_op, lhs, rhs)
479+
crate::num::codegen_checked_int_binop(fx, bin_op, lhs, rhs)
480480
};
481481

482482
lval.write_cvalue(fx, res);
483483
}
484-
Rvalue::UnaryOp(un_op, operand) => {
484+
Rvalue::UnaryOp(un_op, ref operand) => {
485485
let operand = codegen_operand(fx, operand);
486486
let layout = operand.layout();
487487
let val = operand.load_scalar(fx);
@@ -509,8 +509,8 @@ fn codegen_stmt<'tcx>(
509509
};
510510
lval.write_cvalue(fx, res);
511511
}
512-
Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), operand, to_ty) => {
513-
let from_ty = fx.monomorphize(&operand.ty(&fx.mir.local_decls, fx.tcx));
512+
Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), ref operand, to_ty) => {
513+
let from_ty = fx.monomorphize(operand.ty(&fx.mir.local_decls, fx.tcx));
514514
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
515515
match *from_ty.kind() {
516516
ty::FnDef(def_id, substs) => {
@@ -530,14 +530,14 @@ fn codegen_stmt<'tcx>(
530530
_ => bug!("Trying to ReifyFnPointer on non FnDef {:?}", from_ty),
531531
}
532532
}
533-
Rvalue::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), operand, to_ty)
534-
| Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, to_ty)
535-
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => {
533+
Rvalue::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), ref operand, to_ty)
534+
| Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), ref operand, to_ty)
535+
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), ref operand, to_ty) => {
536536
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
537537
let operand = codegen_operand(fx, operand);
538538
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
539539
}
540-
Rvalue::Cast(CastKind::Misc, operand, to_ty) => {
540+
Rvalue::Cast(CastKind::Misc, ref operand, to_ty) => {
541541
let operand = codegen_operand(fx, operand);
542542
let from_ty = operand.layout().ty;
543543
let to_ty = fx.monomorphize(to_ty);
@@ -577,12 +577,12 @@ fn codegen_stmt<'tcx>(
577577

578578
use rustc_target::abi::{Int, TagEncoding, Variants};
579579

580-
match &operand.layout().variants {
580+
match operand.layout().variants {
581581
Variants::Single { index } => {
582582
let discr = operand
583583
.layout()
584584
.ty
585-
.discriminant_for_variant(fx.tcx, *index)
585+
.discriminant_for_variant(fx.tcx, index)
586586
.unwrap();
587587
let discr = if discr.ty.is_signed() {
588588
fx.layout_of(discr.ty).size.sign_extend(discr.val)
@@ -595,7 +595,7 @@ fn codegen_stmt<'tcx>(
595595
lval.write_cvalue(fx, discr);
596596
}
597597
Variants::Multiple {
598-
tag,
598+
ref tag,
599599
tag_field,
600600
tag_encoding: TagEncoding::Direct,
601601
variants: _,
@@ -604,7 +604,7 @@ fn codegen_stmt<'tcx>(
604604

605605
// Read the tag/niche-encoded discriminant from memory.
606606
let encoded_discr =
607-
operand.value_field(fx, mir::Field::new(*tag_field));
607+
operand.value_field(fx, mir::Field::new(tag_field));
608608
let encoded_discr = encoded_discr.load_scalar(fx);
609609

610610
// Decode the discriminant (specifically if it's niche-encoded).
@@ -634,7 +634,7 @@ fn codegen_stmt<'tcx>(
634634
}
635635
Rvalue::Cast(
636636
CastKind::Pointer(PointerCast::ClosureFnPointer(_)),
637-
operand,
637+
ref operand,
638638
_to_ty,
639639
) => {
640640
let operand = codegen_operand(fx, operand);
@@ -654,18 +654,18 @@ fn codegen_stmt<'tcx>(
654654
_ => bug!("{} cannot be cast to a fn ptr", operand.layout().ty),
655655
}
656656
}
657-
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), operand, _to_ty) => {
657+
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), ref operand, _to_ty) => {
658658
let operand = codegen_operand(fx, operand);
659659
operand.unsize_value(fx, lval);
660660
}
661661
Rvalue::Discriminant(place) => {
662-
let place = codegen_place(fx, *place);
662+
let place = codegen_place(fx, place);
663663
let value = place.to_cvalue(fx);
664664
let discr =
665665
crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
666666
lval.write_cvalue(fx, discr);
667667
}
668-
Rvalue::Repeat(operand, times) => {
668+
Rvalue::Repeat(ref operand, times) => {
669669
let operand = codegen_operand(fx, operand);
670670
let times = fx
671671
.monomorphize(times)
@@ -704,7 +704,7 @@ fn codegen_stmt<'tcx>(
704704
}
705705
}
706706
Rvalue::Len(place) => {
707-
let place = codegen_place(fx, *place);
707+
let place = codegen_place(fx, place);
708708
let usize_layout = fx.layout_of(fx.tcx.types.usize);
709709
let len = codegen_array_len(fx, place);
710710
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
@@ -749,7 +749,7 @@ fn codegen_stmt<'tcx>(
749749
CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), ty_size.into());
750750
lval.write_cvalue(fx, val);
751751
}
752-
Rvalue::Aggregate(kind, operands) => match **kind {
752+
Rvalue::Aggregate(ref kind, ref operands) => match kind.as_ref() {
753753
AggregateKind::Array(_ty) => {
754754
for (i, operand) in operands.iter().enumerate() {
755755
let operand = codegen_operand(fx, operand);
@@ -877,8 +877,7 @@ fn codegen_array_len<'tcx>(
877877
match *place.layout().ty.kind() {
878878
ty::Array(_elem_ty, len) => {
879879
let len = fx
880-
.monomorphize(&len)
881-
.eval(fx.tcx, ParamEnv::reveal_all())
880+
.monomorphize(len)
882881
.eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64;
883882
fx.bcx.ins().iconst(fx.pointer_type, len)
884883
}

compiler/rustc_codegen_cranelift/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl<'tcx, M: Module> HasTargetSpec for FunctionCx<'_, 'tcx, M> {
357357
}
358358

359359
impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
360-
pub(crate) fn monomorphize<T>(&self, value: &T) -> T
360+
pub(crate) fn monomorphize<T>(&self, value: T) -> T
361361
where
362362
T: TypeFoldable<'tcx> + Copy,
363363
{

compiler/rustc_codegen_cranelift/src/constant.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl ConstantCx {
3838

3939
pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Module>) {
4040
for constant in &fx.mir.required_consts {
41-
let const_ = fx.monomorphize(&constant.literal);
41+
let const_ = fx.monomorphize(constant.literal);
4242
match const_.val {
4343
ConstKind::Value(_) => {}
4444
ConstKind::Unevaluated(def, ref substs, promoted) => {
@@ -110,7 +110,7 @@ pub(crate) fn codegen_constant<'tcx>(
110110
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
111111
constant: &Constant<'tcx>,
112112
) -> CValue<'tcx> {
113-
let const_ = fx.monomorphize(&constant.literal);
113+
let const_ = fx.monomorphize(constant.literal);
114114
let const_val = match const_.val {
115115
ConstKind::Value(const_val) => const_val,
116116
ConstKind::Unevaluated(def, ref substs, promoted) if fx.tcx.is_static(def.did) => {
@@ -466,7 +466,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
466466
match operand {
467467
Operand::Copy(_) | Operand::Move(_) => None,
468468
Operand::Constant(const_) => Some(
469-
fx.monomorphize(&const_.literal)
469+
fx.monomorphize(const_.literal)
470470
.eval(fx.tcx, ParamEnv::reveal_all()),
471471
),
472472
}

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<'tcx> DebugContext<'tcx> {
365365
let ty = self.tcx.subst_and_normalize_erasing_regions(
366366
instance.substs,
367367
ty::ParamEnv::reveal_all(),
368-
&mir.local_decls[local].ty,
368+
mir.local_decls[local].ty,
369369
);
370370
let var_id = self.define_local(entry_id, format!("{:?}", local), ty);
371371

compiler/rustc_codegen_cranelift/src/main_shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) fn maybe_create_entry_wrapper(
5050
// late-bound regions, since late-bound
5151
// regions must appear in the argument
5252
// listing.
53-
let main_ret_ty = tcx.erase_regions(&main_ret_ty.no_bound_vars().unwrap());
53+
let main_ret_ty = tcx.erase_regions(main_ret_ty.no_bound_vars().unwrap());
5454

5555
let cmain_sig = Signature {
5656
params: vec![

compiler/rustc_codegen_cranelift/src/pretty_clif.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl CommentWriter {
8080
"sig {:?}",
8181
tcx.normalize_erasing_late_bound_regions(
8282
ParamEnv::reveal_all(),
83-
&crate::abi::fn_sig_for_fn_abi(tcx, instance)
83+
crate::abi::fn_sig_for_fn_abi(tcx, instance)
8484
)
8585
),
8686
String::new(),

compiler/rustc_codegen_cranelift/src/value_and_place.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'tcx> CPlace<'tcx> {
455455
from_ty: Ty<'tcx>,
456456
to_ty: Ty<'tcx>,
457457
) {
458-
match (&from_ty.kind(), &to_ty.kind()) {
458+
match (from_ty.kind(), to_ty.kind()) {
459459
(ty::Ref(_, a, _), ty::Ref(_, b, _))
460460
| (
461461
ty::RawPtr(TypeAndMut { ty: a, mutbl: _ }),
@@ -466,11 +466,11 @@ impl<'tcx> CPlace<'tcx> {
466466
(ty::FnPtr(_), ty::FnPtr(_)) => {
467467
let from_sig = fx.tcx.normalize_erasing_late_bound_regions(
468468
ParamEnv::reveal_all(),
469-
&from_ty.fn_sig(fx.tcx),
469+
from_ty.fn_sig(fx.tcx),
470470
);
471471
let to_sig = fx.tcx.normalize_erasing_late_bound_regions(
472472
ParamEnv::reveal_all(),
473-
&to_ty.fn_sig(fx.tcx),
473+
to_ty.fn_sig(fx.tcx),
474474
);
475475
assert_eq!(
476476
from_sig, to_sig,
@@ -479,7 +479,7 @@ impl<'tcx> CPlace<'tcx> {
479479
);
480480
// fn(&T) -> for<'l> fn(&'l T) is allowed
481481
}
482-
(ty::Dynamic(from_traits, _), ty::Dynamic(to_traits, _)) => {
482+
(&ty::Dynamic(from_traits, _), &ty::Dynamic(to_traits, _)) => {
483483
let from_traits = fx
484484
.tcx
485485
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from_traits);

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn make_mir_scope(
9292
let callee = cx.tcx.subst_and_normalize_erasing_regions(
9393
instance.substs,
9494
ty::ParamEnv::reveal_all(),
95-
&callee,
95+
callee,
9696
);
9797
let callee_fn_abi = FnAbi::of_instance(cx, callee, &[]);
9898
cx.dbg_scope_fn(callee, &callee_fn_abi, None)

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl TypeMap<'ll, 'tcx> {
189189
// something that provides more than the 64 bits of the DefaultHasher.
190190
let mut hasher = StableHasher::new();
191191
let mut hcx = cx.tcx.create_stable_hashing_context();
192-
let type_ = cx.tcx.erase_regions(&type_);
192+
let type_ = cx.tcx.erase_regions(type_);
193193
hcx.while_hashing_spans(false, |hcx| {
194194
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
195195
type_.hash_stable(hcx, &mut hasher);
@@ -427,7 +427,7 @@ fn subroutine_type_metadata(
427427
span: Span,
428428
) -> MetadataCreationResult<'ll> {
429429
let signature =
430-
cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &signature);
430+
cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), signature);
431431

432432
let signature_metadata: Vec<_> = iter::once(
433433
// return type

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
501501
let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions(
502502
instance.substs,
503503
ty::ParamEnv::reveal_all(),
504-
&cx.tcx.type_of(impl_def_id),
504+
cx.tcx.type_of(impl_def_id),
505505
);
506506

507507
// Only "class" methods are generally understood by LLVM,

compiler/rustc_codegen_llvm/src/intrinsic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
9191
};
9292

9393
let sig = callee_ty.fn_sig(tcx);
94-
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
94+
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig);
9595
let arg_tys = sig.inputs();
9696
let ret_ty = sig.output();
9797
let name = tcx.item_name(def_id);
@@ -777,8 +777,8 @@ fn generic_simd_intrinsic(
777777
}
778778

779779
let tcx = bx.tcx();
780-
let sig = tcx
781-
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &callee_ty.fn_sig(tcx));
780+
let sig =
781+
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), callee_ty.fn_sig(tcx));
782782
let arg_tys = sig.inputs();
783783
let name_str = &*name.as_str();
784784

compiler/rustc_codegen_llvm/src/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
252252

253253
// Make sure lifetimes are erased, to avoid generating distinct LLVM
254254
// types for Rust types that only differ in the choice of lifetimes.
255-
let normal_ty = cx.tcx.erase_regions(&self.ty);
255+
let normal_ty = cx.tcx.erase_regions(self.ty);
256256

257257
let mut defer = None;
258258
let llty = if self.ty != normal_ty {

0 commit comments

Comments
 (0)