Skip to content

Commit 1e642f0

Browse files
Add basic test
1 parent cecb3be commit 1e642f0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
fn do_something() {}
9+
//~^ ERROR functions are not allowed in struct definitions
10+
//~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks
11+
//~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: functions are not allowed in struct definitions
2+
--> $DIR/struct-fn-in-definition.rs:5:5
3+
|
4+
LL | fn do_something() {}
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: unlike in C++, Java, and C#, functions are declared in `impl` blocks
8+
= help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)