File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
compiler/rustc_error_codes/src/error_codes Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 1- Trait methods currently cannot take patterns as arguments.
1+ Trait methods cannot take patterns as arguments.
2+
3+ Traits cannot control the way in which implementations take arguments, only the
4+ types of those arguments. A pattern here has no effect, because the
5+ implementation can bind its arguments however it would like.
26
37Erroneous code example:
48
5- ``` compile_fail,E0642
9+ ``` compile_fail,E0642,edition2024
610trait Foo {
711 fn foo((x, y): (i32, i32)); // error: patterns aren't allowed
812 // in trait methods
@@ -16,3 +20,9 @@ trait Foo {
1620 fn foo(x_and_y: (i32, i32)); // ok!
1721}
1822```
23+
24+ And you can use patterns in its implementations:
25+
26+ impl Foo for Bar {
27+ fn foo((x, y): (i32, i32)) { /* ... * / } // ok!
28+ }
You can’t perform that action at this time.
0 commit comments