Skip to content

Commit

Permalink
implement Deref for Bar
Browse files Browse the repository at this point in the history
  • Loading branch information
TaKO8Ki committed Apr 18, 2022
1 parent 5924ef8 commit efe438b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
use std::ops::Deref;

struct Foo {
v: Vec<u32>,
}

struct Bar {
v: Vec<u32>,
}

impl Deref for Bar {
type Target = Vec<u32>;

fn deref(&self) -> &Self::Target {
&self.v
}
}

fn f(foo: &Foo) {
match foo {
Foo { v: [1, 2] } => {}
Expand All @@ -10,4 +24,12 @@ fn f(foo: &Foo) {
}
}

fn bar(bar: &Bar) {
match bar {
Bar { v: [1, 2] } => {}
//~^ ERROR expected an array or slice, found `Vec<u32>
_ => {}
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
error[E0529]: expected an array or slice, found `Vec<u32>`
--> $DIR/pattern-struct-with-slice-vec-field.rs:7:18
--> $DIR/pattern-struct-with-slice-vec-field.rs:21:18
|
LL | Foo { v: [1, 2] } => {}
| ^^^^^^ pattern cannot match with input type `Vec<u32>`

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

error: aborting due to 2 previous errors

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

0 comments on commit efe438b

Please sign in to comment.