Skip to content

Commit 22d3f66

Browse files
committed
Fixup long code lines
1 parent 35f25bf commit 22d3f66

File tree

8 files changed

+91
-31
lines changed

8 files changed

+91
-31
lines changed

src/librustc_mir/interpret/cast.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
240240
}
241241
}
242242

243-
fn cast_from_float(&self, bits: u128, fty: FloatTy, dest_ty: Ty<'tcx>) -> EvalResult<'tcx, Scalar> {
243+
fn cast_from_float(
244+
&self,
245+
bits: u128,
246+
fty: FloatTy,
247+
dest_ty: Ty<'tcx>
248+
) -> EvalResult<'tcx, Scalar> {
244249
use rustc::ty::TyKind::*;
245250
use rustc_apfloat::FloatConvert;
246251
match dest_ty.sty {

src/librustc_mir/interpret/eval_context.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout
280280
}
281281
}
282282

283-
impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> layout::HasTyCtxt<'tcx> for &'a EvalContext<'a, 'mir, 'tcx, M> {
283+
impl<'a, 'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for &'a EvalContext<'a, 'mir, 'tcx, M>
284+
where M: Machine<'mir, 'tcx>
285+
{
284286
#[inline]
285287
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
286288
*self.tcx
@@ -340,7 +342,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
340342

341343
pub(crate) fn with_fresh_body<F: FnOnce(&mut Self) -> R, R>(&mut self, f: F) -> R {
342344
let stack = mem::replace(&mut self.stack, Vec::new());
343-
let steps = mem::replace(&mut self.steps_since_detector_enabled, -STEPS_UNTIL_DETECTOR_ENABLED);
345+
let steps = mem::replace(&mut self.steps_since_detector_enabled,
346+
-STEPS_UNTIL_DETECTOR_ENABLED);
344347
let r = f(self);
345348
self.stack = stack;
346349
self.steps_since_detector_enabled = steps;
@@ -389,7 +392,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
389392
Ok(Value::new_slice(Scalar::Ptr(ptr), s.len() as u64, self.tcx.tcx))
390393
}
391394

392-
pub(super) fn resolve(&self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> EvalResult<'tcx, ty::Instance<'tcx>> {
395+
pub(super) fn resolve(&self, def_id: DefId, substs: &'tcx Substs<'tcx>)
396+
-> EvalResult<'tcx, ty::Instance<'tcx>> {
393397
trace!("resolve: {:?}, {:#?}", def_id, substs);
394398
trace!("substs: {:#?}", self.substs());
395399
trace!("param_env: {:#?}", self.param_env);
@@ -416,7 +420,9 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
416420
) -> EvalResult<'tcx, &'tcx mir::Mir<'tcx>> {
417421
// do not continue if typeck errors occurred (can only occur in local crate)
418422
let did = instance.def_id();
419-
if did.is_local() && self.tcx.has_typeck_tables(did) && self.tcx.typeck_tables_of(did).tainted_by_errors {
423+
if did.is_local()
424+
&& self.tcx.has_typeck_tables(did)
425+
&& self.tcx.typeck_tables_of(did).tainted_by_errors {
420426
return err!(TypeckError);
421427
}
422428
trace!("load mir {:?}", instance);
@@ -663,7 +669,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
663669
} else {
664670
self.param_env
665671
};
666-
self.tcx.const_eval(param_env.and(gid)).map_err(|err| EvalErrorKind::ReferencedConstant(err).into())
672+
self.tcx.const_eval(param_env.and(gid))
673+
.map_err(|err| EvalErrorKind::ReferencedConstant(err).into())
667674
}
668675

669676
#[inline(always)]
@@ -769,7 +776,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
769776
} else {
770777
last_span = Some(span);
771778
}
772-
let location = if self.tcx.def_key(instance.def_id()).disambiguated_data.data == DefPathData::ClosureExpr {
779+
let location = if self.tcx.def_key(instance.def_id()).disambiguated_data.data
780+
== DefPathData::ClosureExpr {
773781
"closure".to_owned()
774782
} else {
775783
instance.to_string()

src/librustc_mir/interpret/memory.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
241241
}
242242
};
243243

244-
let alloc_kind = self.alloc_kind.remove(&ptr.alloc_id).expect("alloc_map out of sync with alloc_kind");
244+
let alloc_kind = self.alloc_kind
245+
.remove(&ptr.alloc_id)
246+
.expect("alloc_map out of sync with alloc_kind");
245247

246248
// It is okay for us to still holds locks on deallocation -- for example, we could store
247249
// data we own in a local, and the local could be deallocated (from StorageDead) before the
@@ -259,7 +261,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
259261
}
260262
if let Some((size, align)) = size_and_align {
261263
if size.bytes() != alloc.bytes.len() as u64 || align != alloc.align {
262-
return err!(IncorrectAllocationInformation(size, Size::from_bytes(alloc.bytes.len() as u64), align, alloc.align));
264+
let bytes = Size::from_bytes(alloc.bytes.len() as u64);
265+
return err!(IncorrectAllocationInformation(size,
266+
bytes,
267+
align,
268+
alloc.align));
263269
}
264270
}
265271

@@ -678,7 +684,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
678684
relocations
679685
.iter()
680686
.map(|&(offset, alloc_id)| {
681-
(offset + dest.offset - src.offset + (i * size * relocations.len() as u64), alloc_id)
687+
(offset + dest.offset - src.offset + (i * size * relocations.len() as u64),
688+
alloc_id)
682689
})
683690
);
684691
}
@@ -707,11 +714,15 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
707714
}
708715

709716
for i in 0..length {
710-
ptr::copy(src_bytes, dest_bytes.offset((size.bytes() * i) as isize), size.bytes() as usize);
717+
ptr::copy(src_bytes,
718+
dest_bytes.offset((size.bytes() * i) as isize),
719+
size.bytes() as usize);
711720
}
712721
} else {
713722
for i in 0..length {
714-
ptr::copy_nonoverlapping(src_bytes, dest_bytes.offset((size.bytes() * i) as isize), size.bytes() as usize);
723+
ptr::copy_nonoverlapping(src_bytes,
724+
dest_bytes.offset((size.bytes() * i) as isize),
725+
size.bytes() as usize);
715726
}
716727
}
717728
}
@@ -778,7 +789,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
778789
}
779790

780791
/// Read a *non-ZST* scalar
781-
pub fn read_scalar(&self, ptr: Pointer, ptr_align: Align, size: Size) -> EvalResult<'tcx, ScalarMaybeUndef> {
792+
pub fn read_scalar(&self, ptr: Pointer, ptr_align: Align, size: Size)
793+
-> EvalResult<'tcx, ScalarMaybeUndef> {
782794
// Make sure we don't read part of a pointer as a pointer
783795
self.check_relocation_edges(ptr, size)?;
784796
let endianness = self.endianness();
@@ -801,7 +813,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
801813
} else {
802814
let alloc = self.get(ptr.alloc_id)?;
803815
match alloc.relocations.get(&ptr.offset) {
804-
Some(&alloc_id) => return Ok(ScalarMaybeUndef::Scalar(Pointer::new(alloc_id, Size::from_bytes(bits as u64)).into())),
816+
Some(&alloc_id) => {
817+
let ptr = Pointer::new(alloc_id, Size::from_bytes(bits as u64));
818+
return Ok(ScalarMaybeUndef::Scalar(ptr.into()))
819+
}
805820
None => {},
806821
}
807822
}
@@ -812,7 +827,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
812827
}))
813828
}
814829

815-
pub fn read_ptr_sized(&self, ptr: Pointer, ptr_align: Align) -> EvalResult<'tcx, ScalarMaybeUndef> {
830+
pub fn read_ptr_sized(&self, ptr: Pointer, ptr_align: Align)
831+
-> EvalResult<'tcx, ScalarMaybeUndef> {
816832
self.read_scalar(ptr, ptr_align, self.pointer_size())
817833
}
818834

@@ -865,7 +881,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
865881
Ok(())
866882
}
867883

868-
pub fn write_ptr_sized(&mut self, ptr: Pointer, ptr_align: Align, val: ScalarMaybeUndef) -> EvalResult<'tcx> {
884+
pub fn write_ptr_sized(&mut self, ptr: Pointer, ptr_align: Align, val: ScalarMaybeUndef)
885+
-> EvalResult<'tcx> {
869886
let ptr_size = self.pointer_size();
870887
self.write_scalar(ptr.into(), ptr_align, val, ptr_size)
871888
}
@@ -1009,7 +1026,9 @@ pub trait HasMemory<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> {
10091026
fn memory(&self) -> &Memory<'a, 'mir, 'tcx, M>;
10101027
}
10111028

1012-
impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> HasMemory<'a, 'mir, 'tcx, M> for Memory<'a, 'mir, 'tcx, M> {
1029+
impl<'a, 'mir, 'tcx, M> HasMemory<'a, 'mir, 'tcx, M> for Memory<'a, 'mir, 'tcx, M>
1030+
where M: Machine<'mir, 'tcx>
1031+
{
10131032
#[inline]
10141033
fn memory_mut(&mut self) -> &mut Memory<'a, 'mir, 'tcx, M> {
10151034
self
@@ -1021,7 +1040,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> HasMemory<'a, 'mir, 'tcx, M> for Me
10211040
}
10221041
}
10231042

1024-
impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> HasMemory<'a, 'mir, 'tcx, M> for EvalContext<'a, 'mir, 'tcx, M> {
1043+
impl<'a, 'mir, 'tcx, M> HasMemory<'a, 'mir, 'tcx, M> for EvalContext<'a, 'mir, 'tcx, M>
1044+
where M: Machine<'mir, 'tcx>
1045+
{
10251046
#[inline]
10261047
fn memory_mut(&mut self) -> &mut Memory<'a, 'mir, 'tcx, M> {
10271048
&mut self.memory
@@ -1033,7 +1054,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> HasMemory<'a, 'mir, 'tcx, M> for Ev
10331054
}
10341055
}
10351056

1036-
impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> layout::HasDataLayout for &'a Memory<'a, 'mir, 'tcx, M> {
1057+
impl<'a, 'mir, 'tcx, M> layout::HasDataLayout for &'a Memory<'a, 'mir, 'tcx, M>
1058+
where M: Machine<'mir, 'tcx>
1059+
{
10371060
#[inline]
10381061
fn data_layout(&self) -> &TargetDataLayout {
10391062
&self.tcx.data_layout

src/librustc_mir/interpret/operator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
6868
layout::Abi::Scalar(ref scalar) => scalar.value,
6969
_ => return err!(TypeNotPrimitive(right_layout.ty)),
7070
};
71-
trace!("Running binary op {:?}: {:?} ({:?}), {:?} ({:?})", bin_op, left, left_kind, right, right_kind);
71+
trace!("Running binary op {:?}: {:?} ({:?}), {:?} ({:?})",
72+
bin_op, left, left_kind, right, right_kind);
7273

7374
// I: Handle operations that support pointers
7475
if !left_kind.is_float() && !right_kind.is_float() {

src/librustc_mir/interpret/place.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
287287
offsets[usize::try_from(field).unwrap()],
288288
layout::FieldPlacement::Array { stride, .. } => {
289289
let len = base.len();
290-
assert!(field < len, "Tried to access element {} of array/slice with length {}", field, len);
290+
assert!(field < len,
291+
"Tried to access element {} of array/slice with length {}", field, len);
291292
stride * field
292293
}
293294
layout::FieldPlacement::Union(count) => {
294-
assert!(field < count as u64, "Tried to access field {} of union with {} fields", field, count);
295+
assert!(field < count as u64,
296+
"Tried to access field {} of union with {} fields", field, count);
295297
// Offset is always 0
296298
Size::from_bytes(0)
297299
}
@@ -604,7 +606,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
604606
Value::ScalarPair(a_val, b_val) => {
605607
let (a, b) = match dest.layout.abi {
606608
layout::Abi::ScalarPair(ref a, ref b) => (&a.value, &b.value),
607-
_ => bug!("write_value_to_mplace: invalid ScalarPair layout: {:#?}", dest.layout)
609+
_ => bug!("write_value_to_mplace: invalid ScalarPair layout: {:#?}",
610+
dest.layout)
608611
};
609612
let (a_size, b_size) = (a.size(&self), b.size(&self));
610613
let (a_align, b_align) = (a.align(&self), b.align(&self));
@@ -770,7 +773,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
770773
/// Turn a place that is a dyn trait (i.e., PlaceExtra::Vtable and the appropriate layout)
771774
/// or a slice into the specific fixed-size place and layout that is given by the vtable/len.
772775
/// This "unpacks" the existential quantifier, so to speak.
773-
pub fn unpack_unsized_mplace(&self, mplace: MPlaceTy<'tcx>) -> EvalResult<'tcx, MPlaceTy<'tcx>> {
776+
pub fn unpack_unsized_mplace(&self, mplace: MPlaceTy<'tcx>)
777+
-> EvalResult<'tcx, MPlaceTy<'tcx>> {
774778
trace!("Unpacking {:?} ({:?})", *mplace, mplace.layout.ty);
775779
let layout = match mplace.extra {
776780
PlaceExtra::Vtable(vtable) => {

src/librustc_mir/interpret/terminator/mod.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
5555

5656
for (index, &const_int) in values.iter().enumerate() {
5757
// Compare using binary_op
58-
let const_int = Scalar::Bits { bits: const_int, size: discr.layout.size.bytes() as u8 };
58+
let const_int = Scalar::Bits {
59+
bits: const_int,
60+
size: discr.layout.size.bytes() as u8
61+
};
5962
let (res, _) = self.binary_op(mir::BinOp::Eq,
6063
discr,
6164
ValTy { value: Value::Scalar(const_int.into()), layout: discr.layout }
@@ -154,7 +157,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
154157
target,
155158
..
156159
} => {
157-
let cond_val = self.eval_operand_and_read_value(cond, None)?.to_scalar()?.to_bool()?;
160+
let cond_val = self.eval_operand_and_read_value(cond, None)?
161+
.to_scalar()?
162+
.to_bool()?;
158163
if expected == cond_val {
159164
self.goto_block(target);
160165
} else {
@@ -239,15 +244,24 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
239244
// We need to allow what comes up when a non-capturing closure is cast to a fn().
240245
match (sig.abi, real_sig.abi) {
241246
(Abi::Rust, Abi::RustCall) // check the ABIs. This makes the test here non-symmetric.
242-
if check_ty_compat(sig.output(), real_sig.output()) && real_sig.inputs_and_output.len() == 3 => {
247+
if check_ty_compat(sig.output(), real_sig.output())
248+
&& real_sig.inputs_and_output.len() == 3 => {
243249
// First argument of real_sig must be a ZST
244250
let fst_ty = real_sig.inputs_and_output[0];
245251
if self.layout_of(fst_ty)?.is_zst() {
246252
// Second argument must be a tuple matching the argument list of sig
247253
let snd_ty = real_sig.inputs_and_output[1];
248254
match snd_ty.sty {
255+
<<<<<<< HEAD
249256
ty::Tuple(tys) if sig.inputs().len() == tys.len() =>
250257
if sig.inputs().iter().zip(tys).all(|(ty, real_ty)| check_ty_compat(ty, real_ty)) {
258+
=======
259+
ty::TyTuple(tys) if sig.inputs().len() == tys.len() =>
260+
if sig.inputs()
261+
.iter()
262+
.zip(tys)
263+
.all(|(ty, real_ty)| check_ty_compat(ty, real_ty)) {
264+
>>>>>>> 7d30ba9... Fixup long code lines
251265
return Ok(true)
252266
},
253267
_ => {}
@@ -304,7 +318,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
304318
trace!(
305319
"args: {:#?}",
306320
self.frame().mir.args_iter().zip(args.iter())
307-
.map(|(local, arg)| (local, **arg, arg.layout.ty)).collect::<Vec<_>>()
321+
.map(|(local, arg)| (local, **arg, arg.layout.ty))
322+
.collect::<Vec<_>>()
308323
);
309324
let local = arg_locals.nth(1).unwrap();
310325
for (i, &op) in args.into_iter().enumerate() {
@@ -325,7 +340,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
325340
ty::InstanceDef::Item(_) => {
326341
// Push the stack frame, and potentially be entirely done if the call got hooked
327342
if M::eval_fn_call(self, instance, destination, args, span)? {
328-
// TODO: Can we make it return the frame to push, instead
343+
// FIXME: Can we make it return the frame to push, instead
329344
// of the hook doing half of the work and us doing the argument
330345
// initialization?
331346
return Ok(());

src/librustc_mir/interpret/traits.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
9292
) -> EvalResult<'tcx, (Size, Align)> {
9393
let pointer_size = self.memory.pointer_size();
9494
let pointer_align = self.tcx.data_layout.pointer_align;
95-
let size = self.memory.read_ptr_sized(vtable.offset(pointer_size, self)?, pointer_align)?.to_bits(pointer_size)? as u64;
95+
let size = self.memory.read_ptr_sized(vtable.offset(pointer_size, self)?,pointer_align)?
96+
.to_bits(pointer_size)? as u64;
9697
let align = self.memory.read_ptr_sized(
9798
vtable.offset(pointer_size * 2, self)?,
9899
pointer_align

src/librustc_mir/interpret/validity.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
221221
let variant = self.read_discriminant_as_variant_index(dest.into())?;
222222
let inner_dest = self.mplace_downcast(dest, variant)?;
223223
// Put the variant projection onto the path, as a field
224-
path.push(PathElem::Field(dest.layout.ty.ty_adt_def().unwrap().variants[variant].name));
224+
path.push(PathElem::Field(dest.layout.ty
225+
.ty_adt_def()
226+
.unwrap()
227+
.variants[variant].name));
225228
trace!("variant layout: {:#?}", dest.layout);
226229
(variant, inner_dest)
227230
},

0 commit comments

Comments
 (0)