From f753a6ef0252689930fbfdf39859bf80c0388955 Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 23 Feb 2017 21:35:12 +0100 Subject: [PATCH] Feature gate --- src/librustc_typeck/check/coercion.rs | 9 +++++++++ src/libsyntax/feature_gate.rs | 7 +++++++ src/test/run-pass/closure-to-fn-coercion.rs | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index e9ac0a58d3644..ab498b453dde1 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -74,6 +74,7 @@ use rustc::ty::error::TypeError; use rustc::ty::relate::RelateResult; use syntax::ast::NodeId; use syntax::abi; +use syntax::feature_gate; use util::common::indent; use std::cell::RefCell; @@ -575,6 +576,14 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> { let node_id_a :NodeId = self.tcx.hir.as_local_node_id(def_id_a).unwrap(); match b.sty { ty::TyFnPtr(_) if self.tcx.with_freevars(node_id_a, |v| v.is_empty()) => { + if !self.tcx.sess.features.borrow().closure_to_fn_coercion { + feature_gate::emit_feature_err(&self.tcx.sess.parse_sess, + "closure_to_fn_coercion", + self.cause.span, + feature_gate::GateIssue::Language, + feature_gate::CLOSURE_TO_FN_COERCION); + return self.unify_and_identity(a, b); + } // We coerce the closure, which has fn type // `extern "rust-call" fn((arg0,arg1,...)) -> _` // to diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 1bed3e2784773..2d3fd78867a2d 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -323,6 +323,10 @@ declare_features! ( // `extern "msp430-interrupt" fn()` (active, abi_msp430_interrupt, "1.16.0", Some(38487)), + // Used to identify crates that contain sanitizer runtimes + // rustc internal + (active, closure_to_fn_coercion, "1.17.0", Some(39817)), + // Used to identify crates that contain sanitizer runtimes // rustc internal (active, sanitizer_runtime, "1.17.0", None), @@ -977,6 +981,9 @@ pub const EXPLAIN_DERIVE_UNDERSCORE: &'static str = pub const EXPLAIN_PLACEMENT_IN: &'static str = "placement-in expression syntax is experimental and subject to change."; +pub const CLOSURE_TO_FN_COERCION: &'static str = + "non-capturing closure to fn coercion is experimental"; + struct PostExpansionVisitor<'a> { context: &'a Context<'a>, } diff --git a/src/test/run-pass/closure-to-fn-coercion.rs b/src/test/run-pass/closure-to-fn-coercion.rs index c4d0bbdd0704c..f3f0736041b54 100644 --- a/src/test/run-pass/closure-to-fn-coercion.rs +++ b/src/test/run-pass/closure-to-fn-coercion.rs @@ -10,7 +10,7 @@ // ignore-stage0: new feature, remove this when SNAP -// #![feature(closure_to_fn_coercion)] +#![feature(closure_to_fn_coercion)] const FOO :fn(u8) -> u8 = |v: u8| { v };