]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0183.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0183.md
1 Manual implementation of a `Fn*` trait.
2
3 Erroneous code example:
4
5 ```compile_fail,E0183
6 struct MyClosure {
7     foo: i32
8 }
9
10 impl FnOnce<()> for MyClosure {  // error
11     type Output = ();
12     extern "rust-call" fn call_once(self, args: ()) -> Self::Output {
13         println!("{}", self.foo);
14     }
15 }
16 ```
17
18 Manually implementing `Fn`, `FnMut` or `FnOnce` is unstable
19 and requires `#![feature(fn_traits, unboxed_closures)]`.
20
21 ```
22 #![feature(fn_traits, unboxed_closures)]
23
24 struct MyClosure {
25     foo: i32
26 }
27
28 impl FnOnce<()> for MyClosure {  // ok!
29     type Output = ();
30     extern "rust-call" fn call_once(self, args: ()) -> Self::Output {
31         println!("{}", self.foo);
32     }
33 }
34 ```
35
36 The arguments must be a tuple representing the argument list.
37 For more info, see the [tracking issue][iss29625]:
38
39 [iss29625]: https://github.com/rust-lang/rust/issues/29625