rust/src/test/ui/structs/struct-fn-in-definition.rs

15 lines
519 B
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 do_something() {}
//~^ 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
}
fn main() {}