Skip to content

Commit 7f93557

Browse files
committed
make ValueVisitor mut-polymorphic
1 parent dfbfd2c commit 7f93557

File tree

4 files changed

+210
-230
lines changed

4 files changed

+210
-230
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ fn validate_const<'a, 'tcx>(
535535
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
536536
) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
537537
let cid = key.value;
538-
let mut ecx = mk_eval_cx(tcx, cid.instance, key.param_env).unwrap();
538+
let ecx = mk_eval_cx(tcx, cid.instance, key.param_env).unwrap();
539539
let val = (|| {
540540
let op = ecx.const_to_op(constant)?;
541541
let mut ref_tracking = RefTracking::new(op);

src/librustc_mir/interpret/eval_context.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,34 @@ impl<'tcx, Tag> LocalValue<Tag> {
139139
}
140140
}
141141

142-
impl<'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout
143-
for &'b EvalContext<'a, 'mir, 'tcx, M>
142+
impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout
143+
for &EvalContext<'a, 'mir, 'tcx, M>
144144
{
145145
#[inline]
146146
fn data_layout(&self) -> &layout::TargetDataLayout {
147147
&self.tcx.data_layout
148148
}
149149
}
150150

151-
impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout
152-
for &'c &'b mut EvalContext<'a, 'mir, 'tcx, M>
151+
impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout
152+
for &&EvalContext<'a, 'mir, 'tcx, M>
153153
{
154154
#[inline]
155155
fn data_layout(&self) -> &layout::TargetDataLayout {
156156
&self.tcx.data_layout
157157
}
158158
}
159159

160-
impl<'b, 'a, 'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for &'b EvalContext<'a, 'mir, 'tcx, M>
160+
impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout
161+
for & &mut EvalContext<'a, 'mir, 'tcx, M>
162+
{
163+
#[inline]
164+
fn data_layout(&self) -> &layout::TargetDataLayout {
165+
&self.tcx.data_layout
166+
}
167+
}
168+
169+
impl<'a, 'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for &EvalContext<'a, 'mir, 'tcx, M>
161170
where M: Machine<'a, 'mir, 'tcx>
162171
{
163172
#[inline]
@@ -166,17 +175,17 @@ impl<'b, 'a, 'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for &'b EvalContext<'a, 'mir
166175
}
167176
}
168177

169-
impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> layout::HasTyCtxt<'tcx>
170-
for &'c &'b mut EvalContext<'a, 'mir, 'tcx, M>
178+
impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> layout::HasTyCtxt<'tcx>
179+
for & &mut EvalContext<'a, 'mir, 'tcx, M>
171180
{
172181
#[inline]
173182
fn tcx<'d>(&'d self) -> TyCtxt<'d, 'tcx, 'tcx> {
174183
*self.tcx
175184
}
176185
}
177186

178-
impl<'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> LayoutOf
179-
for &'b EvalContext<'a, 'mir, 'tcx, M>
187+
impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> LayoutOf
188+
for &EvalContext<'a, 'mir, 'tcx, M>
180189
{
181190
type Ty = Ty<'tcx>;
182191
type TyLayout = EvalResult<'tcx, TyLayout<'tcx>>;
@@ -188,8 +197,8 @@ impl<'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> LayoutOf
188197
}
189198
}
190199

191-
impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> LayoutOf
192-
for &'c &'b mut EvalContext<'a, 'mir, 'tcx, M>
200+
impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> LayoutOf
201+
for & &mut EvalContext<'a, 'mir, 'tcx, M>
193202
{
194203
type Ty = Ty<'tcx>;
195204
type TyLayout = EvalResult<'tcx, TyLayout<'tcx>>;

src/librustc_mir/interpret/validity.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ struct ValidityVisitor<'rt, 'a: 'rt, 'mir: 'rt, 'tcx: 'a+'rt+'mir, M: Machine<'a
129129
path: Vec<PathElem>,
130130
ref_tracking: Option<&'rt mut RefTracking<'tcx, M::PointerTag>>,
131131
const_mode: bool,
132-
ecx: &'rt mut EvalContext<'a, 'mir, 'tcx, M>,
132+
ecx: &'rt EvalContext<'a, 'mir, 'tcx, M>,
133133
}
134134

135135
impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> ValidityVisitor<'rt, 'a, 'mir, 'tcx, M> {
@@ -188,8 +188,8 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>
188188
type V = OpTy<'tcx, M::PointerTag>;
189189

190190
#[inline(always)]
191-
fn ecx(&mut self) -> &mut EvalContext<'a, 'mir, 'tcx, M> {
192-
&mut self.ecx
191+
fn ecx(&self) -> &EvalContext<'a, 'mir, 'tcx, M> {
192+
&self.ecx
193193
}
194194

195195
#[inline]
@@ -557,7 +557,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
557557
/// This also toggles between "run-time" (no recursion) and "compile-time" (with recursion)
558558
/// validation (e.g., pointer values are fine in integers at runtime).
559559
pub fn validate_operand(
560-
&mut self,
560+
&self,
561561
op: OpTy<'tcx, M::PointerTag>,
562562
path: Vec<PathElem>,
563563
ref_tracking: Option<&mut RefTracking<'tcx, M::PointerTag>>,

0 commit comments

Comments
 (0)