Skip to content

Commit 5181002

Browse files
committed
Auto merge of #50182 - alexcrichton:beta-next, r=alexcrichton
[beta] Another round of backports This is a backport of: * #50039 * #50121
2 parents d7c60a1 + 1ca8ce9 commit 5181002

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+221
-55
lines changed

src/liballoc/tests/str.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,36 @@ fn test_str_get_maxinclusive() {
401401
}
402402
}
403403

404+
#[test]
405+
fn test_str_slice_rangetoinclusive_ok() {
406+
let s = "abcαβγ";
407+
assert_eq!(&s[..=2], "abc");
408+
assert_eq!(&s[..=4], "abcα");
409+
}
410+
411+
#[test]
412+
#[should_panic]
413+
fn test_str_slice_rangetoinclusive_notok() {
414+
let s = "abcαβγ";
415+
&s[..=3];
416+
}
417+
418+
#[test]
419+
fn test_str_slicemut_rangetoinclusive_ok() {
420+
let mut s = "abcαβγ".to_owned();
421+
let s: &mut str = &mut s;
422+
assert_eq!(&mut s[..=2], "abc");
423+
assert_eq!(&mut s[..=4], "abcα");
424+
}
425+
426+
#[test]
427+
#[should_panic]
428+
fn test_str_slicemut_rangetoinclusive_notok() {
429+
let mut s = "abcαβγ".to_owned();
430+
let s: &mut str = &mut s;
431+
&mut s[..=3];
432+
}
433+
404434
#[test]
405435
fn test_is_char_boundary() {
406436
let s = "ศไทย中华Việt Nam β-release 🐱123";

src/libcore/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ unsafe impl<T, A: Unsize<[T]>> FixedSizeArray<T> for A {
5959
}
6060

6161
/// The error type returned when a conversion from a slice to an array fails.
62-
#[stable(feature = "try_from", since = "1.26.0")]
62+
#[unstable(feature = "try_from", issue = "33417")]
6363
#[derive(Debug, Copy, Clone)]
6464
pub struct TryFromSliceError(());
6565

@@ -148,7 +148,7 @@ macro_rules! array_impls {
148148
}
149149
}
150150

151-
#[stable(feature = "try_from", since = "1.26.0")]
151+
#[unstable(feature = "try_from", issue = "33417")]
152152
impl<'a, T> TryFrom<&'a [T]> for &'a [T; $N] {
153153
type Error = TryFromSliceError;
154154

@@ -162,7 +162,7 @@ macro_rules! array_impls {
162162
}
163163
}
164164

165-
#[stable(feature = "try_from", since = "1.26.0")]
165+
#[unstable(feature = "try_from", issue = "33417")]
166166
impl<'a, T> TryFrom<&'a mut [T]> for &'a mut [T; $N] {
167167
type Error = TryFromSliceError;
168168

src/libcore/char.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl FromStr for char {
265265
}
266266

267267

268-
#[stable(feature = "try_from", since = "1.26.0")]
268+
#[unstable(feature = "try_from", issue = "33417")]
269269
impl TryFrom<u32> for char {
270270
type Error = CharTryFromError;
271271

@@ -280,11 +280,11 @@ impl TryFrom<u32> for char {
280280
}
281281

282282
/// The error type returned when a conversion from u32 to char fails.
283-
#[stable(feature = "try_from", since = "1.26.0")]
283+
#[unstable(feature = "try_from", issue = "33417")]
284284
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
285285
pub struct CharTryFromError(());
286286

287-
#[stable(feature = "try_from", since = "1.26.0")]
287+
#[unstable(feature = "try_from", issue = "33417")]
288288
impl fmt::Display for CharTryFromError {
289289
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
290290
"converted integer out of range for `char`".fmt(f)

src/libcore/cmp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -882,24 +882,24 @@ mod impls {
882882

883883
ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
884884

885-
#[stable(feature = "never_type", since = "1.26.0")]
885+
#[unstable(feature = "never_type", issue = "35121")]
886886
impl PartialEq for ! {
887887
fn eq(&self, _: &!) -> bool {
888888
*self
889889
}
890890
}
891891

892-
#[stable(feature = "never_type", since = "1.26.0")]
892+
#[unstable(feature = "never_type", issue = "35121")]
893893
impl Eq for ! {}
894894

895-
#[stable(feature = "never_type", since = "1.26.0")]
895+
#[unstable(feature = "never_type", issue = "35121")]
896896
impl PartialOrd for ! {
897897
fn partial_cmp(&self, _: &!) -> Option<Ordering> {
898898
*self
899899
}
900900
}
901901

902-
#[stable(feature = "never_type", since = "1.26.0")]
902+
#[unstable(feature = "never_type", issue = "35121")]
903903
impl Ord for ! {
904904
fn cmp(&self, _: &!) -> Ordering {
905905
*self

src/libcore/convert.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,26 +322,22 @@ pub trait From<T>: Sized {
322322
///
323323
/// [`TryFrom`]: trait.TryFrom.html
324324
/// [`Into`]: trait.Into.html
325-
#[stable(feature = "try_from", since = "1.26.0")]
325+
#[unstable(feature = "try_from", issue = "33417")]
326326
pub trait TryInto<T>: Sized {
327327
/// The type returned in the event of a conversion error.
328-
#[stable(feature = "try_from", since = "1.26.0")]
329328
type Error;
330329

331330
/// Performs the conversion.
332-
#[stable(feature = "try_from", since = "1.26.0")]
333331
fn try_into(self) -> Result<T, Self::Error>;
334332
}
335333

336334
/// Attempt to construct `Self` via a conversion.
337-
#[stable(feature = "try_from", since = "1.26.0")]
335+
#[unstable(feature = "try_from", issue = "33417")]
338336
pub trait TryFrom<T>: Sized {
339337
/// The type returned in the event of a conversion error.
340-
#[stable(feature = "try_from", since = "1.26.0")]
341338
type Error;
342339

343340
/// Performs the conversion.
344-
#[stable(feature = "try_from", since = "1.26.0")]
345341
fn try_from(value: T) -> Result<Self, Self::Error>;
346342
}
347343

@@ -409,7 +405,7 @@ impl<T> From<T> for T {
409405

410406

411407
// TryFrom implies TryInto
412-
#[stable(feature = "try_from", since = "1.26.0")]
408+
#[unstable(feature = "try_from", issue = "33417")]
413409
impl<T, U> TryInto<U> for T where U: TryFrom<T>
414410
{
415411
type Error = U::Error;
@@ -421,7 +417,7 @@ impl<T, U> TryInto<U> for T where U: TryFrom<T>
421417

422418
// Infallible conversions are semantically equivalent to fallible conversions
423419
// with an uninhabited error type.
424-
#[stable(feature = "try_from", since = "1.26.0")]
420+
#[unstable(feature = "try_from", issue = "33417")]
425421
impl<T, U> TryFrom<U> for T where T: From<U> {
426422
type Error = !;
427423

src/libcore/fmt/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,14 +1777,14 @@ macro_rules! fmt_refs {
17771777

17781778
fmt_refs! { Debug, Display, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp }
17791779

1780-
#[stable(feature = "never_type", since = "1.26.0")]
1780+
#[unstable(feature = "never_type", issue = "35121")]
17811781
impl Debug for ! {
17821782
fn fmt(&self, _: &mut Formatter) -> Result {
17831783
*self
17841784
}
17851785
}
17861786

1787-
#[stable(feature = "never_type", since = "1.26.0")]
1787+
#[unstable(feature = "never_type", issue = "35121")]
17881788
impl Display for ! {
17891789
fn fmt(&self, _: &mut Formatter) -> Result {
17901790
*self

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#![feature(iterator_repeat_with)]
8686
#![feature(lang_items)]
8787
#![feature(link_llvm_intrinsics)]
88+
#![feature(never_type)]
8889
#![feature(exhaustive_patterns)]
8990
#![feature(macro_at_most_once_rep)]
9091
#![feature(no_core)]

src/libcore/num/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3663,7 +3663,7 @@ macro_rules! from_str_radix_int_impl {
36633663
from_str_radix_int_impl! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 }
36643664

36653665
/// The error type returned when a checked integral type conversion fails.
3666-
#[stable(feature = "try_from", since = "1.26.0")]
3666+
#[unstable(feature = "try_from", issue = "33417")]
36673667
#[derive(Debug, Copy, Clone)]
36683668
pub struct TryFromIntError(());
36693669

@@ -3678,14 +3678,14 @@ impl TryFromIntError {
36783678
}
36793679
}
36803680

3681-
#[stable(feature = "try_from", since = "1.26.0")]
3681+
#[unstable(feature = "try_from", issue = "33417")]
36823682
impl fmt::Display for TryFromIntError {
36833683
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
36843684
self.__description().fmt(fmt)
36853685
}
36863686
}
36873687

3688-
#[stable(feature = "try_from", since = "1.26.0")]
3688+
#[unstable(feature = "try_from", issue = "33417")]
36893689
impl From<!> for TryFromIntError {
36903690
fn from(never: !) -> TryFromIntError {
36913691
never
@@ -3695,7 +3695,7 @@ impl From<!> for TryFromIntError {
36953695
// only negative bounds
36963696
macro_rules! try_from_lower_bounded {
36973697
($source:ty, $($target:ty),*) => {$(
3698-
#[stable(feature = "try_from", since = "1.26.0")]
3698+
#[unstable(feature = "try_from", issue = "33417")]
36993699
impl TryFrom<$source> for $target {
37003700
type Error = TryFromIntError;
37013701

@@ -3714,7 +3714,7 @@ macro_rules! try_from_lower_bounded {
37143714
// unsigned to signed (only positive bound)
37153715
macro_rules! try_from_upper_bounded {
37163716
($source:ty, $($target:ty),*) => {$(
3717-
#[stable(feature = "try_from", since = "1.26.0")]
3717+
#[unstable(feature = "try_from", issue = "33417")]
37183718
impl TryFrom<$source> for $target {
37193719
type Error = TryFromIntError;
37203720

@@ -3733,7 +3733,7 @@ macro_rules! try_from_upper_bounded {
37333733
// all other cases
37343734
macro_rules! try_from_both_bounded {
37353735
($source:ty, $($target:ty),*) => {$(
3736-
#[stable(feature = "try_from", since = "1.26.0")]
3736+
#[unstable(feature = "try_from", issue = "33417")]
37373737
impl TryFrom<$source> for $target {
37383738
type Error = TryFromIntError;
37393739

src/libcore/str/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,18 +2096,13 @@ mod traits {
20962096
fn index(self, slice: &str) -> &Self::Output {
20972097
assert!(self.end != usize::max_value(),
20982098
"attempted to index str up to maximum usize");
2099-
let end = self.end + 1;
2100-
self.get(slice).unwrap_or_else(|| super::slice_error_fail(slice, 0, end))
2099+
(..self.end+1).index(slice)
21012100
}
21022101
#[inline]
21032102
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
21042103
assert!(self.end != usize::max_value(),
21052104
"attempted to index str up to maximum usize");
2106-
if slice.is_char_boundary(self.end) {
2107-
unsafe { self.get_unchecked_mut(slice) }
2108-
} else {
2109-
super::slice_error_fail(slice, 0, self.end + 1)
2110-
}
2105+
(..self.end+1).index_mut(slice)
21112106
}
21122107
}
21132108

src/libcore/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#![feature(step_trait)]
4444
#![feature(test)]
4545
#![feature(trusted_len)]
46+
#![feature(try_from)]
4647
#![feature(try_trait)]
4748
#![feature(exact_chunks)]
4849
#![feature(atomic_nand)]

0 commit comments

Comments
 (0)