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

+3-3
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

+2-2
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

+1-1
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

+6-6
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

+3-3
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

+2-2
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

+6-6
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

+1-1
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

+3-3
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

+2-2
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)

compiler/rustc_infer/src/infer/nll_relate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ where
10081008
ty::ConstKind::Infer(InferConst::Var(vid)) => {
10091009
let mut inner = self.infcx.inner.borrow_mut();
10101010
let variable_table = &mut inner.const_unification_table();
1011-
let var_value = variable_table.probe_value(vid);
1011+
let var_value = variable_table.probe_value(*vid);
10121012
match var_value.val.known() {
10131013
Some(u) => self.relate(u, u),
10141014
None => {

compiler/rustc_infer/src/infer/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
241241
let c = self.infcx.shallow_resolve(c);
242242
match c.val() {
243243
ty::ConstKind::Infer(InferConst::Var(vid)) => {
244-
self.err = Some(FixupError::UnresolvedConst(vid));
244+
self.err = Some(FixupError::UnresolvedConst(*vid));
245245
return self.tcx().const_error(c.ty());
246246
}
247247
ty::ConstKind::Infer(InferConst::Fresh(_)) => {

compiler/rustc_middle/src/infer/unify_key.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ where
173173
L: UndoLogs<snapshot_vec::UndoLog<unify::Delegate<ty::ConstVid<'tcx>>>>,
174174
{
175175
if let ty::ConstKind::Infer(InferConst::Var(vid)) = c.val() {
176-
match table.probe_value(vid).val.known() {
176+
match table.probe_value(*vid).val.known() {
177177
Some(c) => c,
178178
None => c,
179179
}

compiler/rustc_middle/src/mir/interpret/value.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,12 @@ impl<'tcx, Tag: Provenance> ScalarMaybeUninit<Tag> {
587587
}
588588

589589
/// Gets the bytes of a constant slice value.
590-
pub fn get_slice_bytes<'tcx>(cx: &impl HasDataLayout, val: ConstValue<'tcx>) -> &'tcx [u8] {
590+
pub fn get_slice_bytes<'tcx>(cx: &impl HasDataLayout, val: &ConstValue<'tcx>) -> &'tcx [u8] {
591591
if let ConstValue::Slice { data, start, end } = val {
592-
let len = end - start;
592+
let len = *end - *start;
593593
data.get_bytes(
594594
cx,
595-
AllocRange { start: Size::from_bytes(start), size: Size::from_bytes(len) },
595+
AllocRange { start: Size::from_bytes(*start), size: Size::from_bytes(len) },
596596
)
597597
.unwrap_or_else(|err| bug!("const slice is invalid: {:?}", err))
598598
} else {

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ pub fn write_allocations<'tcx>(
669669
fn alloc_ids_from_alloc(alloc: &Allocation) -> impl DoubleEndedIterator<Item = AllocId> + '_ {
670670
alloc.relocations().values().map(|id| *id)
671671
}
672-
fn alloc_ids_from_const(val: ConstValue<'_>) -> impl Iterator<Item = AllocId> + '_ {
672+
fn alloc_ids_from_const<'a>(val: &'a ConstValue<'a>) -> impl Iterator<Item = AllocId> + 'a {
673673
match val {
674674
ConstValue::Scalar(interpret::Scalar::Ptr(ptr, _size)) => {
675675
Either::Left(Either::Left(std::iter::once(ptr.provenance)))

compiler/rustc_middle/src/ty/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl<'tcx> Const<'tcx> {
3838
}
3939

4040
#[inline]
41-
pub fn val(&self) -> ConstKind<'tcx> {
42-
self.val
41+
pub fn val(&self) -> &ConstKind<'tcx> {
42+
&self.val
4343
}
4444

4545
/// Literals and const generic parameters are eagerly converted to a constant, everything else

compiler/rustc_middle/src/ty/relate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
565565
// Currently, the values that can be unified are primitive types,
566566
// and those that derive both `PartialEq` and `Eq`, corresponding
567567
// to structural-match types.
568-
let is_match = match (a.val, b.val) {
568+
let is_match = match (a.val(), b.val()) {
569569
(ty::ConstKind::Infer(_), _) | (_, ty::ConstKind::Infer(_)) => {
570570
// The caller should handle these cases!
571571
bug!("var types encountered in super_relate_consts: {:?} {:?}", a, b)
@@ -614,8 +614,8 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
614614

615615
fn check_const_value_eq<R: TypeRelation<'tcx>>(
616616
relation: &mut R,
617-
a_val: ConstValue<'tcx>,
618-
b_val: ConstValue<'tcx>,
617+
a_val: &ConstValue<'tcx>,
618+
b_val: &ConstValue<'tcx>,
619619
// FIXME(oli-obk): these arguments should go away with valtrees
620620
a: &'tcx ty::Const<'tcx>,
621621
b: &'tcx ty::Const<'tcx>,

compiler/rustc_monomorphize/src/collector.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,10 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
719719
let val = match literal {
720720
mir::ConstantKind::Val(val, _) => val,
721721
mir::ConstantKind::Ty(ct) => match ct.val() {
722-
ty::ConstKind::Value(val) => val,
722+
ty::ConstKind::Value(val) => *val,
723723
ty::ConstKind::Unevaluated(ct) => {
724724
let param_env = ty::ParamEnv::reveal_all();
725-
match self.tcx.const_eval_resolve(param_env, ct, None) {
725+
match self.tcx.const_eval_resolve(param_env, *ct, None) {
726726
// The `monomorphize` call should have evaluated that constant already.
727727
Ok(val) => val,
728728
Err(ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted) => return,
@@ -747,9 +747,9 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
747747
let param_env = ty::ParamEnv::reveal_all();
748748

749749
match substituted_constant.val() {
750-
ty::ConstKind::Value(val) => collect_const_value(self.tcx, val, self.output),
750+
ty::ConstKind::Value(val) => collect_const_value(self.tcx, *val, self.output),
751751
ty::ConstKind::Unevaluated(unevaluated) => {
752-
match self.tcx.const_eval_resolve(param_env, unevaluated, None) {
752+
match self.tcx.const_eval_resolve(param_env, *unevaluated, None) {
753753
// The `monomorphize` call should have evaluated that constant already.
754754
Ok(val) => span_bug!(
755755
self.body.source_info(location).span,

compiler/rustc_monomorphize/src/polymorphize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
300300
// If there is a promoted, don't look at the substs - since it will always contain
301301
// the generic parameters, instead, traverse the promoted MIR.
302302
let promoted = self.tcx.promoted_mir(def.did);
303-
self.visit_body(&promoted[p]);
303+
self.visit_body(&promoted[*p]);
304304
ControlFlow::CONTINUE
305305
}
306306
ty::ConstKind::Unevaluated(uv)

compiler/rustc_symbol_mangling/src/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> {
632632
// relocations (we have an active `str` reference here). We don't use this
633633
// result to affect interpreter execution.
634634
let slice =
635-
data.inspect_with_uninit_and_ptr_outside_interpreter(start..end);
635+
data.inspect_with_uninit_and_ptr_outside_interpreter(*start..*end);
636636
let s = std::str::from_utf8(slice).expect("non utf8 str from miri");
637637

638638
self.push("e");

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ impl AutoTraitFinder<'tcx> {
809809
if let ty::ConstKind::Unevaluated(unevaluated) = c.val() {
810810
match select.infcx().const_eval_resolve(
811811
obligation.param_env,
812-
unevaluated,
812+
*unevaluated,
813813
Some(obligation.cause.span),
814814
) {
815815
Ok(val) => Ok(ty::Const::from_value(select.tcx(), val, c.ty())),

compiler/rustc_trait_selection/src/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
598598
if let ty::ConstKind::Unevaluated(unevaluated) = c.val() {
599599
match self.selcx.infcx().const_eval_resolve(
600600
obligation.param_env,
601-
unevaluated,
601+
*unevaluated,
602602
Some(obligation.cause.span),
603603
) {
604604
Ok(val) => Ok(Const::from_value(self.selcx.tcx(), val, c.ty())),

0 commit comments

Comments
 (0)