From 93c1f2472bd627955e44970de075c2e90f246501 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 15 May 2017 22:11:16 +0200 Subject: [PATCH] Stabilize the loop_break_value feature --- src/doc/unstable-book/src/SUMMARY.md | 1 - .../src/language-features/loop-break-value.md | 83 ------------------- src/librustc/lib.rs | 2 +- src/librustc_driver/lib.rs | 2 +- src/librustc_typeck/lib.rs | 2 +- src/libsyntax/feature_gate.rs | 9 +- .../feature-gate-loop-break-value.rs | 15 ---- src/test/compile-fail/loop-break-value.rs | 1 - .../diverging-fallback-control-flow.rs | 1 - src/test/run-pass/loop-break-value.rs | 1 - src/test/ui/loop-break-value-no-repeat.rs | 1 - src/test/ui/loop-break-value-no-repeat.stderr | 4 +- 12 files changed, 7 insertions(+), 115 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/loop-break-value.md delete mode 100644 src/test/compile-fail/feature-gate-loop-break-value.rs diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 39f800591483b..deed3c50ee1c6 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -49,7 +49,6 @@ - [link_llvm_intrinsics](language-features/link-llvm-intrinsics.md) - [linkage](language-features/linkage.md) - [log_syntax](language-features/log-syntax.md) - - [loop_break_value](language-features/loop-break-value.md) - [macro_reexport](language-features/macro-reexport.md) - [macro_vis_matcher](language-features/macro-vis-matcher.md) - [main](language-features/main.md) diff --git a/src/doc/unstable-book/src/language-features/loop-break-value.md b/src/doc/unstable-book/src/language-features/loop-break-value.md deleted file mode 100644 index e8fefe3b73344..0000000000000 --- a/src/doc/unstable-book/src/language-features/loop-break-value.md +++ /dev/null @@ -1,83 +0,0 @@ -# `loop_break_value` - -The tracking issue for this feature is: [#37339] - -[#37339]: https://github.com/rust-lang/rust/issues/37339 - -Documentation to be appended to section G of the book. - ------------------------- - -### Loops as expressions - -Like most things in Rust, loops are expressions, and have a value; normally `()` unless the loop -never exits. -A `loop` can instead evaluate to a useful value via *break with value*: - -```rust -#![feature(loop_break_value)] - -// Find the first square number over 1000: -let mut n = 1; -let square = loop { - if n * n > 1000 { - break n * n; - } - n += 1; -}; -``` - -The evaluation type may be specified externally: - -```rust -#![feature(loop_break_value)] - -// Declare that value returned is unsigned 64-bit: -let n: u64 = loop { - break 1; -}; -``` - -It is an error if types do not agree, either between a "break" value and an external requirement, -or between multiple "break" values: - -```no_compile -#![feature(loop_break_value)] - -loop { - if true { - break 1u32; - } else { - break 0u8; // error: types do not agree - } -}; - -let n: i32 = loop { - break 0u32; // error: type does not agree with external requirement -}; -``` - -#### Break: label, value - -Four forms of `break` are available, where EXPR is some expression which evaluates to a value: - -1. `break;` -2. `break 'label;` -3. `break EXPR;` -4. `break 'label EXPR;` - -When no value is given, the value `()` is assumed, thus `break;` is equivalent to `break ();`. - -Using a label allows returning a value from an inner loop: - -```rust -#![feature(loop_break_value)] - -let result = 'outer: loop { - for n in 1..10 { - if n > 4 { - break 'outer n; - } - } -}; -``` diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index f32ee7900646b..2b4b5cc73337b 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -30,7 +30,6 @@ #![feature(core_intrinsics)] #![feature(i128_type)] #![feature(libc)] -#![feature(loop_break_value)] #![feature(never_type)] #![feature(nonzero)] #![feature(quote)] @@ -45,6 +44,7 @@ #![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))] #![cfg_attr(stage0, feature(rustc_private))] #![cfg_attr(stage0, feature(staged_api))] +#![cfg_attr(stage0, feature(loop_break_value))] #![recursion_limit="128"] diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 34f636d0b9a12..7742634ffb709 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -23,7 +23,6 @@ #![deny(warnings)] #![feature(box_syntax)] -#![feature(loop_break_value)] #![feature(libc)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] @@ -32,6 +31,7 @@ #![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))] #![cfg_attr(stage0, feature(rustc_private))] #![cfg_attr(stage0, feature(staged_api))] +#![cfg_attr(stage0, feature(loop_break_value))] extern crate arena; extern crate getopts; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 99ee1cff7fd22..6f2c73b892567 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -76,7 +76,6 @@ This API is completely unstable and subject to change. #![feature(box_patterns)] #![feature(box_syntax)] #![feature(conservative_impl_trait)] -#![feature(loop_break_value)] #![feature(never_type)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] @@ -84,6 +83,7 @@ This API is completely unstable and subject to change. #![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))] #![cfg_attr(stage0, feature(rustc_private))] #![cfg_attr(stage0, feature(staged_api))] +#![cfg_attr(stage0, feature(loop_break_value))] #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 09090ab873130..297c8e00ea3c8 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -297,9 +297,6 @@ declare_features! ( (active, use_extern_macros, "1.15.0", Some(35896)), - // Allows `break {expr}` with a value inside `loop`s. - (active, loop_break_value, "1.14.0", Some(37339)), - // Allows #[target_feature(...)] (active, target_feature, "1.15.0", None), @@ -423,6 +420,8 @@ declare_features! ( (accepted, pub_restricted, "1.18.0", Some(32409)), // The #![windows_subsystem] attribute (accepted, windows_subsystem, "1.18.0", Some(37499)), + // Allows `break {expr}` with a value inside `loop`s. + (accepted, loop_break_value, "1.19.0", Some(37339)), ); // If you change this, please modify src/doc/unstable-book as well. You must // move that documentation into the relevant place in the other docs, and @@ -1301,10 +1300,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } } } - ast::ExprKind::Break(_, Some(_)) => { - gate_feature_post!(&self, loop_break_value, e.span, - "`break` with a value is experimental"); - } ast::ExprKind::Lit(ref lit) => { if let ast::LitKind::Int(_, ref ty) = lit.node { match *ty { diff --git a/src/test/compile-fail/feature-gate-loop-break-value.rs b/src/test/compile-fail/feature-gate-loop-break-value.rs deleted file mode 100644 index 1632c40d59fdf..0000000000000 --- a/src/test/compile-fail/feature-gate-loop-break-value.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2016 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - loop { - break 123; //~ ERROR `break` with a value is experimental - } -} diff --git a/src/test/compile-fail/loop-break-value.rs b/src/test/compile-fail/loop-break-value.rs index a414321899203..938f7fba2a032 100644 --- a/src/test/compile-fail/loop-break-value.rs +++ b/src/test/compile-fail/loop-break-value.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(loop_break_value)] #![feature(never_type)] fn main() { diff --git a/src/test/run-pass/diverging-fallback-control-flow.rs b/src/test/run-pass/diverging-fallback-control-flow.rs index 656e90d2d52d7..723a98bcdfa0d 100644 --- a/src/test/run-pass/diverging-fallback-control-flow.rs +++ b/src/test/run-pass/diverging-fallback-control-flow.rs @@ -15,7 +15,6 @@ // like to revisit these and potentially change them. --nmatsakis #![feature(never_type)] -#![feature(loop_break_value)] trait BadDefault { fn default() -> Self; diff --git a/src/test/run-pass/loop-break-value.rs b/src/test/run-pass/loop-break-value.rs index 4906a8e71d7a4..1d5c83bc20d95 100644 --- a/src/test/run-pass/loop-break-value.rs +++ b/src/test/run-pass/loop-break-value.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(loop_break_value)] #![feature(never_type)] #[allow(unused)] diff --git a/src/test/ui/loop-break-value-no-repeat.rs b/src/test/ui/loop-break-value-no-repeat.rs index 790f796fae07f..b52d540fd7511 100644 --- a/src/test/ui/loop-break-value-no-repeat.rs +++ b/src/test/ui/loop-break-value-no-repeat.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(loop_break_value)] #![allow(unused_variables)] use std::ptr; diff --git a/src/test/ui/loop-break-value-no-repeat.stderr b/src/test/ui/loop-break-value-no-repeat.stderr index 0d99abd3907d8..c154ea6f8c2d6 100644 --- a/src/test/ui/loop-break-value-no-repeat.stderr +++ b/src/test/ui/loop-break-value-no-repeat.stderr @@ -1,7 +1,7 @@ error[E0571]: `break` with value from a `for` loop - --> $DIR/loop-break-value-no-repeat.rs:23:9 + --> $DIR/loop-break-value-no-repeat.rs:22:9 | -23 | break 22 +22 | break 22 | ^^^^^^^^ can only break with a value inside `loop` error: aborting due to previous error