Skip to content

Commit f753a6e

Browse files
committed
Feature gate
1 parent 1b9b322 commit f753a6e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/librustc_typeck/check/coercion.rs

+9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ use rustc::ty::error::TypeError;
7474
use rustc::ty::relate::RelateResult;
7575
use syntax::ast::NodeId;
7676
use syntax::abi;
77+
use syntax::feature_gate;
7778
use util::common::indent;
7879

7980
use std::cell::RefCell;
@@ -575,6 +576,14 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
575576
let node_id_a :NodeId = self.tcx.hir.as_local_node_id(def_id_a).unwrap();
576577
match b.sty {
577578
ty::TyFnPtr(_) if self.tcx.with_freevars(node_id_a, |v| v.is_empty()) => {
579+
if !self.tcx.sess.features.borrow().closure_to_fn_coercion {
580+
feature_gate::emit_feature_err(&self.tcx.sess.parse_sess,
581+
"closure_to_fn_coercion",
582+
self.cause.span,
583+
feature_gate::GateIssue::Language,
584+
feature_gate::CLOSURE_TO_FN_COERCION);
585+
return self.unify_and_identity(a, b);
586+
}
578587
// We coerce the closure, which has fn type
579588
// `extern "rust-call" fn((arg0,arg1,...)) -> _`
580589
// to

src/libsyntax/feature_gate.rs

+7
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ declare_features! (
323323
// `extern "msp430-interrupt" fn()`
324324
(active, abi_msp430_interrupt, "1.16.0", Some(38487)),
325325

326+
// Used to identify crates that contain sanitizer runtimes
327+
// rustc internal
328+
(active, closure_to_fn_coercion, "1.17.0", Some(39817)),
329+
326330
// Used to identify crates that contain sanitizer runtimes
327331
// rustc internal
328332
(active, sanitizer_runtime, "1.17.0", None),
@@ -977,6 +981,9 @@ pub const EXPLAIN_DERIVE_UNDERSCORE: &'static str =
977981
pub const EXPLAIN_PLACEMENT_IN: &'static str =
978982
"placement-in expression syntax is experimental and subject to change.";
979983

984+
pub const CLOSURE_TO_FN_COERCION: &'static str =
985+
"non-capturing closure to fn coercion is experimental";
986+
980987
struct PostExpansionVisitor<'a> {
981988
context: &'a Context<'a>,
982989
}

src/test/run-pass/closure-to-fn-coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-stage0: new feature, remove this when SNAP
1212

13-
// #![feature(closure_to_fn_coercion)]
13+
#![feature(closure_to_fn_coercion)]
1414

1515
const FOO :fn(u8) -> u8 = |v: u8| { v };
1616

0 commit comments

Comments
 (0)