Skip to content

Commit 2c311f3

Browse files
authored
Unrolled build for rust-lang#140536
Rollup merge of rust-lang#140536 - zachs18:mapped-guard-filter-map, r=Amanieu Rename `*Guard::try_map` to `filter_map`. Rename `std::sync::*Guard::try_map` to `filter_map`. 1. Analogous to `std::cell::Ref(Mut)::filter_map`. 2. Doesn't imply `Try` genericizability. r? `@Amanieu` (or other T-libs-api) Tracking issue for `mapped_lock_guards`: rust-lang#117108
2 parents 4824c2b + d2068be commit 2c311f3

File tree

4 files changed

+61
-59
lines changed

4 files changed

+61
-59
lines changed

library/std/src/sync/poison/mutex.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ unsafe impl<T: ?Sized + Sync> Sync for MutexGuard<'_, T> {}
253253
/// The data protected by the mutex can be accessed through this guard via its
254254
/// [`Deref`] and [`DerefMut`] implementations.
255255
///
256-
/// This structure is created by the [`map`] and [`try_map`] methods on
256+
/// This structure is created by the [`map`] and [`filter_map`] methods on
257257
/// [`MutexGuard`].
258258
///
259259
/// [`map`]: MutexGuard::map
260-
/// [`try_map`]: MutexGuard::try_map
260+
/// [`filter_map`]: MutexGuard::filter_map
261261
/// [`Condvar`]: crate::sync::Condvar
262262
#[must_use = "if unused the Mutex will immediately unlock"]
263263
#[must_not_suspend = "holding a MappedMutexGuard across suspend \
@@ -718,7 +718,7 @@ impl<'a, T: ?Sized> MutexGuard<'a, T> {
718718
U: ?Sized,
719719
{
720720
// SAFETY: the conditions of `MutexGuard::new` were satisfied when the original guard
721-
// was created, and have been upheld throughout `map` and/or `try_map`.
721+
// was created, and have been upheld throughout `map` and/or `filter_map`.
722722
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
723723
// passed to it. If the closure panics, the guard will be dropped.
724724
let data = NonNull::from(f(unsafe { &mut *orig.lock.data.get() }));
@@ -739,17 +739,16 @@ impl<'a, T: ?Sized> MutexGuard<'a, T> {
739739
/// The `Mutex` is already locked, so this cannot fail.
740740
///
741741
/// This is an associated function that needs to be used as
742-
/// `MutexGuard::try_map(...)`. A method would interfere with methods of the
742+
/// `MutexGuard::filter_map(...)`. A method would interfere with methods of the
743743
/// same name on the contents of the `MutexGuard` used through `Deref`.
744-
#[doc(alias = "filter_map")]
745744
#[unstable(feature = "mapped_lock_guards", issue = "117108")]
746-
pub fn try_map<U, F>(orig: Self, f: F) -> Result<MappedMutexGuard<'a, U>, Self>
745+
pub fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedMutexGuard<'a, U>, Self>
747746
where
748747
F: FnOnce(&mut T) -> Option<&mut U>,
749748
U: ?Sized,
750749
{
751750
// SAFETY: the conditions of `MutexGuard::new` were satisfied when the original guard
752-
// was created, and have been upheld throughout `map` and/or `try_map`.
751+
// was created, and have been upheld throughout `map` and/or `filter_map`.
753752
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
754753
// passed to it. If the closure panics, the guard will be dropped.
755754
match f(unsafe { &mut *orig.lock.data.get() }) {
@@ -826,7 +825,7 @@ impl<'a, T: ?Sized> MappedMutexGuard<'a, T> {
826825
U: ?Sized,
827826
{
828827
// SAFETY: the conditions of `MutexGuard::new` were satisfied when the original guard
829-
// was created, and have been upheld throughout `map` and/or `try_map`.
828+
// was created, and have been upheld throughout `map` and/or `filter_map`.
830829
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
831830
// passed to it. If the closure panics, the guard will be dropped.
832831
let data = NonNull::from(f(unsafe { orig.data.as_mut() }));
@@ -847,17 +846,16 @@ impl<'a, T: ?Sized> MappedMutexGuard<'a, T> {
847846
/// The `Mutex` is already locked, so this cannot fail.
848847
///
849848
/// This is an associated function that needs to be used as
850-
/// `MappedMutexGuard::try_map(...)`. A method would interfere with methods of the
849+
/// `MappedMutexGuard::filter_map(...)`. A method would interfere with methods of the
851850
/// same name on the contents of the `MutexGuard` used through `Deref`.
852-
#[doc(alias = "filter_map")]
853851
#[unstable(feature = "mapped_lock_guards", issue = "117108")]
854-
pub fn try_map<U, F>(mut orig: Self, f: F) -> Result<MappedMutexGuard<'a, U>, Self>
852+
pub fn filter_map<U, F>(mut orig: Self, f: F) -> Result<MappedMutexGuard<'a, U>, Self>
855853
where
856854
F: FnOnce(&mut T) -> Option<&mut U>,
857855
U: ?Sized,
858856
{
859857
// SAFETY: the conditions of `MutexGuard::new` were satisfied when the original guard
860-
// was created, and have been upheld throughout `map` and/or `try_map`.
858+
// was created, and have been upheld throughout `map` and/or `filter_map`.
861859
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
862860
// passed to it. If the closure panics, the guard will be dropped.
863861
match f(unsafe { orig.data.as_mut() }) {

library/std/src/sync/poison/rwlock.rs

+25-29
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ unsafe impl<T: ?Sized + Sync> Sync for RwLockWriteGuard<'_, T> {}
147147
/// RAII structure used to release the shared read access of a lock when
148148
/// dropped, which can point to a subfield of the protected data.
149149
///
150-
/// This structure is created by the [`map`] and [`try_map`] methods
150+
/// This structure is created by the [`map`] and [`filter_map`] methods
151151
/// on [`RwLockReadGuard`].
152152
///
153153
/// [`map`]: RwLockReadGuard::map
154-
/// [`try_map`]: RwLockReadGuard::try_map
154+
/// [`filter_map`]: RwLockReadGuard::filter_map
155155
#[must_use = "if unused the RwLock will immediately unlock"]
156156
#[must_not_suspend = "holding a MappedRwLockReadGuard across suspend \
157157
points can cause deadlocks, delays, \
@@ -176,11 +176,11 @@ unsafe impl<T: ?Sized + Sync> Sync for MappedRwLockReadGuard<'_, T> {}
176176
/// RAII structure used to release the exclusive write access of a lock when
177177
/// dropped, which can point to a subfield of the protected data.
178178
///
179-
/// This structure is created by the [`map`] and [`try_map`] methods
179+
/// This structure is created by the [`map`] and [`filter_map`] methods
180180
/// on [`RwLockWriteGuard`].
181181
///
182182
/// [`map`]: RwLockWriteGuard::map
183-
/// [`try_map`]: RwLockWriteGuard::try_map
183+
/// [`filter_map`]: RwLockWriteGuard::filter_map
184184
#[must_use = "if unused the RwLock will immediately unlock"]
185185
#[must_not_suspend = "holding a MappedRwLockWriteGuard across suspend \
186186
points can cause deadlocks, delays, \
@@ -788,7 +788,7 @@ impl<T: ?Sized> Deref for MappedRwLockReadGuard<'_, T> {
788788

789789
fn deref(&self) -> &T {
790790
// SAFETY: the conditions of `RwLockReadGuard::new` were satisfied when the original guard
791-
// was created, and have been upheld throughout `map` and/or `try_map`.
791+
// was created, and have been upheld throughout `map` and/or `filter_map`.
792792
unsafe { self.data.as_ref() }
793793
}
794794
}
@@ -799,7 +799,7 @@ impl<T: ?Sized> Deref for MappedRwLockWriteGuard<'_, T> {
799799

800800
fn deref(&self) -> &T {
801801
// SAFETY: the conditions of `RwLockWriteGuard::new` were satisfied when the original guard
802-
// was created, and have been upheld throughout `map` and/or `try_map`.
802+
// was created, and have been upheld throughout `map` and/or `filter_map`.
803803
unsafe { self.data.as_ref() }
804804
}
805805
}
@@ -808,7 +808,7 @@ impl<T: ?Sized> Deref for MappedRwLockWriteGuard<'_, T> {
808808
impl<T: ?Sized> DerefMut for MappedRwLockWriteGuard<'_, T> {
809809
fn deref_mut(&mut self) -> &mut T {
810810
// SAFETY: the conditions of `RwLockWriteGuard::new` were satisfied when the original guard
811-
// was created, and have been upheld throughout `map` and/or `try_map`.
811+
// was created, and have been upheld throughout `map` and/or `filter_map`.
812812
unsafe { self.data.as_mut() }
813813
}
814814
}
@@ -838,7 +838,7 @@ impl<T: ?Sized> Drop for RwLockWriteGuard<'_, T> {
838838
impl<T: ?Sized> Drop for MappedRwLockReadGuard<'_, T> {
839839
fn drop(&mut self) {
840840
// SAFETY: the conditions of `RwLockReadGuard::new` were satisfied when the original guard
841-
// was created, and have been upheld throughout `map` and/or `try_map`.
841+
// was created, and have been upheld throughout `map` and/or `filter_map`.
842842
unsafe {
843843
self.inner_lock.read_unlock();
844844
}
@@ -850,7 +850,7 @@ impl<T: ?Sized> Drop for MappedRwLockWriteGuard<'_, T> {
850850
fn drop(&mut self) {
851851
self.poison_flag.done(&self.poison);
852852
// SAFETY: the conditions of `RwLockWriteGuard::new` were satisfied when the original guard
853-
// was created, and have been upheld throughout `map` and/or `try_map`.
853+
// was created, and have been upheld throughout `map` and/or `filter_map`.
854854
unsafe {
855855
self.inner_lock.write_unlock();
856856
}
@@ -878,7 +878,7 @@ impl<'a, T: ?Sized> RwLockReadGuard<'a, T> {
878878
U: ?Sized,
879879
{
880880
// SAFETY: the conditions of `RwLockReadGuard::new` were satisfied when the original guard
881-
// was created, and have been upheld throughout `map` and/or `try_map`.
881+
// was created, and have been upheld throughout `map` and/or `filter_map`.
882882
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
883883
// passed to it. If the closure panics, the guard will be dropped.
884884
let data = NonNull::from(f(unsafe { orig.data.as_ref() }));
@@ -893,22 +893,21 @@ impl<'a, T: ?Sized> RwLockReadGuard<'a, T> {
893893
/// The `RwLock` is already locked for reading, so this cannot fail.
894894
///
895895
/// This is an associated function that needs to be used as
896-
/// `RwLockReadGuard::try_map(...)`. A method would interfere with methods
896+
/// `RwLockReadGuard::filter_map(...)`. A method would interfere with methods
897897
/// of the same name on the contents of the `RwLockReadGuard` used through
898898
/// `Deref`.
899899
///
900900
/// # Panics
901901
///
902902
/// If the closure panics, the guard will be dropped (unlocked) and the RwLock will not be poisoned.
903-
#[doc(alias = "filter_map")]
904903
#[unstable(feature = "mapped_lock_guards", issue = "117108")]
905-
pub fn try_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockReadGuard<'a, U>, Self>
904+
pub fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockReadGuard<'a, U>, Self>
906905
where
907906
F: FnOnce(&T) -> Option<&U>,
908907
U: ?Sized,
909908
{
910909
// SAFETY: the conditions of `RwLockReadGuard::new` were satisfied when the original guard
911-
// was created, and have been upheld throughout `map` and/or `try_map`.
910+
// was created, and have been upheld throughout `map` and/or `filter_map`.
912911
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
913912
// passed to it. If the closure panics, the guard will be dropped.
914913
match f(unsafe { orig.data.as_ref() }) {
@@ -943,7 +942,7 @@ impl<'a, T: ?Sized> MappedRwLockReadGuard<'a, T> {
943942
U: ?Sized,
944943
{
945944
// SAFETY: the conditions of `RwLockReadGuard::new` were satisfied when the original guard
946-
// was created, and have been upheld throughout `map` and/or `try_map`.
945+
// was created, and have been upheld throughout `map` and/or `filter_map`.
947946
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
948947
// passed to it. If the closure panics, the guard will be dropped.
949948
let data = NonNull::from(f(unsafe { orig.data.as_ref() }));
@@ -958,22 +957,21 @@ impl<'a, T: ?Sized> MappedRwLockReadGuard<'a, T> {
958957
/// The `RwLock` is already locked for reading, so this cannot fail.
959958
///
960959
/// This is an associated function that needs to be used as
961-
/// `MappedRwLockReadGuard::try_map(...)`. A method would interfere with
960+
/// `MappedRwLockReadGuard::filter_map(...)`. A method would interfere with
962961
/// methods of the same name on the contents of the `MappedRwLockReadGuard`
963962
/// used through `Deref`.
964963
///
965964
/// # Panics
966965
///
967966
/// If the closure panics, the guard will be dropped (unlocked) and the RwLock will not be poisoned.
968-
#[doc(alias = "filter_map")]
969967
#[unstable(feature = "mapped_lock_guards", issue = "117108")]
970-
pub fn try_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockReadGuard<'a, U>, Self>
968+
pub fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockReadGuard<'a, U>, Self>
971969
where
972970
F: FnOnce(&T) -> Option<&U>,
973971
U: ?Sized,
974972
{
975973
// SAFETY: the conditions of `RwLockReadGuard::new` were satisfied when the original guard
976-
// was created, and have been upheld throughout `map` and/or `try_map`.
974+
// was created, and have been upheld throughout `map` and/or `filter_map`.
977975
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
978976
// passed to it. If the closure panics, the guard will be dropped.
979977
match f(unsafe { orig.data.as_ref() }) {
@@ -1008,7 +1006,7 @@ impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> {
10081006
U: ?Sized,
10091007
{
10101008
// SAFETY: the conditions of `RwLockWriteGuard::new` were satisfied when the original guard
1011-
// was created, and have been upheld throughout `map` and/or `try_map`.
1009+
// was created, and have been upheld throughout `map` and/or `filter_map`.
10121010
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
10131011
// passed to it. If the closure panics, the guard will be dropped.
10141012
let data = NonNull::from(f(unsafe { &mut *orig.lock.data.get() }));
@@ -1029,22 +1027,21 @@ impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> {
10291027
/// The `RwLock` is already locked for writing, so this cannot fail.
10301028
///
10311029
/// This is an associated function that needs to be used as
1032-
/// `RwLockWriteGuard::try_map(...)`. A method would interfere with methods
1030+
/// `RwLockWriteGuard::filter_map(...)`. A method would interfere with methods
10331031
/// of the same name on the contents of the `RwLockWriteGuard` used through
10341032
/// `Deref`.
10351033
///
10361034
/// # Panics
10371035
///
10381036
/// If the closure panics, the guard will be dropped (unlocked) and the RwLock will be poisoned.
1039-
#[doc(alias = "filter_map")]
10401037
#[unstable(feature = "mapped_lock_guards", issue = "117108")]
1041-
pub fn try_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockWriteGuard<'a, U>, Self>
1038+
pub fn filter_map<U, F>(orig: Self, f: F) -> Result<MappedRwLockWriteGuard<'a, U>, Self>
10421039
where
10431040
F: FnOnce(&mut T) -> Option<&mut U>,
10441041
U: ?Sized,
10451042
{
10461043
// SAFETY: the conditions of `RwLockWriteGuard::new` were satisfied when the original guard
1047-
// was created, and have been upheld throughout `map` and/or `try_map`.
1044+
// was created, and have been upheld throughout `map` and/or `filter_map`.
10481045
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
10491046
// passed to it. If the closure panics, the guard will be dropped.
10501047
match f(unsafe { &mut *orig.lock.data.get() }) {
@@ -1147,7 +1144,7 @@ impl<'a, T: ?Sized> MappedRwLockWriteGuard<'a, T> {
11471144
U: ?Sized,
11481145
{
11491146
// SAFETY: the conditions of `RwLockWriteGuard::new` were satisfied when the original guard
1150-
// was created, and have been upheld throughout `map` and/or `try_map`.
1147+
// was created, and have been upheld throughout `map` and/or `filter_map`.
11511148
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
11521149
// passed to it. If the closure panics, the guard will be dropped.
11531150
let data = NonNull::from(f(unsafe { orig.data.as_mut() }));
@@ -1168,22 +1165,21 @@ impl<'a, T: ?Sized> MappedRwLockWriteGuard<'a, T> {
11681165
/// The `RwLock` is already locked for writing, so this cannot fail.
11691166
///
11701167
/// This is an associated function that needs to be used as
1171-
/// `MappedRwLockWriteGuard::try_map(...)`. A method would interfere with
1168+
/// `MappedRwLockWriteGuard::filter_map(...)`. A method would interfere with
11721169
/// methods of the same name on the contents of the `MappedRwLockWriteGuard`
11731170
/// used through `Deref`.
11741171
///
11751172
/// # Panics
11761173
///
11771174
/// If the closure panics, the guard will be dropped (unlocked) and the RwLock will be poisoned.
1178-
#[doc(alias = "filter_map")]
11791175
#[unstable(feature = "mapped_lock_guards", issue = "117108")]
1180-
pub fn try_map<U, F>(mut orig: Self, f: F) -> Result<MappedRwLockWriteGuard<'a, U>, Self>
1176+
pub fn filter_map<U, F>(mut orig: Self, f: F) -> Result<MappedRwLockWriteGuard<'a, U>, Self>
11811177
where
11821178
F: FnOnce(&mut T) -> Option<&mut U>,
11831179
U: ?Sized,
11841180
{
11851181
// SAFETY: the conditions of `RwLockWriteGuard::new` were satisfied when the original guard
1186-
// was created, and have been upheld throughout `map` and/or `try_map`.
1182+
// was created, and have been upheld throughout `map` and/or `filter_map`.
11871183
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
11881184
// passed to it. If the closure panics, the guard will be dropped.
11891185
match f(unsafe { orig.data.as_mut() }) {

library/std/tests/sync/mutex.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,13 @@ fn panic_while_mapping_unlocked_poison() {
409409

410410
let _ = panic::catch_unwind(|| {
411411
let guard = lock.lock().unwrap();
412-
let _guard = MutexGuard::try_map::<(), _>(guard, |_| panic!());
412+
let _guard = MutexGuard::filter_map::<(), _>(guard, |_| panic!());
413413
});
414414

415415
match lock.try_lock() {
416-
Ok(_) => panic!("panicking in a MutexGuard::try_map closure should poison the Mutex"),
416+
Ok(_) => panic!("panicking in a MutexGuard::filter_map closure should poison the Mutex"),
417417
Err(TryLockError::WouldBlock) => {
418-
panic!("panicking in a MutexGuard::try_map closure should unlock the mutex")
418+
panic!("panicking in a MutexGuard::filter_map closure should unlock the mutex")
419419
}
420420
Err(TryLockError::Poisoned(_)) => {}
421421
}
@@ -437,13 +437,15 @@ fn panic_while_mapping_unlocked_poison() {
437437
let _ = panic::catch_unwind(|| {
438438
let guard = lock.lock().unwrap();
439439
let guard = MutexGuard::map::<(), _>(guard, |val| val);
440-
let _guard = MappedMutexGuard::try_map::<(), _>(guard, |_| panic!());
440+
let _guard = MappedMutexGuard::filter_map::<(), _>(guard, |_| panic!());
441441
});
442442

443443
match lock.try_lock() {
444-
Ok(_) => panic!("panicking in a MappedMutexGuard::try_map closure should poison the Mutex"),
444+
Ok(_) => {
445+
panic!("panicking in a MappedMutexGuard::filter_map closure should poison the Mutex")
446+
}
445447
Err(TryLockError::WouldBlock) => {
446-
panic!("panicking in a MappedMutexGuard::try_map closure should unlock the mutex")
448+
panic!("panicking in a MappedMutexGuard::filter_map closure should unlock the mutex")
447449
}
448450
Err(TryLockError::Poisoned(_)) => {}
449451
}

0 commit comments

Comments
 (0)