diff options
| author | Takayuki Maeda <41065217+TaKO8Ki@users.noreply.github.com> | 2022-04-18 13:08:23 +0900 |
|---|---|---|
| committer | Takayuki Maeda <41065217+TaKO8Ki@users.noreply.github.com> | 2022-04-18 13:08:23 +0900 |
| commit | efe438b47441203c8e881e87f2f2e29db76d3ff7 (patch) | |
| tree | 0df604e06c2df9e67faf74beeb1289f9487d31f1 /src/test | |
| parent | 5924ef874ebee33894cd34be07f88ed762f32385 (diff) | |
| download | rust-efe438b47441203c8e881e87f2f2e29db76d3ff7.tar.gz rust-efe438b47441203c8e881e87f2f2e29db76d3ff7.zip | |
implement `Deref` for `Bar`
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs | 22 | ||||
| -rw-r--r-- | src/test/ui/suggestions/pattern-struct-with-slice-vec-field.stderr | 10 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs b/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs index 1a9fc2f0050..5b223a91f50 100644 --- a/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs +++ b/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.rs @@ -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] } => {} @@ -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() {} diff --git a/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.stderr b/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.stderr index cb408d38fd2..5b48a8b18a5 100644 --- a/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.stderr +++ b/src/test/ui/suggestions/pattern-struct-with-slice-vec-field.stderr @@ -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`. |
