]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs/struct-fn-in-definition.rs
Rollup merge of #97317 - GuillaumeGomez:gui-settings-text-click, r=jsha
[rust.git] / src / test / ui / structs / struct-fn-in-definition.rs
1 // It might be intuitive for a user coming from languages like Java
2 // to declare a method directly in a struct's definition. Make sure
3 // rustc can give a helpful suggestion.
4 // Suggested in issue #76421
5
6 struct S {
7     field: usize,
8
9     fn foo() {}
10     //~^ ERROR functions are not allowed in struct definitions
11     //~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks
12     //~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
13 }
14
15 union U {
16     variant: usize,
17
18     fn foo() {}
19     //~^ ERROR functions are not allowed in union definitions
20     //~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks
21     //~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
22 }
23
24 enum E {
25     Variant,
26
27     fn foo() {}
28     //~^ ERROR functions are not allowed in enum definitions
29     //~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks
30     //~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
31 }
32
33 fn main() {}