Skip to content

Commit

Permalink
Rollup merge of rust-lang#64203 - alexreg:rush-pr-2, r=centril
Browse files Browse the repository at this point in the history
A few cosmetic improvements to code & comments in liballoc and libcore

Factored out from hacking on rustc for work on the REPL.

r? @Centril
  • Loading branch information
Centril committed Sep 14, 2019
2 parents 45baedb + 58a26c8 commit afc5291
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 111 deletions.
4 changes: 2 additions & 2 deletions src/liballoc/collections/linked_list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
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
Expand Up @@ -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.

Expand Down Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
34 changes: 17 additions & 17 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,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>()
Expand Down Expand Up @@ -616,19 +616,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
}

Expand Down Expand Up @@ -662,21 +662,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> {
Expand All @@ -685,21 +685,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> {
Expand All @@ -710,7 +710,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 {
Expand Down Expand Up @@ -878,12 +878,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)
})
}
Expand All @@ -892,12 +892,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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down

0 comments on commit afc5291

Please sign in to comment.