-
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
Implement alloc::sync::UniqueArc
#133572
base: master
Are you sure you want to change the base?
Implement alloc::sync::UniqueArc
#133572
Conversation
fec20b5
to
39aed9b
Compare
This comment has been minimized.
This comment has been minimized.
39aed9b
to
5142171
Compare
Hah! I’m just noticing that this, as well as Otherwise, you can fn extend_lifetime<'a, 'b>(x: &'a str) -> &'b str {
let r = UniqueRc::new(""); // UniqueRc<&'static str>
let w = UniqueRc::downgrade(&r); // Weak<&'static str>
let mut r = r; // COVARIANT: ==>> UniqueRc<&'a str>
*r = x; // assign the &'a str
let _r = UniqueRc::into_rc(r); // Rc<&'a str>, but we only care to activate the weak
let r = w.upgrade().unwrap(); // upgrade succeeds: Rc<&'static str>
*r // &'static str, coerces to &'b str
} |
☔ The latest upstream changes (presumably #135357) made this pull request unmergeable. Please resolve the merge conflicts. |
…k-Simulacrum Make (unstable API) `UniqueRc` invariant for soundness Add test case from rust-lang#133572 (comment) (comment in review of `UniqueArc`), and fix the issue for `UniqueRc`.
…k-Simulacrum Make (unstable API) `UniqueRc` invariant for soundness Add test case from rust-lang#133572 (comment) (comment in review of `UniqueArc`), and fix the issue for `UniqueRc`.
Rollup merge of rust-lang#135379 - steffahn:uniquerc-invariant, r=Mark-Simulacrum Make (unstable API) `UniqueRc` invariant for soundness Add test case from rust-lang#133572 (comment) (comment in review of `UniqueArc`), and fix the issue for `UniqueRc`.
5142171
to
9310c96
Compare
This comment has been minimized.
This comment has been minimized.
951fa08
to
0b2c03e
Compare
library/alloc/src/sync.rs
Outdated
} | ||
|
||
#[unstable(feature = "unique_rc_arc", issue = "112566")] | ||
unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for UniqueArc<T, A> { |
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.
} | |
#[unstable(feature = "unique_rc_arc", issue = "112566")] | |
unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for UniqueArc<T, A> { | |
} | |
#[unstable(feature = "deref_pure_trait", issue = "87121")] | |
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Arc<T, A> {} | |
#[unstable(feature = "unique_rc_arc", issue = "112566")] | |
unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for UniqueArc<T, A> { |
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.
Do you mean impl DerefPure for UniqueArc
here? (is Arc
here a typo?)
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.
yes it should be UniqueArc
that's my bad
library/alloc/src/sync.rs
Outdated
|
||
/// Inequality for two `UniqueArc`s. | ||
/// | ||
/// Two `UniqueArc`s are not equal if their inner values are not equal. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// #![feature(unique_rc_arc)] | ||
/// use std::sync::UniqueArc; | ||
/// | ||
/// let five = UniqueArc::new(5); | ||
/// | ||
/// assert!(five != UniqueArc::new(6)); | ||
/// ``` | ||
#[inline] | ||
fn ne(&self, other: &Self) -> bool { | ||
PartialEq::ne(&**self, &**other) | ||
} |
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.
/// Inequality for two `UniqueArc`s. | |
/// | |
/// Two `UniqueArc`s are not equal if their inner values are not equal. | |
/// | |
/// # Examples | |
/// | |
/// ``` | |
/// #![feature(unique_rc_arc)] | |
/// use std::sync::UniqueArc; | |
/// | |
/// let five = UniqueArc::new(5); | |
/// | |
/// assert!(five != UniqueArc::new(6)); | |
/// ``` | |
#[inline] | |
fn ne(&self, other: &Self) -> bool { | |
PartialEq::ne(&**self, &**other) | |
} |
Implementations must ensure that
eq
andne
are consistent with each other:
a != b
if and only if!(a == b)
.The default implementation of
ne
provides this consistency and is almost always sufficient. It should not be overridden without very good reason.
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.
But how about the user overrides <T as PartialEq>::ne
? Then the behaviours of <T as PartialEq>::ne
and <Arc<T> as PartialEq>::ne
are inconsistent.
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.
See #98655 for some context, but the only possible correct implementation of ne
is !eq
, so there is no reason to override 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.
I see, thank you. Should I remove the overidden implementation of <Rc as PartialEq>::ne
too?
0b2c03e
to
ff35547
Compare
ff35547
to
d4783e3
Compare
☔ The latest upstream changes (presumably #138208) made this pull request unmergeable. Please resolve the merge conflicts. |
…k-Simulacrum Make (unstable API) `UniqueRc` invariant for soundness Add test case from rust-lang#133572 (comment) (comment in review of `UniqueArc`), and fix the issue for `UniqueRc`.
This implements the
alloc::sync::UniqueArc
part of #112566.