Skip to content

Commit b0006df

Browse files
author
Alexander Regueiro
committed
A few cosmetic improvements to code & comments in liballoc and libcore
1 parent 1fb3c4e commit b0006df

File tree

13 files changed

+109
-111
lines changed

13 files changed

+109
-111
lines changed

src/liballoc/collections/linked_list/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ fn test_append() {
102102
assert_eq!(m.pop_front(), Some(elt))
103103
}
104104
assert_eq!(n.len(), 0);
105-
// let's make sure it's working properly, since we
106-
// did some direct changes to private members
105+
// Let's make sure it's working properly, since we
106+
// did some direct changes to private members.
107107
n.push_back(3);
108108
assert_eq!(n.len(), 1);
109109
assert_eq!(n.pop_front(), Some(3));

src/liballoc/raw_vec.rs

+74-76
Large diffs are not rendered by default.

src/liballoc/raw_vec/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ fn allocator_param() {
55
use crate::alloc::AllocErr;
66

77
// Writing a test of integration between third-party
8-
// allocators and RawVec is a little tricky because the RawVec
8+
// allocators and `RawVec` is a little tricky because the `RawVec`
99
// API does not expose fallible allocation methods, so we
1010
// cannot check what happens when allocator is exhausted
1111
// (beyond detecting a panic).
1212
//
13-
// Instead, this just checks that the RawVec methods do at
13+
// Instead, this just checks that the `RawVec` methods do at
1414
// least go through the Allocator API when it reserves
1515
// storage.
1616

@@ -44,7 +44,7 @@ fn allocator_param() {
4444
fn reserve_does_not_overallocate() {
4545
{
4646
let mut v: RawVec<u32> = RawVec::new();
47-
// First `reserve` allocates like `reserve_exact`
47+
// First, `reserve` allocates like `reserve_exact`.
4848
v.reserve(0, 9);
4949
assert_eq!(9, v.capacity());
5050
}

src/liballoc/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl<T: ?Sized> Rc<T> {
567567
/// let x = Rc::from_raw(x_ptr);
568568
/// assert_eq!(&*x, "hello");
569569
///
570-
/// // Further calls to `Rc::from_raw(x_ptr)` would be memory unsafe.
570+
/// // Further calls to `Rc::from_raw(x_ptr)` would be memory-unsafe.
571571
/// }
572572
///
573573
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!

src/liballoc/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<T: ?Sized> Arc<T> {
547547
/// let x = Arc::from_raw(x_ptr);
548548
/// assert_eq!(&*x, "hello");
549549
///
550-
/// // Further calls to `Arc::from_raw(x_ptr)` would be memory unsafe.
550+
/// // Further calls to `Arc::from_raw(x_ptr)` would be memory-unsafe.
551551
/// }
552552
///
553553
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!

src/libcore/any.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ impl dyn Any {
153153
#[stable(feature = "rust1", since = "1.0.0")]
154154
#[inline]
155155
pub fn is<T: Any>(&self) -> bool {
156-
// Get TypeId of the type this function is instantiated with
156+
// Get `TypeId` of the type this function is instantiated with.
157157
let t = TypeId::of::<T>();
158158

159-
// Get TypeId of the type in the trait object
159+
// Get `TypeId` of the type in the trait object.
160160
let concrete = self.type_id();
161161

162-
// Compare both TypeIds on equality
162+
// Compare both `TypeId`s on equality.
163163
t == concrete
164164
}
165165

src/libcore/marker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,10 @@ unsafe impl<T: ?Sized> Freeze for *mut T {}
602602
unsafe impl<T: ?Sized> Freeze for &T {}
603603
unsafe impl<T: ?Sized> Freeze for &mut T {}
604604

605-
/// Types which can be safely moved after being pinned.
605+
/// Types that can be safely moved after being pinned.
606606
///
607607
/// Since Rust itself has no notion of immovable types, and considers moves
608-
/// (e.g. through assignment or [`mem::replace`]) to always be safe,
608+
/// (e.g., through assignment or [`mem::replace`]) to always be safe,
609609
/// this trait cannot prevent types from moving by itself.
610610
///
611611
/// Instead it is used to prevent moves through the type system,

src/libcore/ptr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ impl<T: ?Sized> *const T {
10421042
(self as *const u8) == null()
10431043
}
10441044

1045-
/// Cast to a pointer to a different type
1045+
/// Casts to a pointer of another type.
10461046
#[stable(feature = "ptr_cast", since = "1.38.0")]
10471047
#[inline]
10481048
pub const fn cast<U>(self) -> *const U {
@@ -1726,7 +1726,7 @@ impl<T: ?Sized> *mut T {
17261726
(self as *mut u8) == null_mut()
17271727
}
17281728

1729-
/// Cast to a pointer to a different type
1729+
/// Casts to a pointer of another type.
17301730
#[stable(feature = "ptr_cast", since = "1.38.0")]
17311731
#[inline]
17321732
pub const fn cast<U>(self) -> *mut U {

src/libcore/ptr/non_null.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<T: ?Sized> NonNull<T> {
125125
&mut *self.as_ptr()
126126
}
127127

128-
/// Cast to a pointer of another type
128+
/// Casts to a pointer of another type.
129129
#[stable(feature = "nonnull_cast", since = "1.27.0")]
130130
#[inline]
131131
pub const fn cast<U>(self) -> NonNull<U> {

src/libstd/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl Error for VarError {
290290
///
291291
/// Note that while concurrent access to environment variables is safe in Rust,
292292
/// some platforms only expose inherently unsafe non-threadsafe APIs for
293-
/// inspecting the environment. As a result extra care needs to be taken when
293+
/// inspecting the environment. As a result, extra care needs to be taken when
294294
/// auditing calls to unsafe external FFI functions to ensure that any external
295295
/// environment accesses are properly synchronized with accesses in Rust.
296296
///

src/libstd/error.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ pub trait Error: Debug + Display {
196196
#[stable(feature = "error_source", since = "1.30.0")]
197197
fn source(&self) -> Option<&(dyn Error + 'static)> { None }
198198

199-
/// Gets the `TypeId` of `self`
199+
/// Gets the `TypeId` of `self`.
200200
#[doc(hidden)]
201201
#[unstable(feature = "error_type_id",
202-
reason = "this is memory unsafe to override in user code",
202+
reason = "this is memory-unsafe to override in user code",
203203
issue = "60784")]
204204
fn type_id(&self, _: private::Internal) -> TypeId where Self: 'static {
205205
TypeId::of::<Self>()
@@ -601,19 +601,19 @@ impl Error for char::ParseCharError {
601601
}
602602
}
603603

604-
// copied from any.rs
604+
// Copied from `any.rs`.
605605
impl dyn Error + 'static {
606606
/// Returns `true` if the boxed type is the same as `T`
607607
#[stable(feature = "error_downcast", since = "1.3.0")]
608608
#[inline]
609609
pub fn is<T: Error + 'static>(&self) -> bool {
610-
// Get TypeId of the type this function is instantiated with
610+
// Get `TypeId` of the type this function is instantiated with.
611611
let t = TypeId::of::<T>();
612612

613-
// Get TypeId of the type in the trait object
613+
// Get `TypeId` of the type in the trait object.
614614
let boxed = self.type_id(private::Internal);
615615

616-
// Compare both TypeIds on equality
616+
// Compare both `TypeId`s on equality.
617617
t == boxed
618618
}
619619

@@ -647,21 +647,21 @@ impl dyn Error + 'static {
647647
}
648648

649649
impl dyn Error + 'static + Send {
650-
/// Forwards to the method defined on the type `Any`.
650+
/// Forwards to the method defined on the type `dyn Error`.
651651
#[stable(feature = "error_downcast", since = "1.3.0")]
652652
#[inline]
653653
pub fn is<T: Error + 'static>(&self) -> bool {
654654
<dyn Error + 'static>::is::<T>(self)
655655
}
656656

657-
/// Forwards to the method defined on the type `Any`.
657+
/// Forwards to the method defined on the type `dyn Error`.
658658
#[stable(feature = "error_downcast", since = "1.3.0")]
659659
#[inline]
660660
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
661661
<dyn Error + 'static>::downcast_ref::<T>(self)
662662
}
663663

664-
/// Forwards to the method defined on the type `Any`.
664+
/// Forwards to the method defined on the type `dyn Error`.
665665
#[stable(feature = "error_downcast", since = "1.3.0")]
666666
#[inline]
667667
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> {
@@ -670,21 +670,21 @@ impl dyn Error + 'static + Send {
670670
}
671671

672672
impl dyn Error + 'static + Send + Sync {
673-
/// Forwards to the method defined on the type `Any`.
673+
/// Forwards to the method defined on the type `dyn Error`.
674674
#[stable(feature = "error_downcast", since = "1.3.0")]
675675
#[inline]
676676
pub fn is<T: Error + 'static>(&self) -> bool {
677677
<dyn Error + 'static>::is::<T>(self)
678678
}
679679

680-
/// Forwards to the method defined on the type `Any`.
680+
/// Forwards to the method defined on the type `dyn Error`.
681681
#[stable(feature = "error_downcast", since = "1.3.0")]
682682
#[inline]
683683
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
684684
<dyn Error + 'static>::downcast_ref::<T>(self)
685685
}
686686

687-
/// Forwards to the method defined on the type `Any`.
687+
/// Forwards to the method defined on the type `dyn Error`.
688688
#[stable(feature = "error_downcast", since = "1.3.0")]
689689
#[inline]
690690
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> {
@@ -695,7 +695,7 @@ impl dyn Error + 'static + Send + Sync {
695695
impl dyn Error {
696696
#[inline]
697697
#[stable(feature = "error_downcast", since = "1.3.0")]
698-
/// Attempt to downcast the box to a concrete type.
698+
/// Attempts to downcast the box to a concrete type.
699699
pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error>> {
700700
if self.is::<T>() {
701701
unsafe {
@@ -863,12 +863,12 @@ impl<'a> Iterator for ErrorIter<'a> {
863863
impl dyn Error + Send {
864864
#[inline]
865865
#[stable(feature = "error_downcast", since = "1.3.0")]
866-
/// Attempt to downcast the box to a concrete type.
866+
/// Attempts to downcast the box to a concrete type.
867867
pub fn downcast<T: Error + 'static>(self: Box<Self>)
868868
-> Result<Box<T>, Box<dyn Error + Send>> {
869869
let err: Box<dyn Error> = self;
870870
<dyn Error>::downcast(err).map_err(|s| unsafe {
871-
// reapply the Send marker
871+
// Reapply the `Send` marker.
872872
transmute::<Box<dyn Error>, Box<dyn Error + Send>>(s)
873873
})
874874
}
@@ -877,12 +877,12 @@ impl dyn Error + Send {
877877
impl dyn Error + Send + Sync {
878878
#[inline]
879879
#[stable(feature = "error_downcast", since = "1.3.0")]
880-
/// Attempt to downcast the box to a concrete type.
880+
/// Attempts to downcast the box to a concrete type.
881881
pub fn downcast<T: Error + 'static>(self: Box<Self>)
882882
-> Result<Box<T>, Box<Self>> {
883883
let err: Box<dyn Error> = self;
884884
<dyn Error>::downcast(err).map_err(|s| unsafe {
885-
// reapply the Send+Sync marker
885+
// Reapply the `Send + Sync` marker.
886886
transmute::<Box<dyn Error>, Box<dyn Error + Send + Sync>>(s)
887887
})
888888
}

src/libstd/ffi/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ impl CString {
615615
}
616616

617617
// Turns this `CString` into an empty string to prevent
618-
// memory unsafe code from working by accident. Inline
618+
// memory-unsafe code from working by accident. Inline
619619
// to prevent LLVM from optimizing it away in debug builds.
620620
#[stable(feature = "cstring_drop", since = "1.13.0")]
621621
impl Drop for CString {

src/libstd/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ pub fn id() -> u32 {
15951595

15961596
/// A trait for implementing arbitrary return types in the `main` function.
15971597
///
1598-
/// The c-main function only supports to return integers as return type.
1598+
/// The C-main function only supports to return integers as return type.
15991599
/// So, every type implementing the `Termination` trait has to be converted
16001600
/// to an integer.
16011601
///

0 commit comments

Comments
 (0)