提交 f753a6ef 编写于 作者: E est31

Feature gate

上级 1b9b3228
......@@ -74,6 +74,7 @@
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 @@ fn coerce_closure_to_fn(&self,
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
......
......@@ -323,6 +323,10 @@ pub fn new() -> 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 fn feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue: Ga
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>,
}
......
......@@ -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 };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册