File tree 5 files changed +17
-5
lines changed
compiler/rustc_hir_analysis/src
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>(
1231
1231
Applicability :: MachineApplicable ,
1232
1232
) ;
1233
1233
} 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]`).
1237
1234
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 ( ) {
1238
1238
diag. note (
1239
1239
"for more information on `Fn` traits and closure types, see \
1240
1240
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() -> _ {
20
20
//~| NOTE not allowed in type signatures
21
21
//~| HELP replace with an appropriate return type
22
22
//~| SUGGESTION impl Fn() -> i32
23
+ //~| NOTE for more information on `Fn` traits and closure types
23
24
|| 0
24
25
}
25
26
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ LL | fn returns_closure() -> _ {
15
15
| |
16
16
| not allowed in type signatures
17
17
| 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
18
20
19
21
error: aborting due to 2 previous errors
20
22
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ fn fn_once() -> _ {
3
3
//~| NOTE not allowed in type signatures
4
4
//~| HELP replace with an appropriate return type
5
5
//~| SUGGESTION impl FnOnce()
6
+ //~| NOTE for more information on `Fn` traits and closure types
6
7
let x = String :: new ( ) ;
7
8
|| {
8
9
drop ( x) ;
@@ -14,6 +15,7 @@ fn fn_mut() -> _ {
14
15
//~| NOTE not allowed in type signatures
15
16
//~| HELP replace with an appropriate return type
16
17
//~| SUGGESTION impl FnMut(char)
18
+ //~| NOTE for more information on `Fn` traits and closure types
17
19
let x = String :: new ( ) ;
18
20
|c| {
19
21
x. push ( c) ;
@@ -25,6 +27,7 @@ fn fun() -> _ {
25
27
//~| NOTE not allowed in type signatures
26
28
//~| HELP replace with an appropriate return type
27
29
//~| SUGGESTION impl Fn() -> i32
30
+ //~| NOTE for more information on `Fn` traits and closure types
28
31
|| 1i32
29
32
}
30
33
Original file line number Diff line number Diff line change @@ -6,24 +6,30 @@ LL | fn fn_once() -> _ {
6
6
| |
7
7
| not allowed in type signatures
8
8
| 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
9
11
10
12
error[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
12
14
|
13
15
LL | fn fn_mut() -> _ {
14
16
| ^
15
17
| |
16
18
| not allowed in type signatures
17
19
| 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
18
22
19
23
error[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
21
25
|
22
26
LL | fn fun() -> _ {
23
27
| ^
24
28
| |
25
29
| not allowed in type signatures
26
30
| 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
27
33
28
34
error: aborting due to 3 previous errors
29
35
You can’t perform that action at this time.
0 commit comments