Skip to content

Commit afc5291

Browse files
authored
Rollup merge of rust-lang#64203 - alexreg:rush-pr-2, r=centril
A few cosmetic improvements to code & comments in liballoc and libcore Factored out from hacking on rustc for work on the REPL. r? @Centril
2 parents 45baedb + 58a26c8 commit afc5291

File tree

13 files changed

+109
-111
lines changed

13 files changed

+109
-111
lines changed

src/liballoc/collections/linked_list/tests.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 74 additions & 76 deletions
Large diffs are not rendered by default.

src/liballoc/raw_vec/tests.rs

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

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

200-
/// Gets the `TypeId` of `self`
200+
/// Gets the `TypeId` of `self`.
201201
#[doc(hidden)]
202202
#[unstable(feature = "error_type_id",
203-
reason = "this is memory unsafe to override in user code",
203+
reason = "this is memory-unsafe to override in user code",
204204
issue = "60784")]
205205
fn type_id(&self, _: private::Internal) -> TypeId where Self: 'static {
206206
TypeId::of::<Self>()
@@ -616,19 +616,19 @@ impl Error for char::ParseCharError {
616616
}
617617
}
618618

619-
// copied from any.rs
619+
// Copied from `any.rs`.
620620
impl dyn Error + 'static {
621621
/// Returns `true` if the boxed type is the same as `T`
622622
#[stable(feature = "error_downcast", since = "1.3.0")]
623623
#[inline]
624624
pub fn is<T: Error + 'static>(&self) -> bool {
625-
// Get TypeId of the type this function is instantiated with
625+
// Get `TypeId` of the type this function is instantiated with.
626626
let t = TypeId::of::<T>();
627627

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

631-
// Compare both TypeIds on equality
631+
// Compare both `TypeId`s on equality.
632632
t == boxed
633633
}
634634

@@ -662,21 +662,21 @@ impl dyn Error + 'static {
662662
}
663663

664664
impl dyn Error + 'static + Send {
665-
/// Forwards to the method defined on the type `Any`.
665+
/// Forwards to the method defined on the type `dyn Error`.
666666
#[stable(feature = "error_downcast", since = "1.3.0")]
667667
#[inline]
668668
pub fn is<T: Error + 'static>(&self) -> bool {
669669
<dyn Error + 'static>::is::<T>(self)
670670
}
671671

672-
/// Forwards to the method defined on the type `Any`.
672+
/// Forwards to the method defined on the type `dyn Error`.
673673
#[stable(feature = "error_downcast", since = "1.3.0")]
674674
#[inline]
675675
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
676676
<dyn Error + 'static>::downcast_ref::<T>(self)
677677
}
678678

679-
/// Forwards to the method defined on the type `Any`.
679+
/// Forwards to the method defined on the type `dyn Error`.
680680
#[stable(feature = "error_downcast", since = "1.3.0")]
681681
#[inline]
682682
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> {
@@ -685,21 +685,21 @@ impl dyn Error + 'static + Send {
685685
}
686686

687687
impl dyn Error + 'static + Send + Sync {
688-
/// Forwards to the method defined on the type `Any`.
688+
/// Forwards to the method defined on the type `dyn Error`.
689689
#[stable(feature = "error_downcast", since = "1.3.0")]
690690
#[inline]
691691
pub fn is<T: Error + 'static>(&self) -> bool {
692692
<dyn Error + 'static>::is::<T>(self)
693693
}
694694

695-
/// Forwards to the method defined on the type `Any`.
695+
/// Forwards to the method defined on the type `dyn Error`.
696696
#[stable(feature = "error_downcast", since = "1.3.0")]
697697
#[inline]
698698
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
699699
<dyn Error + 'static>::downcast_ref::<T>(self)
700700
}
701701

702-
/// Forwards to the method defined on the type `Any`.
702+
/// Forwards to the method defined on the type `dyn Error`.
703703
#[stable(feature = "error_downcast", since = "1.3.0")]
704704
#[inline]
705705
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> {
@@ -710,7 +710,7 @@ impl dyn Error + 'static + Send + Sync {
710710
impl dyn Error {
711711
#[inline]
712712
#[stable(feature = "error_downcast", since = "1.3.0")]
713-
/// Attempt to downcast the box to a concrete type.
713+
/// Attempts to downcast the box to a concrete type.
714714
pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error>> {
715715
if self.is::<T>() {
716716
unsafe {
@@ -878,12 +878,12 @@ impl<'a> Iterator for ErrorIter<'a> {
878878
impl dyn Error + Send {
879879
#[inline]
880880
#[stable(feature = "error_downcast", since = "1.3.0")]
881-
/// Attempt to downcast the box to a concrete type.
881+
/// Attempts to downcast the box to a concrete type.
882882
pub fn downcast<T: Error + 'static>(self: Box<Self>)
883883
-> Result<Box<T>, Box<dyn Error + Send>> {
884884
let err: Box<dyn Error> = self;
885885
<dyn Error>::downcast(err).map_err(|s| unsafe {
886-
// reapply the Send marker
886+
// Reapply the `Send` marker.
887887
transmute::<Box<dyn Error>, Box<dyn Error + Send>>(s)
888888
})
889889
}
@@ -892,12 +892,12 @@ impl dyn Error + Send {
892892
impl dyn Error + Send + Sync {
893893
#[inline]
894894
#[stable(feature = "error_downcast", since = "1.3.0")]
895-
/// Attempt to downcast the box to a concrete type.
895+
/// Attempts to downcast the box to a concrete type.
896896
pub fn downcast<T: Error + 'static>(self: Box<Self>)
897897
-> Result<Box<T>, Box<Self>> {
898898
let err: Box<dyn Error> = self;
899899
<dyn Error>::downcast(err).map_err(|s| unsafe {
900-
// reapply the Send+Sync marker
900+
// Reapply the `Send + Sync` marker.
901901
transmute::<Box<dyn Error>, Box<dyn Error + Send + Sync>>(s)
902902
})
903903
}

src/libstd/ffi/c_str.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)