Skip to content

Commit b824865

Browse files
committed
Avoid needless copy of val
1 parent 6c7bf3b commit b824865

File tree

29 files changed

+63
-62
lines changed

29 files changed

+63
-62
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
5050
ConstKind::Value(_) => {}
5151
ConstKind::Unevaluated(unevaluated) => {
5252
if let Err(err) =
53-
fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None)
53+
fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), *unevaluated, None)
5454
{
5555
all_constants_ok = false;
5656
match err {
@@ -128,15 +128,15 @@ pub(crate) fn codegen_constant<'tcx>(
128128
ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty),
129129
};
130130
let const_val = match const_.val() {
131-
ConstKind::Value(const_val) => const_val,
131+
ConstKind::Value(const_val) => *const_val,
132132
ConstKind::Unevaluated(uv) if fx.tcx.is_static(uv.def.did) => {
133133
assert!(uv.substs(fx.tcx).is_empty());
134134
assert!(uv.promoted.is_none());
135135

136136
return codegen_static_ref(fx, uv.def.did, fx.layout_of(const_.ty())).to_cvalue(fx);
137137
}
138138
ConstKind::Unevaluated(unevaluated) => {
139-
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
139+
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), *unevaluated, None) {
140140
Ok(const_val) => const_val,
141141
Err(_) => {
142142
span_bug!(constant.span, "erroneous constant not captured by required_consts");

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3333
ty::ConstKind::Unevaluated(ct) => self
3434
.cx
3535
.tcx()
36-
.const_eval_resolve(ty::ParamEnv::reveal_all(), ct, None)
36+
.const_eval_resolve(ty::ParamEnv::reveal_all(), *ct, None)
3737
.map_err(|err| {
3838
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
3939
err
4040
}),
41-
ty::ConstKind::Value(value) => Ok(value),
41+
ty::ConstKind::Value(value) => Ok(*value),
4242
err => span_bug!(
4343
constant.span,
4444
"encountered bad ConstKind after monomorphizing: {:?}",

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
170170
};
171171
let val =
172172
self.tcx.const_eval_global_id(self.param_env, gid, Some(self.tcx.span))?;
173-
let val = self.const_val_to_op(val, ty, Some(dest.layout))?;
173+
let val = self.const_val_to_op(&val, ty, Some(dest.layout))?;
174174
self.copy_op(&val, dest)?;
175175
}
176176

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
573573
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
574574
match val {
575575
mir::ConstantKind::Ty(ct) => self.const_to_op(ct, layout),
576-
mir::ConstantKind::Val(val, ty) => self.const_val_to_op(*val, ty, layout),
576+
mir::ConstantKind::Val(val, ty) => self.const_val_to_op(val, ty, layout),
577577
}
578578
}
579579

580580
crate fn const_val_to_op(
581581
&self,
582-
val_val: ConstValue<'tcx>,
582+
val_val: &ConstValue<'tcx>,
583583
ty: Ty<'tcx>,
584584
layout: Option<TyAndLayout<'tcx>>,
585585
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
@@ -596,20 +596,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
596596
let id = self.tcx.create_memory_alloc(alloc);
597597
// We rely on mutability being set correctly in that allocation to prevent writes
598598
// where none should happen.
599-
let ptr = self.global_base_pointer(Pointer::new(id, offset))?;
599+
let ptr = self.global_base_pointer(Pointer::new(id, *offset))?;
600600
Operand::Indirect(MemPlace::from_ptr(ptr.into(), layout.align.abi))
601601
}
602-
ConstValue::Scalar(x) => Operand::Immediate(tag_scalar(x)?.into()),
602+
ConstValue::Scalar(x) => Operand::Immediate(tag_scalar(*x)?.into()),
603603
ConstValue::Slice { data, start, end } => {
604604
// We rely on mutability being set correctly in `data` to prevent writes
605605
// where none should happen.
606606
let ptr = Pointer::new(
607607
self.tcx.create_memory_alloc(data),
608-
Size::from_bytes(start), // offset: `start`
608+
Size::from_bytes(*start), // offset: `start`
609609
);
610610
Operand::Immediate(Immediate::new_slice(
611611
Scalar::from_pointer(self.global_base_pointer(ptr)?, &*self.tcx),
612-
u64::try_from(end.checked_sub(start).unwrap()).unwrap(), // len: `end - start`
612+
u64::try_from(end.checked_sub(*start).unwrap()).unwrap(), // len: `end - start`
613613
self,
614614
))
615615
}

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
413413
match ct.val() {
414414
ty::ConstKind::Infer(InferConst::Var(vid)) => {
415415
debug!("canonical: const var found with vid {:?}", vid);
416-
match self.infcx.probe_const_var(vid) {
416+
match self.infcx.probe_const_var(*vid) {
417417
Ok(c) => {
418418
debug!("(resolved to {:?})", c);
419419
return self.fold_const(c);
@@ -435,15 +435,15 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
435435
bug!("encountered a fresh const during canonicalization")
436436
}
437437
ty::ConstKind::Bound(debruijn, _) => {
438-
if debruijn >= self.binder_index {
438+
if *debruijn >= self.binder_index {
439439
bug!("escaping bound type during canonicalization")
440440
} else {
441441
return ct;
442442
}
443443
}
444444
ty::ConstKind::Placeholder(placeholder) => {
445445
return self.canonicalize_const_var(
446-
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderConst(placeholder) },
446+
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderConst(*placeholder) },
447447
ct,
448448
);
449449
}

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
442442
// ...in which case we would set `canonical_vars[0]` to `Some(const X)`.
443443

444444
// We only allow a `ty::INNERMOST` index in substitutions.
445-
assert_eq!(debrujin, ty::INNERMOST);
446-
opt_values[b] = Some(*original_value);
445+
assert_eq!(*debrujin, ty::INNERMOST);
446+
opt_values[*b] = Some(*original_value);
447447
}
448448
}
449449
}

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
149149
self.inner
150150
.borrow_mut()
151151
.const_unification_table()
152-
.unify_var_var(a_vid, b_vid)
152+
.unify_var_var(*a_vid, *b_vid)
153153
.map_err(|e| const_unification_error(a_is_expected, e))?;
154154
return Ok(a);
155155
}
@@ -161,11 +161,11 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
161161
}
162162

163163
(ty::ConstKind::Infer(InferConst::Var(vid)), _) => {
164-
return self.unify_const_variable(relation.param_env(), vid, b, a_is_expected);
164+
return self.unify_const_variable(relation.param_env(), *vid, b, a_is_expected);
165165
}
166166

167167
(_, ty::ConstKind::Infer(InferConst::Var(vid))) => {
168-
return self.unify_const_variable(relation.param_env(), vid, a, !a_is_expected);
168+
return self.unify_const_variable(relation.param_env(), *vid, a, !a_is_expected);
169169
}
170170
(ty::ConstKind::Unevaluated(..), _) if self.tcx.lazy_normalization() => {
171171
// FIXME(#59490): Need to remove the leak check to accommodate
@@ -726,7 +726,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
726726
ty::ConstKind::Infer(InferConst::Var(vid)) => {
727727
let mut inner = self.infcx.inner.borrow_mut();
728728
let variable_table = &mut inner.const_unification_table();
729-
let var_value = variable_table.probe_value(vid);
729+
let var_value = variable_table.probe_value(*vid);
730730
match var_value.val {
731731
ConstVariableValue::Known { value: u } => {
732732
drop(inner);
@@ -963,13 +963,13 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
963963
.inner
964964
.borrow_mut()
965965
.const_unification_table()
966-
.unioned(self.target_vid, vid)
966+
.unioned(self.target_vid, *vid)
967967
{
968968
return Err(TypeError::CyclicConst(c));
969969
}
970970

971971
let var_value =
972-
self.infcx.inner.borrow_mut().const_unification_table().probe_value(vid);
972+
self.infcx.inner.borrow_mut().const_unification_table().probe_value(*vid);
973973
match var_value.val {
974974
ConstVariableValue::Known { value: u } => self.consts(u, u),
975975
ConstVariableValue::Unknown { universe } => {

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
392392
GenericArgKind::Const(ct) => {
393393
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.val() {
394394
let origin =
395-
self.inner.borrow_mut().const_unification_table().probe_value(vid).origin;
395+
self.inner.borrow_mut().const_unification_table().probe_value(*vid).origin;
396396
if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) =
397397
origin.kind
398398
{

compiler/rustc_infer/src/infer/freshen.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,18 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
229229
.inner
230230
.borrow_mut()
231231
.const_unification_table()
232-
.probe_value(v)
232+
.probe_value(*v)
233233
.val
234234
.known();
235235
return self.freshen_const(
236236
opt_ct,
237-
ty::InferConst::Var(v),
237+
ty::InferConst::Var(*v),
238238
ty::InferConst::Fresh,
239239
ct.ty(),
240240
);
241241
}
242242
ty::ConstKind::Infer(ty::InferConst::Fresh(i)) => {
243-
if i >= self.const_freshen_count {
243+
if *i >= self.const_freshen_count {
244244
bug!(
245245
"Encountered a freshend const with id {} \
246246
but our counter is only at {}",

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ impl TyOrConstInferVar<'tcx> {
17351735
/// for constants other than `ty::ConstKind::Infer(_)` (or `InferConst::Fresh`).
17361736
pub fn maybe_from_const(ct: &'tcx ty::Const<'tcx>) -> Option<Self> {
17371737
match ct.val() {
1738-
ty::ConstKind::Infer(InferConst::Var(v)) => Some(TyOrConstInferVar::Const(v)),
1738+
ty::ConstKind::Infer(InferConst::Var(v)) => Some(TyOrConstInferVar::Const(*v)),
17391739
_ => None,
17401740
}
17411741
}
@@ -1760,7 +1760,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
17601760
.inner
17611761
.borrow_mut()
17621762
.const_unification_table()
1763-
.probe_value(vid)
1763+
.probe_value(*vid)
17641764
.val
17651765
.known()
17661766
.unwrap_or(ct)

0 commit comments

Comments
 (0)