Skip to content

A few cosmetic improvements to code & comments in liballoc and libcore #64203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/liballoc/collections/linked_list/tests.rs
Original file line number Diff line number Diff line change
@@ -102,8 +102,8 @@ fn test_append() {
assert_eq!(m.pop_front(), Some(elt))
}
assert_eq!(n.len(), 0);
// let's make sure it's working properly, since we
// did some direct changes to private members
// Let's make sure it's working properly, since we
// did some direct changes to private members.
n.push_back(3);
assert_eq!(n.len(), 1);
assert_eq!(n.pop_front(), Some(3));
150 changes: 74 additions & 76 deletions src/liballoc/raw_vec.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/liballoc/raw_vec/tests.rs
Original file line number Diff line number Diff line change
@@ -5,12 +5,12 @@ fn allocator_param() {
use crate::alloc::AllocErr;

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

@@ -44,7 +44,7 @@ fn allocator_param() {
fn reserve_does_not_overallocate() {
{
let mut v: RawVec<u32> = RawVec::new();
// First `reserve` allocates like `reserve_exact`
// First, `reserve` allocates like `reserve_exact`.
v.reserve(0, 9);
assert_eq!(9, v.capacity());
}
2 changes: 1 addition & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
@@ -567,7 +567,7 @@ impl<T: ?Sized> Rc<T> {
/// let x = Rc::from_raw(x_ptr);
/// assert_eq!(&*x, "hello");
///
/// // Further calls to `Rc::from_raw(x_ptr)` would be memory unsafe.
/// // Further calls to `Rc::from_raw(x_ptr)` would be memory-unsafe.
/// }
///
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
2 changes: 1 addition & 1 deletion src/liballoc/sync.rs
Original file line number Diff line number Diff line change
@@ -547,7 +547,7 @@ impl<T: ?Sized> Arc<T> {
/// let x = Arc::from_raw(x_ptr);
/// assert_eq!(&*x, "hello");
///
/// // Further calls to `Arc::from_raw(x_ptr)` would be memory unsafe.
/// // Further calls to `Arc::from_raw(x_ptr)` would be memory-unsafe.
/// }
///
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
6 changes: 3 additions & 3 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
@@ -153,13 +153,13 @@ impl dyn Any {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn is<T: Any>(&self) -> bool {
// Get TypeId of the type this function is instantiated with
// Get `TypeId` of the type this function is instantiated with.
let t = TypeId::of::<T>();

// Get TypeId of the type in the trait object
// Get `TypeId` of the type in the trait object.
let concrete = self.type_id();

// Compare both TypeIds on equality
// Compare both `TypeId`s on equality.
t == concrete
}

4 changes: 2 additions & 2 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
@@ -602,10 +602,10 @@ unsafe impl<T: ?Sized> Freeze for *mut T {}
unsafe impl<T: ?Sized> Freeze for &T {}
unsafe impl<T: ?Sized> Freeze for &mut T {}

/// Types which can be safely moved after being pinned.
/// Types that can be safely moved after being pinned.
///
/// Since Rust itself has no notion of immovable types, and considers moves
/// (e.g. through assignment or [`mem::replace`]) to always be safe,
/// (e.g., through assignment or [`mem::replace`]) to always be safe,
/// this trait cannot prevent types from moving by itself.
///
/// Instead it is used to prevent moves through the type system,
4 changes: 2 additions & 2 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
@@ -1042,7 +1042,7 @@ impl<T: ?Sized> *const T {
(self as *const u8) == null()
}

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

/// Cast to a pointer to a different type
/// Casts to a pointer of another type.
#[stable(feature = "ptr_cast", since = "1.38.0")]
#[inline]
pub const fn cast<U>(self) -> *mut U {
2 changes: 1 addition & 1 deletion src/libcore/ptr/non_null.rs
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ impl<T: ?Sized> NonNull<T> {
&mut *self.as_ptr()
}

/// Cast to a pointer of another type
/// Casts to a pointer of another type.
#[stable(feature = "nonnull_cast", since = "1.27.0")]
#[inline]
pub const fn cast<U>(self) -> NonNull<U> {
2 changes: 1 addition & 1 deletion src/libstd/env.rs
Original file line number Diff line number Diff line change
@@ -290,7 +290,7 @@ impl Error for VarError {
///
/// Note that while concurrent access to environment variables is safe in Rust,
/// some platforms only expose inherently unsafe non-threadsafe APIs for
/// inspecting the environment. As a result extra care needs to be taken when
/// inspecting the environment. As a result, extra care needs to be taken when
/// auditing calls to unsafe external FFI functions to ensure that any external
/// environment accesses are properly synchronized with accesses in Rust.
///
34 changes: 17 additions & 17 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
@@ -196,10 +196,10 @@ pub trait Error: Debug + Display {
#[stable(feature = "error_source", since = "1.30.0")]
fn source(&self) -> Option<&(dyn Error + 'static)> { None }

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

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

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

// Compare both TypeIds on equality
// Compare both `TypeId`s on equality.
t == boxed
}

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

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

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

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

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

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

/// Forwards to the method defined on the type `Any`.
/// Forwards to the method defined on the type `dyn Error`.
#[stable(feature = "error_downcast", since = "1.3.0")]
#[inline]
pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> {
@@ -695,7 +695,7 @@ impl dyn Error + 'static + Send + Sync {
impl dyn Error {
#[inline]
#[stable(feature = "error_downcast", since = "1.3.0")]
/// Attempt to downcast the box to a concrete type.
/// Attempts to downcast the box to a concrete type.
pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error>> {
if self.is::<T>() {
unsafe {
@@ -863,12 +863,12 @@ impl<'a> Iterator for ErrorIter<'a> {
impl dyn Error + Send {
#[inline]
#[stable(feature = "error_downcast", since = "1.3.0")]
/// Attempt to downcast the box to a concrete type.
/// Attempts to downcast the box to a concrete type.
pub fn downcast<T: Error + 'static>(self: Box<Self>)
-> Result<Box<T>, Box<dyn Error + Send>> {
let err: Box<dyn Error> = self;
<dyn Error>::downcast(err).map_err(|s| unsafe {
// reapply the Send marker
// Reapply the `Send` marker.
transmute::<Box<dyn Error>, Box<dyn Error + Send>>(s)
})
}
@@ -877,12 +877,12 @@ impl dyn Error + Send {
impl dyn Error + Send + Sync {
#[inline]
#[stable(feature = "error_downcast", since = "1.3.0")]
/// Attempt to downcast the box to a concrete type.
/// Attempts to downcast the box to a concrete type.
pub fn downcast<T: Error + 'static>(self: Box<Self>)
-> Result<Box<T>, Box<Self>> {
let err: Box<dyn Error> = self;
<dyn Error>::downcast(err).map_err(|s| unsafe {
// reapply the Send+Sync marker
// Reapply the `Send + Sync` marker.
transmute::<Box<dyn Error>, Box<dyn Error + Send + Sync>>(s)
})
}
2 changes: 1 addition & 1 deletion src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
@@ -615,7 +615,7 @@ impl CString {
}

// Turns this `CString` into an empty string to prevent
// memory unsafe code from working by accident. Inline
// memory-unsafe code from working by accident. Inline
// to prevent LLVM from optimizing it away in debug builds.
#[stable(feature = "cstring_drop", since = "1.13.0")]
impl Drop for CString {
2 changes: 1 addition & 1 deletion src/libstd/process.rs
Original file line number Diff line number Diff line change
@@ -1595,7 +1595,7 @@ pub fn id() -> u32 {

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