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

+30
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

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

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

+4-4
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

+4-8
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

+2-2
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

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

+6-6
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

+2-7
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

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

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#![cfg_attr(stage0, feature(match_default_bindings))]
5959
#![feature(macro_lifetime_matcher)]
6060
#![feature(macro_vis_matcher)]
61+
#![feature(never_type)]
6162
#![feature(exhaustive_patterns)]
6263
#![feature(non_exhaustive)]
6364
#![feature(nonzero)]

src/librustc/ty/context.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
21812181
self.intern_tup(&[])
21822182
}
21832183

2184+
pub fn mk_diverging_default(self) -> Ty<'tcx> {
2185+
if self.features().never_type {
2186+
self.types.never
2187+
} else {
2188+
self.intern_tup(&[])
2189+
}
2190+
}
2191+
21842192
pub fn mk_bool(self) -> Ty<'tcx> {
21852193
self.mk_ty(TyBool)
21862194
}

src/librustc_apfloat/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
#![cfg_attr(stage0, feature(slice_patterns))]
5050
#![cfg_attr(stage0, feature(i128_type))]
51-
#![cfg_attr(stage0, feature(try_from))]
51+
#![feature(try_from)]
5252

5353
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
5454
#[allow(unused_extern_crates)]

src/librustc_mir/build/matches/simplify.rs

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
113113
PatternKind::Variant { adt_def, substs, variant_index, ref subpatterns } => {
114114
let irrefutable = adt_def.variants.iter().enumerate().all(|(i, v)| {
115115
i == variant_index || {
116+
self.hir.tcx().features().never_type &&
116117
self.hir.tcx().features().exhaustive_patterns &&
117118
self.hir.tcx().is_variant_uninhabited_from_all_modules(v, substs)
118119
}

src/librustc_mir/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
4040
#![cfg_attr(stage0, feature(underscore_lifetimes))]
4141
#![cfg_attr(stage0, feature(never_type))]
4242
#![feature(inclusive_range_fields)]
43+
#![feature(crate_visibility_modifier)]
44+
#![feature(never_type)]
45+
#![cfg_attr(stage0, feature(try_trait))]
4346

4447
extern crate arena;
4548
#[macro_use]

src/librustc_typeck/check/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
22002200
}
22012201

22022202
// Tries to apply a fallback to `ty` if it is an unsolved variable.
2203-
// Non-numerics get replaced with !, unconstrained ints with i32,
2203+
// Non-numerics get replaced with ! or () (depending on whether
2204+
// feature(never_type) is enabled, unconstrained ints with i32,
22042205
// unconstrained floats with f64.
22052206
// Fallback becomes very dubious if we have encountered type-checking errors.
22062207
// In that case, fallback to TyError.
@@ -2214,7 +2215,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
22142215
_ if self.is_tainted_by_errors() => self.tcx().types.err,
22152216
UnconstrainedInt => self.tcx.types.i32,
22162217
UnconstrainedFloat => self.tcx.types.f64,
2217-
Neither if self.type_var_diverges(ty) => self.tcx.types.never,
2218+
Neither if self.type_var_diverges(ty) => self.tcx.mk_diverging_default(),
22182219
Neither => return false,
22192220
};
22202221
debug!("default_type_parameters: defaulting `{:?}` to `{:?}`", ty, fallback);

src/librustc_typeck/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ This API is completely unstable and subject to change.
8989
#![cfg_attr(stage0, feature(i128_type))]
9090
#![cfg_attr(stage0, feature(never_type))]
9191
#![feature(dyn_trait)]
92+
#![feature(never_type)]
9293

9394
#[macro_use] extern crate log;
9495
#[macro_use] extern crate syntax;

src/libstd/error.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<'a> From<Cow<'a, str>> for Box<Error> {
233233
}
234234
}
235235

236-
#[stable(feature = "never_type", since = "1.26.0")]
236+
#[unstable(feature = "never_type", issue = "35121")]
237237
impl Error for ! {
238238
fn description(&self) -> &str { *self }
239239
}
@@ -275,14 +275,14 @@ impl Error for num::ParseIntError {
275275
}
276276
}
277277

278-
#[stable(feature = "try_from", since = "1.26.0")]
278+
#[unstable(feature = "try_from", issue = "33417")]
279279
impl Error for num::TryFromIntError {
280280
fn description(&self) -> &str {
281281
self.__description()
282282
}
283283
}
284284

285-
#[stable(feature = "try_from", since = "1.26.0")]
285+
#[unstable(feature = "try_from", issue = "33417")]
286286
impl Error for array::TryFromSliceError {
287287
fn description(&self) -> &str {
288288
self.__description()
@@ -356,7 +356,7 @@ impl Error for cell::BorrowMutError {
356356
}
357357
}
358358

359-
#[stable(feature = "try_from", since = "1.26.0")]
359+
#[unstable(feature = "try_from", issue = "33417")]
360360
impl Error for char::CharTryFromError {
361361
fn description(&self) -> &str {
362362
"converted integer out of range for `char`"

src/libstd/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
#![feature(macro_reexport)]
281281
#![feature(macro_vis_matcher)]
282282
#![feature(needs_panic_runtime)]
283+
#![feature(never_type)]
283284
#![feature(exhaustive_patterns)]
284285
#![feature(nonzero)]
285286
#![feature(num_bits_bytes)]
@@ -311,6 +312,7 @@
311312
#![feature(test, rustc_private)]
312313
#![feature(thread_local)]
313314
#![feature(toowned_clone_into)]
315+
#![feature(try_from)]
314316
#![feature(try_reserve)]
315317
#![feature(unboxed_closures)]
316318
#![feature(unicode)]

0 commit comments

Comments
 (0)