Skip to content

Commit 60d8c66

Browse files
committed
Auto merge of #50939 - pietroalbini:beta-backports, r=alexcrichton
[beta] Process backports Merged in master and accepted: * #50758: Stabilise inclusive_range_methods * #50656: Fix `fn main() -> impl Trait` for non-`Termination` trait r? @alexcrichton
2 parents 84b5a46 + c05689b commit 60d8c66

File tree

11 files changed

+69
-23
lines changed

11 files changed

+69
-23
lines changed

src/liballoc/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#![feature(try_reserve)]
2626
#![feature(unboxed_closures)]
2727
#![feature(exact_chunks)]
28-
#![feature(inclusive_range_methods)]
2928

3029
extern crate alloc_system;
3130
extern crate core;

src/libcore/ops/range.rs

+25-10
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
318318
/// # Examples
319319
///
320320
/// ```
321-
/// #![feature(inclusive_range_methods)]
322-
///
323321
/// assert_eq!((3..=5), std::ops::RangeInclusive::new(3, 5));
324322
/// assert_eq!(3 + 4 + 5, (3..=5).sum());
325323
///
@@ -355,12 +353,11 @@ impl<Idx> RangeInclusive<Idx> {
355353
/// # Examples
356354
///
357355
/// ```
358-
/// #![feature(inclusive_range_methods)]
359356
/// use std::ops::RangeInclusive;
360357
///
361358
/// assert_eq!(3..=5, RangeInclusive::new(3, 5));
362359
/// ```
363-
#[unstable(feature = "inclusive_range_methods", issue = "49022")]
360+
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
364361
#[inline]
365362
pub const fn new(start: Idx, end: Idx) -> Self {
366363
Self { start, end }
@@ -373,17 +370,18 @@ impl<Idx> RangeInclusive<Idx> {
373370
/// whether the inclusive range is empty, use the [`is_empty()`] method
374371
/// instead of comparing `start() > end()`.
375372
///
373+
/// Note: the value returned by this method is unspecified after the range
374+
/// has been iterated to exhaustion.
375+
///
376376
/// [`end()`]: #method.end
377377
/// [`is_empty()`]: #method.is_empty
378378
///
379379
/// # Examples
380380
///
381381
/// ```
382-
/// #![feature(inclusive_range_methods)]
383-
///
384382
/// assert_eq!((3..=5).start(), &3);
385383
/// ```
386-
#[unstable(feature = "inclusive_range_methods", issue = "49022")]
384+
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
387385
#[inline]
388386
pub fn start(&self) -> &Idx {
389387
&self.start
@@ -396,21 +394,38 @@ impl<Idx> RangeInclusive<Idx> {
396394
/// whether the inclusive range is empty, use the [`is_empty()`] method
397395
/// instead of comparing `start() > end()`.
398396
///
397+
/// Note: the value returned by this method is unspecified after the range
398+
/// has been iterated to exhaustion.
399+
///
399400
/// [`start()`]: #method.start
400401
/// [`is_empty()`]: #method.is_empty
401402
///
402403
/// # Examples
403404
///
404405
/// ```
405-
/// #![feature(inclusive_range_methods)]
406-
///
407406
/// assert_eq!((3..=5).end(), &5);
408407
/// ```
409-
#[unstable(feature = "inclusive_range_methods", issue = "49022")]
408+
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
410409
#[inline]
411410
pub fn end(&self) -> &Idx {
412411
&self.end
413412
}
413+
414+
/// Destructures the `RangeInclusive` into (lower bound, upper (inclusive) bound).
415+
///
416+
/// Note: the value returned by this method is unspecified after the range
417+
/// has been iterated to exhaustion.
418+
///
419+
/// # Examples
420+
///
421+
/// ```
422+
/// assert_eq!((3..=5).into_inner(), (3, 5));
423+
/// ```
424+
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
425+
#[inline]
426+
pub fn into_inner(self) -> (Idx, Idx) {
427+
(self.start, self.end)
428+
}
414429
}
415430

416431
#[stable(feature = "inclusive_range", since = "1.26.0")]

src/libcore/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#![feature(exact_chunks)]
4545
#![cfg_attr(stage0, feature(atomic_nand))]
4646
#![feature(reverse_bits)]
47-
#![feature(inclusive_range_methods)]
4847
#![feature(iterator_find_map)]
4948
#![feature(slice_internals)]
5049

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
#![feature(trusted_len)]
7070
#![feature(catch_expr)]
7171
#![feature(test)]
72-
#![feature(inclusive_range_methods)]
7372

7473
#![recursion_limit="512"]
7574

src/librustc_mir/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
3131
#![feature(range_contains)]
3232
#![feature(rustc_diagnostic_macros)]
3333
#![feature(nonzero)]
34-
#![feature(inclusive_range_methods)]
3534
#![feature(crate_visibility_modifier)]
3635
#![feature(never_type)]
3736
#![feature(specialization)]

src/librustc_target/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#![feature(const_fn)]
3030
#![feature(fs_read_write)]
3131
#![feature(inclusive_range)]
32-
#![feature(inclusive_range_methods)]
3332
#![feature(slice_patterns)]
3433

3534
#[macro_use]

src/librustc_trans/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#![feature(rustc_diagnostic_macros)]
3030
#![feature(slice_sort_by_cached_key)]
3131
#![feature(optin_builtin_traits)]
32-
#![feature(inclusive_range_methods)]
3332

3433
use rustc::dep_graph::WorkProduct;
3534
use syntax_pos::symbol::Symbol;

src/librustc_typeck/check/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1036,13 +1036,13 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
10361036
let mut fcx = FnCtxt::new(inherited, param_env, body.value.id);
10371037
*fcx.ps.borrow_mut() = UnsafetyState::function(fn_sig.unsafety, fn_id);
10381038

1039-
let ret_ty = fn_sig.output();
1040-
fcx.require_type_is_sized(ret_ty, decl.output.span(), traits::SizedReturnType);
1041-
let ret_ty = fcx.instantiate_anon_types_from_return_value(fn_id, &ret_ty);
1042-
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
1039+
let declared_ret_ty = fn_sig.output();
1040+
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
1041+
let revealed_ret_ty = fcx.instantiate_anon_types_from_return_value(fn_id, &declared_ret_ty);
1042+
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(revealed_ret_ty)));
10431043
fn_sig = fcx.tcx.mk_fn_sig(
10441044
fn_sig.inputs().iter().cloned(),
1045-
ret_ty,
1045+
revealed_ret_ty,
10461046
fn_sig.variadic,
10471047
fn_sig.unsafety,
10481048
fn_sig.abi
@@ -1124,15 +1124,15 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
11241124
actual_return_ty = fcx.next_diverging_ty_var(
11251125
TypeVariableOrigin::DivergingFn(span));
11261126
}
1127-
fcx.demand_suptype(span, ret_ty, actual_return_ty);
1127+
fcx.demand_suptype(span, revealed_ret_ty, actual_return_ty);
11281128

11291129
// Check that the main return type implements the termination trait.
11301130
if let Some(term_id) = fcx.tcx.lang_items().termination() {
11311131
if let Some((id, _, entry_type)) = *fcx.tcx.sess.entry_fn.borrow() {
11321132
if id == fn_id {
11331133
match entry_type {
11341134
config::EntryMain => {
1135-
let substs = fcx.tcx.mk_substs(iter::once(Kind::from(ret_ty)));
1135+
let substs = fcx.tcx.mk_substs(iter::once(Kind::from(declared_ret_ty)));
11361136
let trait_ref = ty::TraitRef::new(term_id, substs);
11371137
let return_ty_span = decl.output.span();
11381138
let cause = traits::ObligationCause::new(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(termination_trait_lib)]
12+
13+
fn main() -> impl std::process::Termination { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that an `impl Trait` that is not `impl Termination` will not work.
12+
fn main() -> impl Copy { }
13+
//~^ ERROR `main` has invalid return type `impl std::marker::Copy`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0277]: `main` has invalid return type `impl std::marker::Copy`
2+
--> $DIR/termination-trait-impl-trait.rs:12:14
3+
|
4+
LL | fn main() -> impl Copy { }
5+
| ^^^^^^^^^ `main` can only return types that implement `std::process::Termination`
6+
|
7+
= help: consider using `()`, or a `Result`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)