Skip to content

Commit 35f25bf

Browse files
committed
Reflow and fixup comments
1 parent 37db3db commit 35f25bf

File tree

9 files changed

+49
-31
lines changed

9 files changed

+49
-31
lines changed

src/librustc/mir/interpret/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ use std::num::NonZeroU32;
5050
pub enum Lock {
5151
NoLock,
5252
WriteLock(DynamicLifetime),
53-
/// This should never be empty -- that would be a read lock held and nobody there to release it...
53+
/// This should never be empty -- that would be a read lock held and nobody
54+
/// there to release it...
5455
ReadLock(Vec<DynamicLifetime>),
5556
}
5657

src/librustc_mir/interpret/cast.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
226226
Ok(Scalar::Bits { bits: v, size: 4 })
227227
},
228228

229-
// No alignment check needed for raw pointers. But we have to truncate to target ptr size.
229+
// No alignment check needed for raw pointers.
230+
// But we have to truncate to target ptr size.
230231
RawPtr(_) => {
231232
Ok(Scalar::Bits {
232233
bits: self.memory.truncate_to_ptr(v).0 as u128,
@@ -302,7 +303,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
302303
fn cast_from_ptr(&self, ptr: Pointer, ty: Ty<'tcx>) -> EvalResult<'tcx, Scalar> {
303304
use rustc::ty::TyKind::*;
304305
match ty.sty {
305-
// Casting to a reference or fn pointer is not permitted by rustc, no need to support it here.
306+
// Casting to a reference or fn pointer is not permitted by rustc,
307+
// no need to support it here.
306308
RawPtr(_) |
307309
Int(IntTy::Isize) |
308310
Uint(UintTy::Usize) => Ok(ptr.into()),

src/librustc_mir/interpret/eval_context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ pub struct Frame<'mir, 'tcx: 'mir> {
9292
pub return_place: Place,
9393

9494
/// The list of locals for this stack frame, stored in order as
95-
/// `[return_ptr, arguments..., variables..., temporaries...]`. The locals are stored as `Option<Value>`s.
95+
/// `[return_ptr, arguments..., variables..., temporaries...]`.
96+
/// The locals are stored as `Option<Value>`s.
9697
/// `None` represents a local that is currently dead, while a live local
9798
/// can either directly contain `Scalar` or refer to some part of an `Allocation`.
9899
pub locals: IndexVec<mir::Local, LocalValue>,
@@ -624,7 +625,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
624625
match frame.return_to_block {
625626
StackPopCleanup::MarkStatic(mutable) => {
626627
if let Place::Ptr(MemPlace { ptr, .. }) = frame.return_place {
627-
// FIXME: to_ptr()? might be too extreme here, static zsts might reach this under certain conditions
628+
// FIXME: to_ptr()? might be too extreme here,
629+
// static zsts might reach this under certain conditions
628630
self.memory.mark_static_initialized(
629631
ptr.to_ptr()?.alloc_id,
630632
mutable,

src/librustc_mir/interpret/memory.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
243243

244244
let alloc_kind = self.alloc_kind.remove(&ptr.alloc_id).expect("alloc_map out of sync with alloc_kind");
245245

246-
// It is okay for us to still holds locks on deallocation -- for example, we could store data we own
247-
// in a local, and the local could be deallocated (from StorageDead) before the function returns.
248-
// However, we should check *something*. For now, we make sure that there is no conflicting write
249-
// lock by another frame. We *have* to permit deallocation if we hold a read lock.
250-
// TODO: Figure out the exact rules here.
246+
// It is okay for us to still holds locks on deallocation -- for example, we could store
247+
// data we own in a local, and the local could be deallocated (from StorageDead) before the
248+
// function returns. However, we should check *something*. For now, we make sure that there
249+
// is no conflicting write lock by another frame. We *have* to permit deallocation if we
250+
// hold a read lock.
251+
// FIXME: Figure out the exact rules here.
251252
M::free_lock(self, ptr.alloc_id, alloc.bytes.len() as u64)?;
252253

253254
if alloc_kind != kind {
@@ -521,13 +522,15 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
521522
size: Size,
522523
align: Align,
523524
) -> EvalResult<'tcx, &[u8]> {
524-
// Zero-sized accesses can use dangling pointers, but they still have to be aligned and non-NULL
525+
// Zero-sized accesses can use dangling pointers,
526+
// but they still have to be aligned and non-NULL
525527
self.check_align(ptr.into(), align)?;
526528
if size.bytes() == 0 {
527529
return Ok(&[]);
528530
}
529531
M::check_locks(self, ptr, size, AccessKind::Read)?;
530-
self.check_bounds(ptr.offset(size, self)?, true)?; // if ptr.offset is in bounds, then so is ptr (because offset checks for overflow)
532+
// if ptr.offset is in bounds, then so is ptr (because offset checks for overflow)
533+
self.check_bounds(ptr.offset(size, self)?, true)?;
531534
let alloc = self.get(ptr.alloc_id)?;
532535
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
533536
assert_eq!(size.bytes() as usize as u64, size.bytes());
@@ -542,13 +545,15 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
542545
size: Size,
543546
align: Align,
544547
) -> EvalResult<'tcx, &mut [u8]> {
545-
// Zero-sized accesses can use dangling pointers, but they still have to be aligned and non-NULL
548+
// Zero-sized accesses can use dangling pointers,
549+
// but they still have to be aligned and non-NULL
546550
self.check_align(ptr.into(), align)?;
547551
if size.bytes() == 0 {
548552
return Ok(&mut []);
549553
}
550554
M::check_locks(self, ptr, size, AccessKind::Write)?;
551-
self.check_bounds(ptr.offset(size, &*self)?, true)?; // if ptr.offset is in bounds, then so is ptr (because offset checks for overflow)
555+
// if ptr.offset is in bounds, then so is ptr (because offset checks for overflow)
556+
self.check_bounds(ptr.offset(size, &*self)?, true)?;
552557
let alloc = self.get_mut(ptr.alloc_id)?;
553558
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
554559
assert_eq!(size.bytes() as usize as u64, size.bytes());
@@ -774,14 +779,16 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
774779

775780
/// Read a *non-ZST* scalar
776781
pub fn read_scalar(&self, ptr: Pointer, ptr_align: Align, size: Size) -> EvalResult<'tcx, ScalarMaybeUndef> {
777-
self.check_relocation_edges(ptr, size)?; // Make sure we don't read part of a pointer as a pointer
782+
// Make sure we don't read part of a pointer as a pointer
783+
self.check_relocation_edges(ptr, size)?;
778784
let endianness = self.endianness();
779785
// get_bytes_unchecked tests alignment
780786
let bytes = self.get_bytes_unchecked(ptr, size, ptr_align.min(self.int_align(size)))?;
781787
// Undef check happens *after* we established that the alignment is correct.
782788
// We must not return Ok() for unaligned pointers!
783789
if self.check_defined(ptr, size).is_err() {
784-
// this inflates undefined bytes to the entire scalar, even if only a few bytes are undefined
790+
// this inflates undefined bytes to the entire scalar,
791+
// even if only a few bytes are undefined
785792
return Ok(ScalarMaybeUndef::Undef);
786793
}
787794
// Now we do the actual reading

src/librustc_mir/interpret/place.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ impl MemPlace {
119119
/// Extract the ptr part of the mplace
120120
#[inline(always)]
121121
pub fn to_ptr(self) -> EvalResult<'tcx, Pointer> {
122-
// At this point, we forget about the alignment information -- the place has been turned into a reference,
123-
// and no matter where it came from, it now must be aligned.
122+
// At this point, we forget about the alignment information --
123+
// the place has been turned into a reference, and no matter where it came from,
124+
// it now must be aligned.
124125
self.to_scalar_ptr_align().0.to_ptr()
125126
}
126127

@@ -582,9 +583,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
582583
dest: MPlaceTy<'tcx>,
583584
) -> EvalResult<'tcx> {
584585
let (ptr, ptr_align) = dest.to_scalar_ptr_align();
585-
// Note that it is really important that the type here is the right one, and matches the type things are read at.
586-
// In case `src_val` is a `ScalarPair`, we don't do any magic here to handle padding properly, which is only
587-
// correct if we never look at this data with the wrong type.
586+
// Note that it is really important that the type here is the right one, and matches the
587+
// type things are read at. In case `src_val` is a `ScalarPair`, we don't do any magic here
588+
// to handle padding properly, which is only correct if we never look at this data with the
589+
// wrong type.
588590

589591
// Nothing to do for ZSTs, other than checking alignment
590592
if dest.layout.size.bytes() == 0 {

src/librustc_mir/interpret/step.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
108108

109109
use rustc::mir::StatementKind::*;
110110

111-
// Some statements (e.g. box) push new stack frames. We have to record the stack frame number
112-
// *before* executing the statement.
111+
// Some statements (e.g. box) push new stack frames.
112+
// We have to record the stack frame number *before* executing the statement.
113113
let frame_idx = self.cur_frame();
114114
self.tcx.span = stmt.source_info.span;
115115
self.memory.tcx.span = stmt.source_info.span;

src/librustc_mir/interpret/terminator/drop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
2424
target: BasicBlock,
2525
) -> EvalResult<'tcx> {
2626
trace!("drop_in_place: {:?},\n {:?}, {:?}", *place, place.layout.ty, instance);
27-
// We take the address of the object. This may well be unaligned, which is fine for us here.
28-
// However, unaligned accesses will probably make the actual drop implementation fail -- a problem shared
29-
// by rustc.
27+
// We take the address of the object. This may well be unaligned, which is fine for us
28+
// here. However, unaligned accesses will probably make the actual drop implementation fail
29+
// -- a problem shared by rustc.
3030
let place = self.force_allocation(place)?;
3131

3232
let (instance, place) = match place.layout.ty.sty {

src/librustc_mir/interpret/terminator/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,18 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
185185
DropAndReplace { .. } => unimplemented!(),
186186
Resume => unimplemented!(),
187187
Abort => unimplemented!(),
188-
FalseEdges { .. } => bug!("should have been eliminated by `simplify_branches` mir pass"),
189-
FalseUnwind { .. } => bug!("should have been eliminated by `simplify_branches` mir pass"),
188+
FalseEdges { .. } => bug!("should have been eliminated by\
189+
`simplify_branches` mir pass"),
190+
FalseUnwind { .. } => bug!("should have been eliminated by\
191+
`simplify_branches` mir pass"),
190192
Unreachable => return err!(Unreachable),
191193
}
192194

193195
Ok(())
194196
}
195197

196-
/// Decides whether it is okay to call the method with signature `real_sig` using signature `sig`.
198+
/// Decides whether it is okay to call the method with signature `real_sig`
199+
/// using signature `sig`.
197200
/// FIXME: This should take into account the platform-dependent ABI description.
198201
fn check_sig_compat(
199202
&mut self,
@@ -207,7 +210,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
207210
return match (&ty.sty, &real_ty.sty) {
208211
// Permit changing the pointer type of raw pointers and references as well as
209212
// mutability of raw pointers.
210-
// TODO: Should not be allowed when fat pointers are involved.
213+
// FIXME: Should not be allowed when fat pointers are involved.
211214
(&ty::RawPtr(_), &ty::RawPtr(_)) => true,
212215
(&ty::Ref(_, _, _), &ty::Ref(_, _, _)) => {
213216
ty.is_mutable_pointer() == real_ty.is_mutable_pointer()

src/librustc_mir/interpret/validity.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
265265
if value.layout.ty.builtin_deref(false).is_some() {
266266
trace!("Recursing below ptr {:#?}", value);
267267
let ptr_place = self.ref_to_mplace(value)?;
268-
// we have not encountered this pointer+layout combination before
268+
// we have not encountered this pointer+layout
269+
// combination before
269270
if seen.insert(ptr_place) {
270271
todo.push((ptr_place, path_clone_and_deref(path)));
271272
}

0 commit comments

Comments
 (0)