Skip to content

Commit 099b411

Browse files
committed
auto merge of #20869 : nikomatsakis/rust/issue-18875, r=huonw
Feature-gate `<>` syntax used with `Fn`. Fixes #18875. r? @huonw
2 parents 3b03c20 + 152d623 commit 099b411

5 files changed

+41
-5
lines changed

src/librustc_typeck/astconv.rs

+13
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,19 @@ fn ast_path_to_trait_ref<'a,'tcx>(
582582

583583
let (regions, types, assoc_bindings) = match path.segments.last().unwrap().parameters {
584584
ast::AngleBracketedParameters(ref data) => {
585+
// For now, require that parenthetical notation be used
586+
// only with `Fn()` etc.
587+
if !this.tcx().sess.features.borrow().unboxed_closures &&
588+
this.tcx().lang_items.fn_trait_kind(trait_def_id).is_some()
589+
{
590+
this.tcx().sess.span_err(path.span,
591+
"angle-bracket notation is not stable when \
592+
used with the `Fn` family of traits, use parentheses");
593+
span_help!(this.tcx().sess, path.span,
594+
"add `#![feature(unboxed_closures)]` to \
595+
the crate attributes to enable");
596+
}
597+
585598
convert_angle_bracketed_parameters(this, &shifted_rscope, data)
586599
}
587600
ast::ParenthesizedParameters(ref data) => {

src/test/compile-fail/feature-gate-unboxed-closures-manual-impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
#![allow(dead_code)]
1212

1313
struct Foo;
14-
impl Fn<(), ()> for Foo { //~ ERROR manual implementations of `Fn` are experimental
14+
impl Fn() for Foo { //~ ERROR manual implementations of `Fn` are experimental
1515
extern "rust-call" fn call(&self, args: ()) -> () {}
1616
}
1717
struct Bar;
18-
impl FnMut<(), ()> for Bar { //~ ERROR manual implementations of `FnMut` are experimental
18+
impl FnMut() for Bar { //~ ERROR manual implementations of `FnMut` are experimental
1919
extern "rust-call" fn call_mut(&self, args: ()) -> () {}
2020
}
2121
struct Baz;
22-
impl FnOnce<(), ()> for Baz { //~ ERROR manual implementations of `FnOnce` are experimental
22+
impl FnOnce() for Baz { //~ ERROR manual implementations of `FnOnce` are experimental
2323
extern "rust-call" fn call_once(&self, args: ()) -> () {}
2424
}
2525

src/test/compile-fail/feature-gate-unboxed-closures-method-calls.rs

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

1111
#![allow(dead_code)]
1212

13-
fn foo<F: Fn<(), ()>>(mut f: F) {
13+
fn foo<F: Fn()>(mut f: F) {
1414
f.call(()); //~ ERROR explicit use of unboxed closure method `call`
1515
f.call_mut(()); //~ ERROR explicit use of unboxed closure method `call_mut`
1616
f.call_once(()); //~ ERROR explicit use of unboxed closure method `call_once`

src/test/compile-fail/feature-gate-unboxed-closures-ufcs-calls.rs

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

1111
#![allow(dead_code)]
1212

13-
fn foo<F: Fn<(), ()>>(mut f: F, mut g: F) {
13+
fn foo<F: Fn()>(mut f: F, mut g: F) {
1414
Fn::call(&g, ()); //~ ERROR explicit use of unboxed closure method `call`
1515
FnMut::call_mut(&mut g, ()); //~ ERROR explicit use of unboxed closure method `call_mut`
1616
FnOnce::call_once(g, ()); //~ ERROR explicit use of unboxed closure method `call_once`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
// Test that the `Fn` traits require `()` form without a feature gate.
13+
14+
fn bar1(x: &Fn<(),()>) {
15+
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family
16+
}
17+
18+
fn bar2<T>(x: &T) where T: Fn<(),()> {
19+
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family
20+
}
21+
22+
fn main() { }
23+

0 commit comments

Comments
 (0)