diff options
| author | Jorge Aparicio <jorge.aparicio@ferrous-systems.com> | 2020-01-20 07:50:32 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-20 07:50:32 +0000 |
| commit | a3a077610028c773bffc7a74e6a15faa10d2360d (patch) | |
| tree | 819cf353c019f421d80d9545aa18583841c34348 /src/test/ui/array-slice-vec | |
| parent | 470cdf54ac9acee20ab8da46ef7899bae9f58f29 (diff) | |
| parent | 29b854fb741809c29764e33fc17c32ba9c6523ba (diff) | |
| download | rust-a3a077610028c773bffc7a74e6a15faa10d2360d.tar.gz rust-a3a077610028c773bffc7a74e6a15faa10d2360d.zip | |
Merge branch 'master' into bare-metal-cortex-a
Diffstat (limited to 'src/test/ui/array-slice-vec')
12 files changed, 109 insertions, 15 deletions
diff --git a/src/test/ui/array-slice-vec/slice-pat-type-mismatches.rs b/src/test/ui/array-slice-vec/slice-pat-type-mismatches.rs new file mode 100644 index 00000000000..34adb42a32f --- /dev/null +++ b/src/test/ui/array-slice-vec/slice-pat-type-mismatches.rs @@ -0,0 +1,36 @@ +fn main() { + match "foo".to_string() { + ['f', 'o', ..] => {} + //~^ ERROR expected an array or slice, found `std::string::String` + _ => { } + }; + + // Note that this one works with default binding modes. + match &[0, 1, 2] { + [..] => {} + }; + + match &[0, 1, 2] { + &[..] => {} // ok + }; + + match [0, 1, 2] { + [0] => {}, //~ ERROR pattern requires + + [0, 1, x @ ..] => { + let a: [_; 1] = x; + } + [0, 1, 2, 3, x @ ..] => {} //~ ERROR pattern requires + }; + + match does_not_exist { //~ ERROR cannot find value `does_not_exist` in this scope + [] => {} + }; +} + +fn another_fn_to_avoid_suppression() { + match Default::default() + { + [] => {} //~ ERROR type annotations needed + }; +} diff --git a/src/test/ui/array-slice-vec/slice-pat-type-mismatches.stderr b/src/test/ui/array-slice-vec/slice-pat-type-mismatches.stderr new file mode 100644 index 00000000000..c4548142c13 --- /dev/null +++ b/src/test/ui/array-slice-vec/slice-pat-type-mismatches.stderr @@ -0,0 +1,36 @@ +error[E0425]: cannot find value `does_not_exist` in this scope + --> $DIR/slice-pat-type-mismatches.rs:26:11 + | +LL | match does_not_exist { + | ^^^^^^^^^^^^^^ not found in this scope + +error[E0529]: expected an array or slice, found `std::string::String` + --> $DIR/slice-pat-type-mismatches.rs:3:9 + | +LL | ['f', 'o', ..] => {} + | ^^^^^^^^^^^^^^ pattern cannot match with input type `std::string::String` + +error[E0527]: pattern requires 1 element but array has 3 + --> $DIR/slice-pat-type-mismatches.rs:18:9 + | +LL | [0] => {}, + | ^^^ expected 3 elements + +error[E0528]: pattern requires at least 4 elements but array has 3 + --> $DIR/slice-pat-type-mismatches.rs:23:9 + | +LL | [0, 1, 2, 3, x @ ..] => {} + | ^^^^^^^^^^^^^^^^^^^^ pattern cannot match array of 3 elements + +error[E0282]: type annotations needed + --> $DIR/slice-pat-type-mismatches.rs:34:9 + | +LL | [] => {} + | ^^ cannot infer type + | + = note: type must be known at this point + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0282, E0425, E0527, E0528, E0529. +For more information about an error, try `rustc --explain E0282`. diff --git a/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.rs b/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.rs new file mode 100644 index 00000000000..97e33624bf6 --- /dev/null +++ b/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.rs @@ -0,0 +1,11 @@ +fn main() { + let a: &[u8] = &[]; + match a { + [1, tail @ .., tail @ ..] => {}, + //~^ ERROR identifier `tail` is bound more than once in the same pattern + //~| ERROR `..` can only be used once per slice pattern + _ => () + } +} + +const RECOVERY_WITNESS: () = 0; //~ ERROR mismatched types diff --git a/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr b/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr new file mode 100644 index 00000000000..4d6078788b2 --- /dev/null +++ b/src/test/ui/array-slice-vec/subslice-only-once-semantic-restriction.stderr @@ -0,0 +1,24 @@ +error[E0416]: identifier `tail` is bound more than once in the same pattern + --> $DIR/subslice-only-once-semantic-restriction.rs:4:24 + | +LL | [1, tail @ .., tail @ ..] => {}, + | ^^^^ used in a pattern more than once + +error: `..` can only be used once per slice pattern + --> $DIR/subslice-only-once-semantic-restriction.rs:4:31 + | +LL | [1, tail @ .., tail @ ..] => {}, + | -- ^^ can only be used once per slice pattern + | | + | previously used here + +error[E0308]: mismatched types + --> $DIR/subslice-only-once-semantic-restriction.rs:11:30 + | +LL | const RECOVERY_WITNESS: () = 0; + | ^ expected `()`, found integer + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0416. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/array-slice-vec/subslice-patterns-const-eval-match.rs b/src/test/ui/array-slice-vec/subslice-patterns-const-eval-match.rs index 0e767d9613a..69c33921868 100644 --- a/src/test/ui/array-slice-vec/subslice-patterns-const-eval-match.rs +++ b/src/test/ui/array-slice-vec/subslice-patterns-const-eval-match.rs @@ -2,7 +2,7 @@ // run-pass -#![feature(slice_patterns, const_fn, const_if_match)] +#![feature(const_fn, const_if_match)] #[derive(PartialEq, Debug, Clone)] struct N(u8); diff --git a/src/test/ui/array-slice-vec/subslice-patterns-const-eval.rs b/src/test/ui/array-slice-vec/subslice-patterns-const-eval.rs index 5444f8a9051..0b793fa0120 100644 --- a/src/test/ui/array-slice-vec/subslice-patterns-const-eval.rs +++ b/src/test/ui/array-slice-vec/subslice-patterns-const-eval.rs @@ -2,8 +2,6 @@ // run-pass -#![feature(slice_patterns)] - #[derive(PartialEq, Debug, Clone)] struct N(u8); diff --git a/src/test/ui/array-slice-vec/subslice-patterns-pass.rs b/src/test/ui/array-slice-vec/subslice-patterns-pass.rs index 1ebf3def788..e05790911f5 100644 --- a/src/test/ui/array-slice-vec/subslice-patterns-pass.rs +++ b/src/test/ui/array-slice-vec/subslice-patterns-pass.rs @@ -4,8 +4,6 @@ // run-pass -#![feature(slice_patterns)] - #![allow(unreachable_patterns)] use std::convert::identity; diff --git a/src/test/ui/array-slice-vec/vec-matching-fixed.rs b/src/test/ui/array-slice-vec/vec-matching-fixed.rs index 5253bc1b214..fdeb7e4fda6 100644 --- a/src/test/ui/array-slice-vec/vec-matching-fixed.rs +++ b/src/test/ui/array-slice-vec/vec-matching-fixed.rs @@ -1,7 +1,5 @@ // run-pass -#![feature(slice_patterns)] - fn a() { let x = [1, 2, 3]; match x { diff --git a/src/test/ui/array-slice-vec/vec-matching-fold.rs b/src/test/ui/array-slice-vec/vec-matching-fold.rs index f416160db24..998899271e4 100644 --- a/src/test/ui/array-slice-vec/vec-matching-fold.rs +++ b/src/test/ui/array-slice-vec/vec-matching-fold.rs @@ -1,7 +1,5 @@ // run-pass -#![feature(slice_patterns)] - use std::fmt::Debug; fn foldl<T, U, F>(values: &[T], diff --git a/src/test/ui/array-slice-vec/vec-matching-legal-tail-element-borrow.rs b/src/test/ui/array-slice-vec/vec-matching-legal-tail-element-borrow.rs index f0602c328b0..ed34f074a92 100644 --- a/src/test/ui/array-slice-vec/vec-matching-legal-tail-element-borrow.rs +++ b/src/test/ui/array-slice-vec/vec-matching-legal-tail-element-borrow.rs @@ -1,7 +1,6 @@ // run-pass -#![allow(unused_variables)] -#![feature(slice_patterns)] +#![allow(unused_variables)] pub fn main() { let x = &[1, 2, 3, 4, 5]; diff --git a/src/test/ui/array-slice-vec/vec-matching.rs b/src/test/ui/array-slice-vec/vec-matching.rs index 49c736bd728..7009244aa18 100644 --- a/src/test/ui/array-slice-vec/vec-matching.rs +++ b/src/test/ui/array-slice-vec/vec-matching.rs @@ -1,7 +1,5 @@ // run-pass -#![feature(slice_patterns)] - fn a() { let x = [1]; match x { diff --git a/src/test/ui/array-slice-vec/vec-tail-matching.rs b/src/test/ui/array-slice-vec/vec-tail-matching.rs index 3c7b160dcc5..5f1699227d8 100644 --- a/src/test/ui/array-slice-vec/vec-tail-matching.rs +++ b/src/test/ui/array-slice-vec/vec-tail-matching.rs @@ -1,7 +1,5 @@ // run-pass -#![feature(slice_patterns)] - struct Foo { string: &'static str } |
