Skip to content

Commit 517385b

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

File tree

11 files changed

+149
-8
lines changed

11 files changed

+149
-8
lines changed

library/alloc/tests/lib.rs

+1
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)]

library/alloc/tests/str.rs

+24
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";

library/core/src/str/mod.rs

+41
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
///

library/std/src/lazy.rs

+3-1
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

src/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
This directory contains the source code of the rust project, including:
22
- `rustc` and its tests
3-
- `libstd`
3+
- The bootstrapping build system
44
- Various submodules for tools, like rustdoc, rls, etc.
55

66
For more information on how various parts of the compiler work, see the [rustc dev guide].
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
An `impl Trait` type expands to a recursive type.
22

3-
An `impl Trait` type must be expandable to a concrete type that contains no
4-
`impl Trait` types. For example the following example tries to create an
5-
`impl Trait` type `T` that is equal to `[T, T]`:
3+
Erroneous code example:
64

75
```compile_fail,E0720
86
fn make_recursive_type() -> impl Sized {
97
[make_recursive_type(), make_recursive_type()]
108
}
119
```
10+
11+
An `impl Trait` type must be expandable to a concrete type that contains no
12+
`impl Trait` types. For example the previous example tries to create an
13+
`impl Trait` type `T` that is equal to `[T, T]`.

src/librustc_trait_selection/traits/auto_trait.rs

+32
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,38 @@ impl AutoTraitFinder<'tcx> {
802802
_ => {}
803803
};
804804
}
805+
ty::PredicateAtom::ConstEquate(c1, c2) => {
806+
let evaluate = |c: &'tcx ty::Const<'tcx>| {
807+
if let ty::ConstKind::Unevaluated(def, substs, promoted) = c.val {
808+
match select.infcx().const_eval_resolve(
809+
obligation.param_env,
810+
def,
811+
substs,
812+
promoted,
813+
Some(obligation.cause.span),
814+
) {
815+
Ok(val) => Ok(ty::Const::from_value(select.tcx(), val, c.ty)),
816+
Err(err) => Err(err),
817+
}
818+
} else {
819+
Ok(c)
820+
}
821+
};
822+
823+
match (evaluate(c1), evaluate(c2)) {
824+
(Ok(c1), Ok(c2)) => {
825+
match select
826+
.infcx()
827+
.at(&obligation.cause, obligation.param_env)
828+
.eq(c1, c2)
829+
{
830+
Ok(_) => (),
831+
Err(_) => return false,
832+
}
833+
}
834+
_ => return false,
835+
}
836+
}
805837
_ => panic!("Unexpected predicate {:?} {:?}", ty, predicate),
806838
};
807839
}

src/librustdoc/html/static/themes/ayu.css

+2-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,8 @@ pre {
197197
color: #a37acc;
198198
}
199199

200-
pre.rust .comment, pre.rust .doccomment {
201-
color: #788797;
202-
}
200+
pre.rust .comment { color: #788797; }
201+
pre.rust .doccomment { color: #a1ac88; }
203202

204203
nav:not(.sidebar) {
205204
border-bottom-color: #424c57;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![crate_name = "foo"]
2+
#![feature(lazy_normalization_consts)]
3+
#![allow(incomplete_features)]
4+
5+
// Checking if `Send` is implemented for `Hasher` requires us to evaluate a `ConstEquate` predicate,
6+
// which previously caused an ICE.
7+
8+
pub struct Hasher<T> {
9+
cv_stack: T,
10+
}
11+
12+
unsafe impl<T: Default> Send for Hasher<T> {}
13+
14+
// @has foo/struct.Foo.html
15+
// @has - '//code' 'impl Send for Foo'
16+
pub struct Foo {
17+
hasher: Hasher<[u8; 3]>,
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-pass
2+
#![feature(const_generics)]
3+
#![allow(incomplete_features)]
4+
5+
fn foo<const N: usize>(v: &[u8; N]) -> &[u8] {
6+
v
7+
}
8+
9+
fn main() {
10+
assert_eq!(foo(&[1, 2]), &[1, 2]);
11+
}

triagebot.toml

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ Thanks! <3
5858
"""
5959
label = "O-ARM"
6060

61+
[ping.risc-v]
62+
message = """\
63+
Hey RISC-V Group! This bug has been identified as a good "RISC-V candidate".
64+
In case it's useful, here are some [instructions] for tackling these sorts of
65+
bugs. Maybe take a look?
66+
Thanks! <3
67+
68+
[instructions]: https://rustc-dev-guide.rust-lang.org/notification-groups/risc-v.html
69+
"""
70+
label = "O-riscv"
71+
6172
[prioritize]
6273
label = "I-prioritize"
6374

0 commit comments

Comments
 (0)