-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Run rustfmt on liballoc #28610
Merged
Merged
Run rustfmt on liballoc #28610
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,7 +214,9 @@ impl<T> Arc<T> { | |
#[stable(feature = "arc_unique", since = "1.4.0")] | ||
pub fn try_unwrap(this: Self) -> Result<T, Self> { | ||
// See `drop` for why all these atomics are like this | ||
if this.inner().strong.compare_and_swap(1, 0, Release) != 1 { return Err(this) } | ||
if this.inner().strong.compare_and_swap(1, 0, Release) != 1 { | ||
return Err(this) | ||
} | ||
|
||
atomic::fence(Acquire); | ||
|
||
|
@@ -251,7 +253,9 @@ impl<T: ?Sized> Arc<T> { | |
let cur = this.inner().weak.load(Relaxed); | ||
|
||
// check if the weak counter is currently "locked"; if so, spin. | ||
if cur == usize::MAX { continue } | ||
if cur == usize::MAX { | ||
continue | ||
} | ||
|
||
// NOTE: this code currently ignores the possibility of overflow | ||
// into usize::MAX; in general both Rc and Arc need to be adjusted | ||
|
@@ -303,7 +307,9 @@ impl<T: ?Sized> Arc<T> { | |
|
||
if self.inner().weak.fetch_sub(1, Release) == 1 { | ||
atomic::fence(Acquire); | ||
deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr)) | ||
deallocate(ptr as *mut u8, | ||
size_of_val(&*ptr), | ||
align_of_val(&*ptr)) | ||
} | ||
} | ||
} | ||
|
@@ -348,7 +354,9 @@ impl<T: ?Sized> Clone for Arc<T> { | |
// We abort because such a program is incredibly degenerate, and we | ||
// don't care to support it. | ||
if old_size > MAX_REFCOUNT { | ||
unsafe { abort(); } | ||
unsafe { | ||
abort(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... like, one did get used here |
||
} | ||
} | ||
|
||
Arc { _ptr: self._ptr } | ||
|
@@ -556,7 +564,9 @@ impl<T: ?Sized> Drop for Arc<T> { | |
// Because `fetch_sub` is already atomic, we do not need to synchronize | ||
// with other threads unless we are going to delete the object. This | ||
// same logic applies to the below `fetch_sub` to the `weak` count. | ||
if self.inner().strong.fetch_sub(1, Release) != 1 { return } | ||
if self.inner().strong.fetch_sub(1, Release) != 1 { | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
|
||
// This fence is needed to prevent reordering of use of the data and | ||
// deletion of the data. Because it is marked `Release`, the decreasing | ||
|
@@ -578,7 +588,7 @@ impl<T: ?Sized> Drop for Arc<T> { | |
atomic::fence(Acquire); | ||
|
||
unsafe { | ||
self.drop_slow() | ||
self.drop_slow(); | ||
} | ||
} | ||
} | ||
|
@@ -613,11 +623,15 @@ impl<T: ?Sized> Weak<T> { | |
// "stale" read of 0 is fine), and any other value is | ||
// confirmed via the CAS below. | ||
let n = inner.strong.load(Relaxed); | ||
if n == 0 { return None } | ||
if n == 0 { | ||
return None | ||
} | ||
|
||
// Relaxed is valid for the same reason it is on Arc's Clone impl | ||
let old = inner.strong.compare_and_swap(n, n + 1, Relaxed); | ||
if old == n { return Some(Arc { _ptr: self._ptr }) } | ||
if old == n { | ||
return Some(Arc { _ptr: self._ptr }) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -653,7 +667,9 @@ impl<T: ?Sized> Clone for Weak<T> { | |
|
||
// See comments in Arc::clone() for why we do this (for mem::forget). | ||
if old_size > MAX_REFCOUNT { | ||
unsafe { abort(); } | ||
unsafe { | ||
abort(); | ||
} | ||
} | ||
|
||
return Weak { _ptr: self._ptr } | ||
|
@@ -705,9 +721,11 @@ impl<T: ?Sized> Drop for Weak<T> { | |
// ref, which can only happen after the lock is released. | ||
if self.inner().weak.fetch_sub(1, Release) == 1 { | ||
atomic::fence(Acquire); | ||
unsafe { deallocate(ptr as *mut u8, | ||
size_of_val(&*ptr), | ||
align_of_val(&*ptr)) } | ||
unsafe { | ||
deallocate(ptr as *mut u8, | ||
size_of_val(&*ptr), | ||
align_of_val(&*ptr)) | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -727,7 +745,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> { | |
/// | ||
/// five == Arc::new(5); | ||
/// ``` | ||
fn eq(&self, other: &Arc<T>) -> bool { *(*self) == *(*other) } | ||
fn eq(&self, other: &Arc<T>) -> bool { | ||
*(*self) == *(*other) | ||
} | ||
|
||
/// Inequality for two `Arc<T>`s. | ||
/// | ||
|
@@ -742,7 +762,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> { | |
/// | ||
/// five != Arc::new(5); | ||
/// ``` | ||
fn ne(&self, other: &Arc<T>) -> bool { *(*self) != *(*other) } | ||
fn ne(&self, other: &Arc<T>) -> bool { | ||
*(*self) != *(*other) | ||
} | ||
} | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> { | ||
|
@@ -776,7 +798,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> { | |
/// | ||
/// five < Arc::new(5); | ||
/// ``` | ||
fn lt(&self, other: &Arc<T>) -> bool { *(*self) < *(*other) } | ||
fn lt(&self, other: &Arc<T>) -> bool { | ||
*(*self) < *(*other) | ||
} | ||
|
||
/// 'Less-than or equal to' comparison for two `Arc<T>`s. | ||
/// | ||
|
@@ -791,7 +815,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> { | |
/// | ||
/// five <= Arc::new(5); | ||
/// ``` | ||
fn le(&self, other: &Arc<T>) -> bool { *(*self) <= *(*other) } | ||
fn le(&self, other: &Arc<T>) -> bool { | ||
*(*self) <= *(*other) | ||
} | ||
|
||
/// Greater-than comparison for two `Arc<T>`s. | ||
/// | ||
|
@@ -806,7 +832,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> { | |
/// | ||
/// five > Arc::new(5); | ||
/// ``` | ||
fn gt(&self, other: &Arc<T>) -> bool { *(*self) > *(*other) } | ||
fn gt(&self, other: &Arc<T>) -> bool { | ||
*(*self) > *(*other) | ||
} | ||
|
||
/// 'Greater-than or equal to' comparison for two `Arc<T>`s. | ||
/// | ||
|
@@ -821,11 +849,15 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> { | |
/// | ||
/// five >= Arc::new(5); | ||
/// ``` | ||
fn ge(&self, other: &Arc<T>) -> bool { *(*self) >= *(*other) } | ||
fn ge(&self, other: &Arc<T>) -> bool { | ||
*(*self) >= *(*other) | ||
} | ||
} | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T: ?Sized + Ord> Ord for Arc<T> { | ||
fn cmp(&self, other: &Arc<T>) -> Ordering { (**self).cmp(&**other) } | ||
fn cmp(&self, other: &Arc<T>) -> Ordering { | ||
(**self).cmp(&**other) | ||
} | ||
} | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T: ?Sized + Eq> Eq for Arc<T> {} | ||
|
@@ -854,7 +886,9 @@ impl<T> fmt::Pointer for Arc<T> { | |
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T: Default> Default for Arc<T> { | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
fn default() -> Arc<T> { Arc::new(Default::default()) } | ||
fn default() -> Arc<T> { | ||
Arc::new(Default::default()) | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
|
@@ -1015,7 +1049,7 @@ mod tests { | |
#[test] | ||
fn weak_self_cyclic() { | ||
struct Cycle { | ||
x: Mutex<Option<Weak<Cycle>>> | ||
x: Mutex<Option<Weak<Cycle>>>, | ||
} | ||
|
||
let a = Arc::new(Cycle { x: Mutex::new(None) }); | ||
|
@@ -1095,7 +1129,9 @@ mod tests { | |
|
||
// Make sure deriving works with Arc<T> | ||
#[derive(Eq, Ord, PartialEq, PartialOrd, Clone, Debug, Default)] | ||
struct Foo { inner: Arc<i32> } | ||
struct Foo { | ||
inner: Arc<i32>, | ||
} | ||
|
||
#[test] | ||
fn test_unsized() { | ||
|
@@ -1108,5 +1144,7 @@ mod tests { | |
} | ||
|
||
impl<T: ?Sized> borrow::Borrow<T> for Arc<T> { | ||
fn borrow(&self) -> &T { &**self } | ||
fn borrow(&self) -> &T { | ||
&**self | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is a style PR, I wonder: is it good style to use
;
here? I probably would. I know it's not in the original source, so it's notrustfmt
doing it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that we should - https://github.com/nrc/rustfmt/issues/353
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer to leave off
;
whenever it's a terminating statement that can't have anything following it anyway (e.g.break
,return
,continue
) but that may be just my style