This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +17
-5
lines changed
compiler/rustc_hir_analysis/src Expand file tree Collapse file tree 5 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -1231,10 +1231,10 @@ fn infer_return_ty_for_fn_sig<'tcx>(
12311231 Applicability :: MachineApplicable ,
12321232 ) ;
12331233 } else if ret_ty. is_closure ( ) {
1234- // We're dealing with a closure, so we should suggest using `impl Fn` or trait bounds
1235- // to prevent the user from getting a papercut while trying to use the unique closure
1236- // syntax (e.g. `[closure@src/lib.rs:2:5: 2:9]`).
12371234 diag. help ( "consider using an `Fn`, `FnMut`, or `FnOnce` trait bound" ) ;
1235+ }
1236+ // Also note how `Fn` traits work just in case!
1237+ if ret_ty. is_closure ( ) {
12381238 diag. note (
12391239 "for more information on `Fn` traits and closure types, see \
12401240 https://doc.rust-lang.org/book/ch13-01-closures.html",
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ fn returns_closure() -> _ {
2020//~| NOTE not allowed in type signatures
2121//~| HELP replace with an appropriate return type
2222//~| SUGGESTION impl Fn() -> i32
23+ //~| NOTE for more information on `Fn` traits and closure types
2324 || 0
2425}
2526
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ LL | fn returns_closure() -> _ {
1515 | |
1616 | not allowed in type signatures
1717 | help: replace with an appropriate return type: `impl Fn() -> i32`
18+ |
19+ = note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
1820
1921error: aborting due to 2 previous errors
2022
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ fn fn_once() -> _ {
33 //~| NOTE not allowed in type signatures
44 //~| HELP replace with an appropriate return type
55 //~| SUGGESTION impl FnOnce()
6+ //~| NOTE for more information on `Fn` traits and closure types
67 let x = String :: new ( ) ;
78 || {
89 drop ( x) ;
@@ -14,6 +15,7 @@ fn fn_mut() -> _ {
1415 //~| NOTE not allowed in type signatures
1516 //~| HELP replace with an appropriate return type
1617 //~| SUGGESTION impl FnMut(char)
18+ //~| NOTE for more information on `Fn` traits and closure types
1719 let x = String :: new ( ) ;
1820 |c| {
1921 x. push ( c) ;
@@ -25,6 +27,7 @@ fn fun() -> _ {
2527 //~| NOTE not allowed in type signatures
2628 //~| HELP replace with an appropriate return type
2729 //~| SUGGESTION impl Fn() -> i32
30+ //~| NOTE for more information on `Fn` traits and closure types
2831 || 1i32
2932}
3033
Original file line number Diff line number Diff line change @@ -6,24 +6,30 @@ LL | fn fn_once() -> _ {
66 | |
77 | not allowed in type signatures
88 | help: replace with an appropriate return type: `impl FnOnce()`
9+ |
10+ = note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
911
1012error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
11- --> $DIR/suggest-return-closure.rs:12 :16
13+ --> $DIR/suggest-return-closure.rs:13 :16
1214 |
1315LL | fn fn_mut() -> _ {
1416 | ^
1517 | |
1618 | not allowed in type signatures
1719 | help: replace with an appropriate return type: `impl FnMut(char)`
20+ |
21+ = note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
1822
1923error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
20- --> $DIR/suggest-return-closure.rs:23 :13
24+ --> $DIR/suggest-return-closure.rs:25 :13
2125 |
2226LL | fn fun() -> _ {
2327 | ^
2428 | |
2529 | not allowed in type signatures
2630 | help: replace with an appropriate return type: `impl Fn() -> i32`
31+ |
32+ = note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
2733
2834error: aborting due to 3 previous errors
2935
You can’t perform that action at this time.
0 commit comments