]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0059.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0059.md
1 The built-in function traits are generic over a tuple of the function arguments.
2 If one uses angle-bracket notation (`Fn<(T,), Output=U>`) instead of parentheses
3 (`Fn(T) -> U`) to denote the function trait, the type parameter should be a
4 tuple. Otherwise function call notation cannot be used and the trait will not be
5 implemented by closures.
6
7 The most likely source of this error is using angle-bracket notation without
8 wrapping the function argument type into a tuple, for example:
9
10 ```compile_fail,E0059
11 #![feature(unboxed_closures)]
12
13 fn foo<F: Fn<i32>>(f: F) -> F::Output { f(3) }
14 ```
15
16 It can be fixed by adjusting the trait bound like this:
17
18 ```
19 #![feature(unboxed_closures)]
20
21 fn foo<F: Fn<(i32,)>>(f: F) -> F::Output { f(3) }
22 ```
23
24 Note that `(T,)` always denotes the type of a 1-tuple containing an element of
25 type `T`. The comma is necessary for syntactic disambiguation.