Skip to content

Commit

Permalink
Feature-gate <> syntax used with Fn. Fixes #18875.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jan 10, 2015
1 parent 3975af5 commit 152d623
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -582,6 +582,19 @@ fn ast_path_to_trait_ref<'a,'tcx>(

let (regions, types, assoc_bindings) = match path.segments.last().unwrap().parameters {
ast::AngleBracketedParameters(ref data) => {
// For now, require that parenthetical notation be used
// only with `Fn()` etc.
if !this.tcx().sess.features.borrow().unboxed_closures &&
this.tcx().lang_items.fn_trait_kind(trait_def_id).is_some()
{
this.tcx().sess.span_err(path.span,
"angle-bracket notation is not stable when \
used with the `Fn` family of traits, use parentheses");
span_help!(this.tcx().sess, path.span,
"add `#![feature(unboxed_closures)]` to \
the crate attributes to enable");
}

convert_angle_bracketed_parameters(this, &shifted_rscope, data)
}
ast::ParenthesizedParameters(ref data) => {
Expand Down
Expand Up @@ -11,15 +11,15 @@
#![allow(dead_code)]

struct Foo;
impl Fn<(), ()> for Foo { //~ ERROR manual implementations of `Fn` are experimental
impl Fn() for Foo { //~ ERROR manual implementations of `Fn` are experimental
extern "rust-call" fn call(&self, args: ()) -> () {}
}
struct Bar;
impl FnMut<(), ()> for Bar { //~ ERROR manual implementations of `FnMut` are experimental
impl FnMut() for Bar { //~ ERROR manual implementations of `FnMut` are experimental
extern "rust-call" fn call_mut(&self, args: ()) -> () {}
}
struct Baz;
impl FnOnce<(), ()> for Baz { //~ ERROR manual implementations of `FnOnce` are experimental
impl FnOnce() for Baz { //~ ERROR manual implementations of `FnOnce` are experimental
extern "rust-call" fn call_once(&self, args: ()) -> () {}
}

Expand Down
Expand Up @@ -10,7 +10,7 @@

#![allow(dead_code)]

fn foo<F: Fn<(), ()>>(mut f: F) {
fn foo<F: Fn()>(mut f: F) {
f.call(()); //~ ERROR explicit use of unboxed closure method `call`
f.call_mut(()); //~ ERROR explicit use of unboxed closure method `call_mut`
f.call_once(()); //~ ERROR explicit use of unboxed closure method `call_once`
Expand Down
Expand Up @@ -10,7 +10,7 @@

#![allow(dead_code)]

fn foo<F: Fn<(), ()>>(mut f: F, mut g: F) {
fn foo<F: Fn()>(mut f: F, mut g: F) {
Fn::call(&g, ()); //~ ERROR explicit use of unboxed closure method `call`
FnMut::call_mut(&mut g, ()); //~ ERROR explicit use of unboxed closure method `call_mut`
FnOnce::call_once(g, ()); //~ ERROR explicit use of unboxed closure method `call_once`
Expand Down
23 changes: 23 additions & 0 deletions src/test/compile-fail/unboxed-closure-sugar-not-used-on-fn.rs
@@ -0,0 +1,23 @@
// Copyright 2014 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.


// Test that the `Fn` traits require `()` form without a feature gate.

fn bar1(x: &Fn<(),()>) {
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family
}

fn bar2<T>(x: &T) where T: Fn<(),()> {
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family
}

fn main() { }

8 comments on commit 152d623

@nikomatsakis
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=huonw

@bors
Copy link
Contributor

@bors bors commented on 152d623 Jan 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at nikomatsakis@152d623

@bors
Copy link
Contributor

@bors bors commented on 152d623 Jan 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nikomatsakis/rust/issue-18875 = 152d623 into auto

@bors
Copy link
Contributor

@bors bors commented on 152d623 Jan 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status: {"merge_sha": "099b411e080d302ec0dc5f3aebe53d76c50acfc7"}

@bors
Copy link
Contributor

@bors bors commented on 152d623 Jan 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nikomatsakis/rust/issue-18875 = 152d623 merged ok, testing candidate = 099b411

@bors
Copy link
Contributor

@bors bors commented on 152d623 Jan 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 099b411

@bors
Copy link
Contributor

@bors bors commented on 152d623 Jan 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 099b411

Please sign in to comment.