rust/tests/ui/structs/struct-fn-in-definition.rs

35 lines
1.2 KiB
Rust
Raw Normal View History

2020-09-17 11:44:09 -05:00
// It might be intuitive for a user coming from languages like Java
// to declare a method directly in a struct's definition. Make sure
// rustc can give a helpful suggestion.
// Suggested in issue #76421
struct S {
field: usize,
fn foo() {}
2020-09-17 11:44:09 -05:00
//~^ ERROR functions are not allowed in struct definitions
//~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks
//~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
}
union U {
variant: usize,
fn foo() {}
//~^ ERROR functions are not allowed in union definitions
//~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks
//~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
}
enum E {
Variant,
fn foo() {}
//~^ ERROR functions are not allowed in enum definitions
//~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks
//~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
//~| HELP enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
}
2020-09-17 11:44:09 -05:00
fn main() {}