Restore Fn trait note
This commit is contained in:
parent
a0390463fc
commit
89086f7d36
5 changed files with 17 additions and 5 deletions
|
@ -1231,10 +1231,10 @@ fn infer_return_ty_for_fn_sig<'tcx>(
|
|||
Applicability::MachineApplicable,
|
||||
);
|
||||
} else if ret_ty.is_closure() {
|
||||
// We're dealing with a closure, so we should suggest using `impl Fn` or trait bounds
|
||||
// to prevent the user from getting a papercut while trying to use the unique closure
|
||||
// syntax (e.g. `[closure@src/lib.rs:2:5: 2:9]`).
|
||||
diag.help("consider using an `Fn`, `FnMut`, or `FnOnce` trait bound");
|
||||
}
|
||||
// Also note how `Fn` traits work just in case!
|
||||
if ret_ty.is_closure() {
|
||||
diag.note(
|
||||
"for more information on `Fn` traits and closure types, see \
|
||||
https://doc.rust-lang.org/book/ch13-01-closures.html",
|
||||
|
|
|
@ -20,6 +20,7 @@ fn returns_closure() -> _ {
|
|||
//~| NOTE not allowed in type signatures
|
||||
//~| HELP replace with an appropriate return type
|
||||
//~| SUGGESTION impl Fn() -> i32
|
||||
//~| NOTE for more information on `Fn` traits and closure types
|
||||
|| 0
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ LL | fn returns_closure() -> _ {
|
|||
| |
|
||||
| not allowed in type signatures
|
||||
| help: replace with an appropriate return type: `impl Fn() -> i32`
|
||||
|
|
||||
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ fn fn_once() -> _ {
|
|||
//~| NOTE not allowed in type signatures
|
||||
//~| HELP replace with an appropriate return type
|
||||
//~| SUGGESTION impl FnOnce()
|
||||
//~| NOTE for more information on `Fn` traits and closure types
|
||||
let x = String::new();
|
||||
|| {
|
||||
drop(x);
|
||||
|
@ -14,6 +15,7 @@ fn fn_mut() -> _ {
|
|||
//~| NOTE not allowed in type signatures
|
||||
//~| HELP replace with an appropriate return type
|
||||
//~| SUGGESTION impl FnMut(char)
|
||||
//~| NOTE for more information on `Fn` traits and closure types
|
||||
let x = String::new();
|
||||
|c| {
|
||||
x.push(c);
|
||||
|
@ -25,6 +27,7 @@ fn fun() -> _ {
|
|||
//~| NOTE not allowed in type signatures
|
||||
//~| HELP replace with an appropriate return type
|
||||
//~| SUGGESTION impl Fn() -> i32
|
||||
//~| NOTE for more information on `Fn` traits and closure types
|
||||
|| 1i32
|
||||
}
|
||||
|
||||
|
|
|
@ -6,24 +6,30 @@ LL | fn fn_once() -> _ {
|
|||
| |
|
||||
| not allowed in type signatures
|
||||
| help: replace with an appropriate return type: `impl FnOnce()`
|
||||
|
|
||||
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
|
||||
|
||||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
|
||||
--> $DIR/suggest-return-closure.rs:12:16
|
||||
--> $DIR/suggest-return-closure.rs:13:16
|
||||
|
|
||||
LL | fn fn_mut() -> _ {
|
||||
| ^
|
||||
| |
|
||||
| not allowed in type signatures
|
||||
| help: replace with an appropriate return type: `impl FnMut(char)`
|
||||
|
|
||||
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
|
||||
|
||||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
|
||||
--> $DIR/suggest-return-closure.rs:23:13
|
||||
--> $DIR/suggest-return-closure.rs:25:13
|
||||
|
|
||||
LL | fn fun() -> _ {
|
||||
| ^
|
||||
| |
|
||||
| not allowed in type signatures
|
||||
| help: replace with an appropriate return type: `impl Fn() -> i32`
|
||||
|
|
||||
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue