Skip to content

Commit ea37682

Browse files
committed
Auto merge of #41277 - frewsxcv:rollup, r=frewsxcv
Rollup of 3 pull requests - Successful merges: #41240, #41250, #41266 - Failed merges:
2 parents 43ef63d + 6afb2c4 commit ea37682

File tree

5 files changed

+117
-67
lines changed

5 files changed

+117
-67
lines changed

src/liballoc/arc.rs

+33-33
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,29 @@ unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {}
165165
#[unstable(feature = "coerce_unsized", issue = "27732")]
166166
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Arc<U>> for Arc<T> {}
167167

168-
/// A weak version of [`Arc`][arc].
168+
/// `Weak` is a version of [`Arc`] that holds a non-owning reference to the
169+
/// managed value. The value is accessed by calling [`upgrade`] on the `Weak`
170+
/// pointer, which returns an [`Option`]`<`[`Arc`]`<T>>`.
169171
///
170-
/// `Weak` pointers do not count towards determining if the inner value
171-
/// should be dropped.
172+
/// Since a `Weak` reference does not count towards ownership, it will not
173+
/// prevent the inner value from being dropped, and `Weak` itself makes no
174+
/// guarantees about the value still being present and may return [`None`]
175+
/// when [`upgrade`]d.
172176
///
173-
/// The typical way to obtain a `Weak` pointer is to call
174-
/// [`Arc::downgrade`][downgrade].
177+
/// A `Weak` pointer is useful for keeping a temporary reference to the value
178+
/// within [`Arc`] without extending its lifetime. It is also used to prevent
179+
/// circular references between [`Arc`] pointers, since mutual owning references
180+
/// would never allow either [`Arc`] to be dropped. For example, a tree could
181+
/// have strong [`Arc`] pointers from parent nodes to children, and `Weak`
182+
/// pointers from children back to their parents.
175183
///
176-
/// See the [`Arc`][arc] documentation for more details.
184+
/// The typical way to obtain a `Weak` pointer is to call [`Arc::downgrade`].
177185
///
178-
/// [arc]: struct.Arc.html
179-
/// [downgrade]: struct.Arc.html#method.downgrade
186+
/// [`Arc`]: struct.Arc.html
187+
/// [`Arc::downgrade`]: struct.Arc.html#method.downgrade
188+
/// [`upgrade`]: struct.Weak.html#method.upgrade
189+
/// [`Option`]: ../../std/option/enum.Option.html
190+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
180191
#[stable(feature = "arc_weak", since = "1.4.0")]
181192
pub struct Weak<T: ?Sized> {
182193
ptr: Shared<ArcInner<T>>,
@@ -766,14 +777,11 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
766777
}
767778

768779
impl<T> Weak<T> {
769-
/// Constructs a new `Weak<T>`, without an accompanying instance of `T`.
770-
///
771-
/// This allocates memory for `T`, but does not initialize it. Calling
772-
/// [`upgrade`][upgrade] on the return value always gives
773-
/// [`None`][option].
780+
/// Constructs a new `Weak<T>`, allocating memory for `T` without initializing
781+
/// it. Calling [`upgrade`] on the return value always gives [`None`].
774782
///
775-
/// [upgrade]: struct.Weak.html#method.upgrade
776-
/// [option]: ../../std/option/enum.Option.html
783+
/// [`upgrade`]: struct.Weak.html#method.upgrade
784+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
777785
///
778786
/// # Examples
779787
///
@@ -798,13 +806,13 @@ impl<T> Weak<T> {
798806
}
799807

800808
impl<T: ?Sized> Weak<T> {
801-
/// Upgrades the `Weak` pointer to an [`Arc`][arc], if possible.
809+
/// Attempts to upgrade the `Weak` pointer to an [`Arc`], extending
810+
/// the lifetime of the value if successful.
802811
///
803-
/// Returns [`None`][option] if the strong count has reached zero and the
804-
/// inner value was destroyed.
812+
/// Returns [`None`] if the value has since been dropped.
805813
///
806-
/// [arc]: struct.Arc.html
807-
/// [option]: ../../std/option/enum.Option.html
814+
/// [`Arc`]: struct.Arc.html
815+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
808816
///
809817
/// # Examples
810818
///
@@ -865,10 +873,7 @@ impl<T: ?Sized> Weak<T> {
865873

866874
#[stable(feature = "arc_weak", since = "1.4.0")]
867875
impl<T: ?Sized> Clone for Weak<T> {
868-
/// Makes a clone of the `Weak` pointer.
869-
///
870-
/// This creates another pointer to the same inner value, increasing the
871-
/// weak reference count.
876+
/// Makes a clone of the `Weak` pointer that points to the same value.
872877
///
873878
/// # Examples
874879
///
@@ -900,14 +905,11 @@ impl<T: ?Sized> Clone for Weak<T> {
900905

901906
#[stable(feature = "downgraded_weak", since = "1.10.0")]
902907
impl<T> Default for Weak<T> {
903-
/// Constructs a new `Weak<T>`, without an accompanying instance of `T`.
908+
/// Constructs a new `Weak<T>`, allocating memory for `T` without initializing
909+
/// it. Calling [`upgrade`] on the return value always gives [`None`].
904910
///
905-
/// This allocates memory for `T`, but does not initialize it. Calling
906-
/// [`upgrade`][upgrade] on the return value always gives
907-
/// [`None`][option].
908-
///
909-
/// [upgrade]: struct.Weak.html#method.upgrade
910-
/// [option]: ../../std/option/enum.Option.html
911+
/// [`upgrade`]: struct.Weak.html#method.upgrade
912+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
911913
///
912914
/// # Examples
913915
///
@@ -926,8 +928,6 @@ impl<T> Default for Weak<T> {
926928
impl<T: ?Sized> Drop for Weak<T> {
927929
/// Drops the `Weak` pointer.
928930
///
929-
/// This will decrement the weak reference count.
930-
///
931931
/// # Examples
932932
///
933933
/// ```

src/liballoc/rc.rs

+33-33
Original file line numberDiff line numberDiff line change
@@ -922,18 +922,29 @@ impl<T> From<T> for Rc<T> {
922922
}
923923
}
924924

925-
/// A weak version of [`Rc`][rc].
925+
/// `Weak` is a version of [`Rc`] that holds a non-owning reference to the
926+
/// managed value. The value is accessed by calling [`upgrade`] on the `Weak`
927+
/// pointer, which returns an [`Option`]`<`[`Rc`]`<T>>`.
926928
///
927-
/// `Weak` pointers do not count towards determining if the inner value
928-
/// should be dropped.
929+
/// Since a `Weak` reference does not count towards ownership, it will not
930+
/// prevent the inner value from being dropped, and `Weak` itself makes no
931+
/// guarantees about the value still being present and may return [`None`]
932+
/// when [`upgrade`]d.
929933
///
930-
/// The typical way to obtain a `Weak` pointer is to call
931-
/// [`Rc::downgrade`][downgrade].
934+
/// A `Weak` pointer is useful for keeping a temporary reference to the value
935+
/// within [`Rc`] without extending its lifetime. It is also used to prevent
936+
/// circular references between [`Rc`] pointers, since mutual owning references
937+
/// would never allow either [`Arc`] to be dropped. For example, a tree could
938+
/// have strong [`Rc`] pointers from parent nodes to children, and `Weak`
939+
/// pointers from children back to their parents.
932940
///
933-
/// See the [module-level documentation](./index.html) for more details.
941+
/// The typical way to obtain a `Weak` pointer is to call [`Rc::downgrade`].
934942
///
935-
/// [rc]: struct.Rc.html
936-
/// [downgrade]: struct.Rc.html#method.downgrade
943+
/// [`Rc`]: struct.Rc.html
944+
/// [`Rc::downgrade`]: struct.Rc.html#method.downgrade
945+
/// [`upgrade`]: struct.Weak.html#method.upgrade
946+
/// [`Option`]: ../../std/option/enum.Option.html
947+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
937948
#[stable(feature = "rc_weak", since = "1.4.0")]
938949
pub struct Weak<T: ?Sized> {
939950
ptr: Shared<RcBox<T>>,
@@ -948,14 +959,11 @@ impl<T: ?Sized> !marker::Sync for Weak<T> {}
948959
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T> {}
949960

950961
impl<T> Weak<T> {
951-
/// Constructs a new `Weak<T>`, without an accompanying instance of `T`.
952-
///
953-
/// This allocates memory for `T`, but does not initialize it. Calling
954-
/// [`upgrade`][upgrade] on the return value always gives
955-
/// [`None`][option].
962+
/// Constructs a new `Weak<T>`, allocating memory for `T` without initializing
963+
/// it. Calling [`upgrade`] on the return value always gives [`None`].
956964
///
957-
/// [upgrade]: struct.Weak.html#method.upgrade
958-
/// [option]: ../../std/option/enum.Option.html
965+
/// [`upgrade`]: struct.Weak.html#method.upgrade
966+
/// [`None`]: ../../std/option/enum.Option.html
959967
///
960968
/// # Examples
961969
///
@@ -980,13 +988,13 @@ impl<T> Weak<T> {
980988
}
981989

982990
impl<T: ?Sized> Weak<T> {
983-
/// Upgrades the `Weak` pointer to an [`Rc`][rc], if possible.
991+
/// Attempts to upgrade the `Weak` pointer to an [`Rc`], extending
992+
/// the lifetime of the value if successful.
984993
///
985-
/// Returns [`None`][option] if the strong count has reached zero and the
986-
/// inner value was destroyed.
994+
/// Returns [`None`] if the value has since been dropped.
987995
///
988-
/// [rc]: struct.Rc.html
989-
/// [option]: ../../std/option/enum.Option.html
996+
/// [`Rc`]: struct.Rc.html
997+
/// [`None`]: ../../std/option/enum.Option.html
990998
///
991999
/// # Examples
9921000
///
@@ -1021,8 +1029,6 @@ impl<T: ?Sized> Weak<T> {
10211029
impl<T: ?Sized> Drop for Weak<T> {
10221030
/// Drops the `Weak` pointer.
10231031
///
1024-
/// This will decrement the weak reference count.
1025-
///
10261032
/// # Examples
10271033
///
10281034
/// ```
@@ -1061,10 +1067,7 @@ impl<T: ?Sized> Drop for Weak<T> {
10611067

10621068
#[stable(feature = "rc_weak", since = "1.4.0")]
10631069
impl<T: ?Sized> Clone for Weak<T> {
1064-
/// Makes a clone of the `Weak` pointer.
1065-
///
1066-
/// This creates another pointer to the same inner value, increasing the
1067-
/// weak reference count.
1070+
/// Makes a clone of the `Weak` pointer that points to the same value.
10681071
///
10691072
/// # Examples
10701073
///
@@ -1091,14 +1094,11 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {
10911094

10921095
#[stable(feature = "downgraded_weak", since = "1.10.0")]
10931096
impl<T> Default for Weak<T> {
1094-
/// Constructs a new `Weak<T>`, without an accompanying instance of `T`.
1095-
///
1096-
/// This allocates memory for `T`, but does not initialize it. Calling
1097-
/// [`upgrade`][upgrade] on the return value always gives
1098-
/// [`None`][option].
1097+
/// Constructs a new `Weak<T>`, allocating memory for `T` without initializing
1098+
/// it. Calling [`upgrade`] on the return value always gives [`None`].
10991099
///
1100-
/// [upgrade]: struct.Weak.html#method.upgrade
1101-
/// [option]: ../../std/option/enum.Option.html
1100+
/// [`upgrade`]: struct.Weak.html#method.upgrade
1101+
/// [`None`]: ../../std/option/enum.Option.html
11021102
///
11031103
/// # Examples
11041104
///

src/libcompiler_builtins/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub mod reimpls {
180180
sr = sr.wrapping_add(1);
181181

182182
// 1 <= sr <= u64::bits() - 1
183-
q = n.wrapping_shl(64u32.wrapping_sub(sr));
183+
q = n.wrapping_shl(128u32.wrapping_sub(sr));
184184
r = n.wrapping_shr(sr);
185185
} else {
186186
if d.high() == 0 {

src/test/run-pass/i128.rs

+5
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,9 @@ fn main() {
104104
assert_eq!(l.checked_sub(l), Some(0));
105105
assert_eq!(b(1u128).checked_shl(b(127)), Some(1 << 127));
106106
assert_eq!(o.checked_shl(b(128)), None);
107+
108+
// https://github.com/rust-lang/rust/issues/41228
109+
assert_eq!(b(-87559967289969187895646876466835277875_i128) /
110+
b(84285771033834995895337664386045050880_i128),
111+
-1i128);
107112
}

src/test/run-pass/u128.rs

+45
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,49 @@ fn main() {
7777
assert_eq!(o.checked_sub(b(18)), None);
7878
assert_eq!(b(1u128).checked_shl(b(127)), Some(1 << 127));
7979
assert_eq!(o.checked_shl(b(128)), None);
80+
81+
// Test cases for all udivmodti4 branches.
82+
// case "0X/0X"
83+
assert_eq!(b(0x69545bd57727c050_u128) /
84+
b(0x3283527a3350d88c_u128),
85+
2u128);
86+
// case "0X/KX"
87+
assert_eq!(b(0x0_8003c9c50b473ae6_u128) /
88+
b(0x1_283e8838c30fa8f4_u128),
89+
0u128);
90+
// case "K0/K0"
91+
assert_eq!(b(0xc43f42a207978720_u128 << 64) /
92+
b(0x098e62b74c23cf1a_u128 << 64),
93+
20u128);
94+
// case "KK/K0" for power-of-two D.
95+
assert_eq!(b(0xa9008fb6c9d81e42_0e25730562a601c8_u128) /
96+
b(1u128 << 120),
97+
169u128);
98+
// case "KK/K0" with N >= D (https://github.com/rust-lang/rust/issues/41228).
99+
assert_eq!(b(0xe4d26e59f0640328_06da5b06efe83a41_u128) /
100+
b(0x330fcb030ea4447c_u128 << 64),
101+
4u128);
102+
assert_eq!(b(3u128 << 64 | 1) /
103+
b(3u128 << 64),
104+
1u128);
105+
// case "KK/K0" with N < D.
106+
assert_eq!(b(0x6655c9fb66ca2884_e2d1dfd470158c62_u128) /
107+
b(0xb35b667cab7e355b_u128 << 64),
108+
0u128);
109+
// case "KX/0K" for power-of-two D.
110+
assert_eq!(b(0x3e49dd84feb2df59_7b2f97d93a253969_u128) /
111+
b(1u128 << 4),
112+
0x03e49dd84feb2df5_97b2f97d93a25396_u128);
113+
// case "KX/0K" in general.
114+
assert_eq!(b(0x299692b3a1dae5bd_6162e6f489d2620e_u128) /
115+
b(0x900b6f027571d6f7_u128),
116+
0x49e95f54b0442578_u128);
117+
// case "KX/KK" with N >= D.
118+
assert_eq!(b(0xc7b889180b67b07d_bc1a3c88783d35b5_u128) /
119+
b(0x1d7e69f53160b9e2_60074771e852f244_u128),
120+
6u128);
121+
// case "KX/KK" with N < D.
122+
assert_eq!(b(0x679289ac23bb334f_36144401cf882172_u128) /
123+
b(0x7b0b271b64865f05_f54a7b72746c062f_u128),
124+
0u128);
80125
}

0 commit comments

Comments
 (0)