Skip to content

Commit fdbf180

Browse files
committed
Auto merge of rust-lang#74894 - JohnTitor:rollup-4ine62a, r=JohnTitor
Rollup of 8 pull requests Successful merges: - rust-lang#74266 (Clean up E0720 explanation) - rust-lang#74671 (add const generics array coercion test) - rust-lang#74707 (Add str::[r]split_once) - rust-lang#74814 (Fix RefUnwindSafe & UnwinsSafe impls for lazy::SyncLazy) - rust-lang#74859 (Update outdated readme) - rust-lang#74864 (ayu theme: Change doccomment color to `#a1ac88`) - rust-lang#74872 (Enable to ping RISC-V group via triagebot) - rust-lang#74891 (handle ConstEquate in rustdoc) Failed merges: r? @ghost
2 parents 7f6fce2 + 8f6fc64 commit fdbf180

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

alloc/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(map_first_last)]
77
#![feature(new_uninit)]
88
#![feature(pattern)]
9+
#![feature(str_split_once)]
910
#![feature(trusted_len)]
1011
#![feature(try_reserve)]
1112
#![feature(unboxed_closures)]

alloc/tests/str.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,30 @@ fn test_rsplitn() {
13181318
assert_eq!(split, ["mb\n", "\nMäry häd ä little lämb\nLittle l"]);
13191319
}
13201320

1321+
#[test]
1322+
fn test_split_once() {
1323+
assert_eq!("".split_once("->"), None);
1324+
assert_eq!("-".split_once("->"), None);
1325+
assert_eq!("->".split_once("->"), Some(("", "")));
1326+
assert_eq!("a->".split_once("->"), Some(("a", "")));
1327+
assert_eq!("->b".split_once("->"), Some(("", "b")));
1328+
assert_eq!("a->b".split_once("->"), Some(("a", "b")));
1329+
assert_eq!("a->b->c".split_once("->"), Some(("a", "b->c")));
1330+
assert_eq!("---".split_once("--"), Some(("", "-")));
1331+
}
1332+
1333+
#[test]
1334+
fn test_rsplit_once() {
1335+
assert_eq!("".rsplit_once("->"), None);
1336+
assert_eq!("-".rsplit_once("->"), None);
1337+
assert_eq!("->".rsplit_once("->"), Some(("", "")));
1338+
assert_eq!("a->".rsplit_once("->"), Some(("a", "")));
1339+
assert_eq!("->b".rsplit_once("->"), Some(("", "b")));
1340+
assert_eq!("a->b".rsplit_once("->"), Some(("a", "b")));
1341+
assert_eq!("a->b->c".rsplit_once("->"), Some(("a->b", "c")));
1342+
assert_eq!("---".rsplit_once("--"), Some(("-", "")));
1343+
}
1344+
13211345
#[test]
13221346
fn test_split_whitespace() {
13231347
let data = "\n \tMäry häd\tä little lämb\nLittle lämb\n";

core/src/str/mod.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,6 +3610,47 @@ impl str {
36103610
RSplitN(self.splitn(n, pat).0)
36113611
}
36123612

3613+
/// Splits the string on the first occurrence of the specified delimiter and
3614+
/// returns prefix before delimiter and suffix after delimiter.
3615+
///
3616+
/// # Examples
3617+
///
3618+
/// ```
3619+
/// #![feature(str_split_once)]
3620+
///
3621+
/// assert_eq!("cfg".split_once('='), None);
3622+
/// assert_eq!("cfg=foo".split_once('='), Some(("cfg", "foo")));
3623+
/// assert_eq!("cfg=foo=bar".split_once('='), Some(("cfg", "foo=bar")));
3624+
/// ```
3625+
#[unstable(feature = "str_split_once", reason = "newly added", issue = "74773")]
3626+
#[inline]
3627+
pub fn split_once<'a, P: Pattern<'a>>(&'a self, delimiter: P) -> Option<(&'a str, &'a str)> {
3628+
let (start, end) = delimiter.into_searcher(self).next_match()?;
3629+
Some((&self[..start], &self[end..]))
3630+
}
3631+
3632+
/// Splits the string on the last occurrence of the specified delimiter and
3633+
/// returns prefix before delimiter and suffix after delimiter.
3634+
///
3635+
/// # Examples
3636+
///
3637+
/// ```
3638+
/// #![feature(str_split_once)]
3639+
///
3640+
/// assert_eq!("cfg".rsplit_once('='), None);
3641+
/// assert_eq!("cfg=foo".rsplit_once('='), Some(("cfg", "foo")));
3642+
/// assert_eq!("cfg=foo=bar".rsplit_once('='), Some(("cfg=foo", "bar")));
3643+
/// ```
3644+
#[unstable(feature = "str_split_once", reason = "newly added", issue = "74773")]
3645+
#[inline]
3646+
pub fn rsplit_once<'a, P>(&'a self, delimiter: P) -> Option<(&'a str, &'a str)>
3647+
where
3648+
P: Pattern<'a, Searcher: ReverseSearcher<'a>>,
3649+
{
3650+
let (start, end) = delimiter.into_searcher(self).next_match_back()?;
3651+
Some((&self[..start], &self[end..]))
3652+
}
3653+
36133654
/// An iterator over the disjoint matches of a pattern within the given string
36143655
/// slice.
36153656
///

std/src/lazy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,9 @@ unsafe impl<T, F: Send> Sync for SyncLazy<T, F> where SyncOnceCell<T>: Sync {}
451451
// auto-derived `Send` impl is OK.
452452

453453
#[unstable(feature = "once_cell", issue = "74465")]
454-
impl<T, F: RefUnwindSafe> RefUnwindSafe for SyncLazy<T, F> where SyncOnceCell<T>: RefUnwindSafe {}
454+
impl<T, F: UnwindSafe> RefUnwindSafe for SyncLazy<T, F> where SyncOnceCell<T>: RefUnwindSafe {}
455+
#[unstable(feature = "once_cell", issue = "74465")]
456+
impl<T, F: UnwindSafe> UnwindSafe for SyncLazy<T, F> where SyncOnceCell<T>: UnwindSafe {}
455457

456458
impl<T, F> SyncLazy<T, F> {
457459
/// Creates a new lazy value with the given initializing

0 commit comments

Comments
 (0)