Skip to content

Commit

Permalink
Auto merge of #50939 - pietroalbini:beta-backports, r=alexcrichton
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
bors committed May 21, 2018
2 parents 84b5a46 + c05689b commit 60d8c66
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#![feature(try_reserve)]
#![feature(unboxed_closures)]
#![feature(exact_chunks)]
#![feature(inclusive_range_methods)]

extern crate alloc_system;
extern crate core;
Expand Down
35 changes: 25 additions & 10 deletions src/libcore/ops/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
/// # Examples
///
/// ```
/// #![feature(inclusive_range_methods)]
///
/// assert_eq!((3..=5), std::ops::RangeInclusive::new(3, 5));
/// assert_eq!(3 + 4 + 5, (3..=5).sum());
///
Expand Down Expand Up @@ -355,12 +353,11 @@ impl<Idx> RangeInclusive<Idx> {
/// # Examples
///
/// ```
/// #![feature(inclusive_range_methods)]
/// use std::ops::RangeInclusive;
///
/// assert_eq!(3..=5, RangeInclusive::new(3, 5));
/// ```
#[unstable(feature = "inclusive_range_methods", issue = "49022")]
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
#[inline]
pub const fn new(start: Idx, end: Idx) -> Self {
Self { start, end }
Expand All @@ -373,17 +370,18 @@ impl<Idx> RangeInclusive<Idx> {
/// whether the inclusive range is empty, use the [`is_empty()`] method
/// instead of comparing `start() > end()`.
///
/// Note: the value returned by this method is unspecified after the range
/// has been iterated to exhaustion.
///
/// [`end()`]: #method.end
/// [`is_empty()`]: #method.is_empty
///
/// # Examples
///
/// ```
/// #![feature(inclusive_range_methods)]
///
/// assert_eq!((3..=5).start(), &3);
/// ```
#[unstable(feature = "inclusive_range_methods", issue = "49022")]
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
#[inline]
pub fn start(&self) -> &Idx {
&self.start
Expand All @@ -396,21 +394,38 @@ impl<Idx> RangeInclusive<Idx> {
/// whether the inclusive range is empty, use the [`is_empty()`] method
/// instead of comparing `start() > end()`.
///
/// Note: the value returned by this method is unspecified after the range
/// has been iterated to exhaustion.
///
/// [`start()`]: #method.start
/// [`is_empty()`]: #method.is_empty
///
/// # Examples
///
/// ```
/// #![feature(inclusive_range_methods)]
///
/// assert_eq!((3..=5).end(), &5);
/// ```
#[unstable(feature = "inclusive_range_methods", issue = "49022")]
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
#[inline]
pub fn end(&self) -> &Idx {
&self.end
}

/// Destructures the `RangeInclusive` into (lower bound, upper (inclusive) bound).
///
/// Note: the value returned by this method is unspecified after the range
/// has been iterated to exhaustion.
///
/// # Examples
///
/// ```
/// assert_eq!((3..=5).into_inner(), (3, 5));
/// ```
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
#[inline]
pub fn into_inner(self) -> (Idx, Idx) {
(self.start, self.end)
}
}

#[stable(feature = "inclusive_range", since = "1.26.0")]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#![feature(exact_chunks)]
#![cfg_attr(stage0, feature(atomic_nand))]
#![feature(reverse_bits)]
#![feature(inclusive_range_methods)]
#![feature(iterator_find_map)]
#![feature(slice_internals)]

Expand Down
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
#![feature(trusted_len)]
#![feature(catch_expr)]
#![feature(test)]
#![feature(inclusive_range_methods)]

#![recursion_limit="512"]

Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![feature(range_contains)]
#![feature(rustc_diagnostic_macros)]
#![feature(nonzero)]
#![feature(inclusive_range_methods)]
#![feature(crate_visibility_modifier)]
#![feature(never_type)]
#![feature(specialization)]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_target/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#![feature(const_fn)]
#![feature(fs_read_write)]
#![feature(inclusive_range)]
#![feature(inclusive_range_methods)]
#![feature(slice_patterns)]

#[macro_use]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_trans/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#![feature(rustc_diagnostic_macros)]
#![feature(slice_sort_by_cached_key)]
#![feature(optin_builtin_traits)]
#![feature(inclusive_range_methods)]

use rustc::dep_graph::WorkProduct;
use syntax_pos::symbol::Symbol;
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,13 +1036,13 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
let mut fcx = FnCtxt::new(inherited, param_env, body.value.id);
*fcx.ps.borrow_mut() = UnsafetyState::function(fn_sig.unsafety, fn_id);

let ret_ty = fn_sig.output();
fcx.require_type_is_sized(ret_ty, decl.output.span(), traits::SizedReturnType);
let ret_ty = fcx.instantiate_anon_types_from_return_value(fn_id, &ret_ty);
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
let declared_ret_ty = fn_sig.output();
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
let revealed_ret_ty = fcx.instantiate_anon_types_from_return_value(fn_id, &declared_ret_ty);
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(revealed_ret_ty)));
fn_sig = fcx.tcx.mk_fn_sig(
fn_sig.inputs().iter().cloned(),
ret_ty,
revealed_ret_ty,
fn_sig.variadic,
fn_sig.unsafety,
fn_sig.abi
Expand Down Expand Up @@ -1124,15 +1124,15 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
actual_return_ty = fcx.next_diverging_ty_var(
TypeVariableOrigin::DivergingFn(span));
}
fcx.demand_suptype(span, ret_ty, actual_return_ty);
fcx.demand_suptype(span, revealed_ret_ty, actual_return_ty);

// Check that the main return type implements the termination trait.
if let Some(term_id) = fcx.tcx.lang_items().termination() {
if let Some((id, _, entry_type)) = *fcx.tcx.sess.entry_fn.borrow() {
if id == fn_id {
match entry_type {
config::EntryMain => {
let substs = fcx.tcx.mk_substs(iter::once(Kind::from(ret_ty)));
let substs = fcx.tcx.mk_substs(iter::once(Kind::from(declared_ret_ty)));
let trait_ref = ty::TraitRef::new(term_id, substs);
let return_ty_span = decl.output.span();
let cause = traits::ObligationCause::new(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(termination_trait_lib)]

fn main() -> impl std::process::Termination { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Tests that an `impl Trait` that is not `impl Termination` will not work.
fn main() -> impl Copy { }
//~^ ERROR `main` has invalid return type `impl std::marker::Copy`
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0277]: `main` has invalid return type `impl std::marker::Copy`
--> $DIR/termination-trait-impl-trait.rs:12:14
|
LL | fn main() -> impl Copy { }
| ^^^^^^^^^ `main` can only return types that implement `std::process::Termination`
|
= help: consider using `()`, or a `Result`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 60d8c66

Please sign in to comment.