diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index bd92f32e24b68..25bacacd85036 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -505,7 +505,8 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { gate_all!( closure_lifetime_binder, "`for<...>` binders for closures are experimental", - "consider removing `for<...>`" + "consider using a type annotation instead: \ + `let closure: for<...> fn(...) -> ... = /* closure */;`" ); gate_all!( half_open_range_patterns_in_slices, diff --git a/tests/ui/const-generics/generic_const_exprs/const-generics-closure.stderr b/tests/ui/const-generics/generic_const_exprs/const-generics-closure.stderr index 5410bbdc12536..3ab2d6676724b 100644 --- a/tests/ui/const-generics/generic_const_exprs/const-generics-closure.stderr +++ b/tests/ui/const-generics/generic_const_exprs/const-generics-closure.stderr @@ -7,7 +7,7 @@ LL | let _ = for<'a, 'b> |x: &'a &'a Vec<&'b u32>, b: bool| -> &'a Vec<& = note: see issue #97362 for more information = help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = help: consider removing `for<...>` + = help: consider using a type annotation instead: `let closure: for<...> fn(...) -> ... = /* closure */;` error[E0308]: mismatched types --> $DIR/const-generics-closure.rs:4:10 diff --git a/tests/ui/expr/malformed_closure/missing-braces-before-close-brace.stderr b/tests/ui/expr/malformed_closure/missing-braces-before-close-brace.stderr index baf6a9dd9f4c9..533c1432611a3 100644 --- a/tests/ui/expr/malformed_closure/missing-braces-before-close-brace.stderr +++ b/tests/ui/expr/malformed_closure/missing-braces-before-close-brace.stderr @@ -27,7 +27,7 @@ LL | for<> || -> () {}; = note: see issue #97362 for more information = help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = help: consider removing `for<...>` + = help: consider using a type annotation instead: `let closure: for<...> fn(...) -> ... = /* closure */;` error[E0658]: `for<...>` binders for closures are experimental --> $DIR/missing-braces-before-close-brace.rs:6:5 @@ -38,7 +38,7 @@ LL | for<'a> || -> () |_; = note: see issue #97362 for more information = help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = help: consider removing `for<...>` + = help: consider using a type annotation instead: `let closure: for<...> fn(...) -> ... = /* closure */;` error: aborting due to 5 previous errors diff --git a/tests/ui/feature-gates/feature-gate-closure_lifetime_binder.stderr b/tests/ui/feature-gates/feature-gate-closure_lifetime_binder.stderr index 96e428fb9a37e..d5306287b58d9 100644 --- a/tests/ui/feature-gates/feature-gate-closure_lifetime_binder.stderr +++ b/tests/ui/feature-gates/feature-gate-closure_lifetime_binder.stderr @@ -7,7 +7,7 @@ LL | for<> || -> () {}; = note: see issue #97362 for more information = help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = help: consider removing `for<...>` + = help: consider using a type annotation instead: `let closure: for<...> fn(...) -> ... = /* closure */;` error[E0658]: `for<...>` binders for closures are experimental --> $DIR/feature-gate-closure_lifetime_binder.rs:4:5 @@ -18,7 +18,7 @@ LL | for<'a> || -> () {}; = note: see issue #97362 for more information = help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = help: consider removing `for<...>` + = help: consider using a type annotation instead: `let closure: for<...> fn(...) -> ... = /* closure */;` error[E0658]: `for<...>` binders for closures are experimental --> $DIR/feature-gate-closure_lifetime_binder.rs:6:5 @@ -29,7 +29,7 @@ LL | for<'a, 'b> |_: &'a ()| -> () {}; = note: see issue #97362 for more information = help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = help: consider removing `for<...>` + = help: consider using a type annotation instead: `let closure: for<...> fn(...) -> ... = /* closure */;` error: aborting due to 3 previous errors diff --git a/tests/ui/parser/recover/recover-quantified-closure.stderr b/tests/ui/parser/recover/recover-quantified-closure.stderr index 96953b7beeede..095657882c36c 100644 --- a/tests/ui/parser/recover/recover-quantified-closure.stderr +++ b/tests/ui/parser/recover/recover-quantified-closure.stderr @@ -13,7 +13,7 @@ LL | for<'a> |x: &'a u8| *x + 1; = note: see issue #97362 for more information = help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = help: consider removing `for<...>` + = help: consider using a type annotation instead: `let closure: for<...> fn(...) -> ... = /* closure */;` error[E0658]: `for<...>` binders for closures are experimental --> $DIR/recover-quantified-closure.rs:10:5 @@ -24,7 +24,7 @@ LL | for ::Bar in x {} = note: see issue #97362 for more information = help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = help: consider removing `for<...>` + = help: consider using a type annotation instead: `let closure: for<...> fn(...) -> ... = /* closure */;` error: implicit types in closure signatures are forbidden when `for<...>` is present --> $DIR/recover-quantified-closure.rs:3:24