Skip to content

Commit bd01175

Browse files
author
Ariel Ben-Yehuda
committed
clarify the parenthetical notation stability error message
This also calls the right API, which e.g. prevents a suggestion for #![feature(unboxed_closures)] on stable. Fixes #26970
1 parent 4c371bb commit bd01175

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ use util::nodemap::FnvHashSet;
6969
use std::slice;
7070
use syntax::{abi, ast, ast_util};
7171
use syntax::codemap::{Span, Pos};
72+
use syntax::feature_gate::emit_feature_err;
7273
use syntax::parse::token;
7374
use syntax::print::pprust;
7475

@@ -791,12 +792,11 @@ fn create_substs_for_ast_trait_ref<'a,'tcx>(this: &AstConv<'tcx>,
791792
// For now, require that parenthetical notation be used
792793
// only with `Fn()` etc.
793794
if !this.tcx().sess.features.borrow().unboxed_closures && trait_def.paren_sugar {
794-
span_err!(this.tcx().sess, span, E0215,
795-
"angle-bracket notation is not stable when \
796-
used with the `Fn` family of traits, use parentheses");
797-
fileline_help!(this.tcx().sess, span,
798-
"add `#![feature(unboxed_closures)]` to \
799-
the crate attributes to enable");
795+
emit_feature_err(&this.tcx().sess.parse_sess.span_diagnostic,
796+
"unboxed_closures", span,
797+
"\
798+
the precise format of `Fn`-family traits' type parameters is \
799+
subject to change. Use parenthetical notation (Fn(Foo, Bar) -> Baz) instead");
800800
}
801801

802802
convert_angle_bracketed_parameters(this, rscope, span, &trait_def.generics, data)
@@ -805,12 +805,10 @@ fn create_substs_for_ast_trait_ref<'a,'tcx>(this: &AstConv<'tcx>,
805805
// For now, require that parenthetical notation be used
806806
// only with `Fn()` etc.
807807
if !this.tcx().sess.features.borrow().unboxed_closures && !trait_def.paren_sugar {
808-
span_err!(this.tcx().sess, span, E0216,
809-
"parenthetical notation is only stable when \
810-
used with the `Fn` family of traits");
811-
fileline_help!(this.tcx().sess, span,
812-
"add `#![feature(unboxed_closures)]` to \
813-
the crate attributes to enable");
808+
emit_feature_err(&this.tcx().sess.parse_sess.span_diagnostic,
809+
"unboxed_closures", span,
810+
"\
811+
parenthetical notation is only stable when used with `Fn`-family traits");
814812
}
815813

816814
convert_parenthesized_parameters(this, rscope, span, &trait_def.generics, data)

src/librustc_typeck/diagnostics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,14 +2319,14 @@ register_diagnostics! {
23192319
E0212, // cannot extract an associated type from a higher-ranked trait bound
23202320
E0213, // associated types are not accepted in this context
23212321
E0214, // parenthesized parameters may only be used with a trait
2322-
E0215, // angle-bracket notation is not stable with `Fn`
2323-
E0216, // parenthetical notation is only stable with `Fn`
2322+
// E0215, // angle-bracket notation is not stable with `Fn`
2323+
// E0216, // parenthetical notation is only stable with `Fn`
23242324
E0217, // ambiguous associated type, defined in multiple supertraits
23252325
E0218, // no associated type defined
23262326
E0219, // associated type defined in higher-ranked supertrait
23272327
E0221, // ambiguous associated type in bounds
2328-
//E0222, // Error code E0045 (variadic function must have C calling
2329-
// convention) duplicate
2328+
// E0222, // Error code E0045 (variadic function must have C calling
2329+
// convention) duplicate
23302330
E0224, // at least one non-builtin train is required for an object type
23312331
E0226, // only a single explicit lifetime bound is permitted
23322332
E0227, // ambiguous lifetime bound, explicit lifetime bound required

src/test/compile-fail/unboxed-closure-feature-gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait Foo<A> {
2121

2222
fn main() {
2323
let x: Box<Foo(isize)>;
24-
//~^ ERROR parenthetical notation is only stable when used with the `Fn` family
24+
//~^ ERROR parenthetical notation is only stable when used with `Fn`-family
2525

2626
// No errors with these:
2727
let x: Box<Fn(isize)>;

src/test/compile-fail/unboxed-closure-sugar-not-used-on-fn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// Test that the `Fn` traits require `()` form without a feature gate.
1313

1414
fn bar1(x: &Fn<(), Output=()>) {
15-
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family
15+
//~^ ERROR of `Fn`-family traits' type parameters is subject to change
1616
}
1717

1818
fn bar2<T>(x: &T) where T: Fn<()> {
19-
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family
19+
//~^ ERROR of `Fn`-family traits' type parameters is subject to change
2020
}
2121

2222
fn main() { }

0 commit comments

Comments
 (0)