Skip to content

Commit

Permalink
Feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Feb 23, 2017
1 parent 1b9b322 commit f753a6e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/librustc_typeck/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ declare_features! (
// `extern "msp430-interrupt" fn()`
(active, abi_msp430_interrupt, "1.16.0", Some(38487)),

This comment has been minimized.

Copy link
@whitequark

whitequark Mar 4, 2017

Member

@est31 I think this comment is a merge screwup

This comment has been minimized.

Copy link
@est31

est31 Mar 4, 2017

Author Member

Oh indeed. Do you want me to file a PR? Otherwise, you are welcome to do it.

This comment has been minimized.

Copy link
@whitequark

whitequark Mar 4, 2017

Member

I think you're in a better position to describe this feature gate.

// 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),
Expand Down Expand Up @@ -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>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/closure-to-fn-coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down

0 comments on commit f753a6e

Please sign in to comment.