Skip to content

Commit efe438b

Browse files
committed
implement Deref for Bar
1 parent 5924ef8 commit efe438b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1+
use std::ops::Deref;
2+
13
struct Foo {
24
v: Vec<u32>,
35
}
46

7+
struct Bar {
8+
v: Vec<u32>,
9+
}
10+
11+
impl Deref for Bar {
12+
type Target = Vec<u32>;
13+
14+
fn deref(&self) -> &Self::Target {
15+
&self.v
16+
}
17+
}
18+
519
fn f(foo: &Foo) {
620
match foo {
721
Foo { v: [1, 2] } => {}
@@ -10,4 +24,12 @@ fn f(foo: &Foo) {
1024
}
1125
}
1226

27+
fn bar(bar: &Bar) {
28+
match bar {
29+
Bar { v: [1, 2] } => {}
30+
//~^ ERROR expected an array or slice, found `Vec<u32>
31+
_ => {}
32+
}
33+
}
34+
1335
fn main() {}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
error[E0529]: expected an array or slice, found `Vec<u32>`
2-
--> $DIR/pattern-struct-with-slice-vec-field.rs:7:18
2+
--> $DIR/pattern-struct-with-slice-vec-field.rs:21:18
33
|
44
LL | Foo { v: [1, 2] } => {}
55
| ^^^^^^ pattern cannot match with input type `Vec<u32>`
66

7-
error: aborting due to previous error
7+
error[E0529]: expected an array or slice, found `Vec<u32>`
8+
--> $DIR/pattern-struct-with-slice-vec-field.rs:29:18
9+
|
10+
LL | Bar { v: [1, 2] } => {}
11+
| ^^^^^^ pattern cannot match with input type `Vec<u32>`
12+
13+
error: aborting due to 2 previous errors
814

915
For more information about this error, try `rustc --explain E0529`.

0 commit comments

Comments
 (0)