diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-09-01 23:24:07 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-09-05 08:33:09 +0200 |
| commit | aa7a02b02966d464bb06560c581f92355825fc56 (patch) | |
| tree | 34b6de3dfc800fe9f5e2c63ae5832f81aa969958 | |
| parent | 33317c7baad5000ff34449f5c8a55b48e6296453 (diff) | |
| download | rust-aa7a02b02966d464bb06560c581f92355825fc56.tar.gz rust-aa7a02b02966d464bb06560c581f92355825fc56.zip | |
resolve: test binding mode consistency for or-patterns.
| -rw-r--r-- | src/test/ui/or-patterns/inconsistent-modes.rs | 26 | ||||
| -rw-r--r-- | src/test/ui/or-patterns/inconsistent-modes.stderr | 72 |
2 files changed, 98 insertions, 0 deletions
diff --git a/src/test/ui/or-patterns/inconsistent-modes.rs b/src/test/ui/or-patterns/inconsistent-modes.rs new file mode 100644 index 00000000000..a13596a9c8b --- /dev/null +++ b/src/test/ui/or-patterns/inconsistent-modes.rs @@ -0,0 +1,26 @@ +// This test ensures that or patterns require binding mode consistency across arms. + +#![feature(or_patterns)] +#![allow(incomplete_features, non_camel_case_types)] +fn main() { + // One level: + let Ok(a) | Err(ref a): Result<&u8, u8> = Ok(&0); + //~^ ERROR variable `a` is bound in inconsistent ways + let Ok(ref mut a) | Err(a): Result<u8, &mut u8> = Ok(0); + //~^ ERROR variable `a` is bound in inconsistent ways + let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0); + //~^ ERROR variable `a` is bound in inconsistent ways + //~| ERROR mismatched types + let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0)); + //~^ ERROR variable `a` is bound in inconsistent ways + //~| ERROR variable `b` is bound in inconsistent ways + //~| ERROR mismatched types + + // Two levels: + let Ok(Ok(a) | Err(a)) | Err(ref a) = Err(0); + //~^ ERROR variable `a` is bound in inconsistent ways + + // Three levels: + let Ok([ Ok((Ok(ref a) | Err(a),)) | Err(a) ]) | Err(a) = Err(&1); + //~^ ERROR variable `a` is bound in inconsistent ways +} diff --git a/src/test/ui/or-patterns/inconsistent-modes.stderr b/src/test/ui/or-patterns/inconsistent-modes.stderr new file mode 100644 index 00000000000..a34a4fe1387 --- /dev/null +++ b/src/test/ui/or-patterns/inconsistent-modes.stderr @@ -0,0 +1,72 @@ +error[E0409]: variable `a` is bound in inconsistent ways within the same match arm + --> $DIR/inconsistent-modes.rs:7:25 + | +LL | let Ok(a) | Err(ref a): Result<&u8, u8> = Ok(&0); + | - ^ bound in different ways + | | + | first binding + +error[E0409]: variable `a` is bound in inconsistent ways within the same match arm + --> $DIR/inconsistent-modes.rs:9:29 + | +LL | let Ok(ref mut a) | Err(a): Result<u8, &mut u8> = Ok(0); + | - ^ bound in different ways + | | + | first binding + +error[E0409]: variable `a` is bound in inconsistent ways within the same match arm + --> $DIR/inconsistent-modes.rs:11:33 + | +LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0); + | - first binding ^ bound in different ways + +error[E0409]: variable `a` is bound in inconsistent ways within the same match arm + --> $DIR/inconsistent-modes.rs:14:39 + | +LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0)); + | - first binding ^ bound in different ways + +error[E0409]: variable `b` is bound in inconsistent ways within the same match arm + --> $DIR/inconsistent-modes.rs:14:46 + | +LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0)); + | - first binding ^ bound in different ways + +error[E0409]: variable `a` is bound in inconsistent ways within the same match arm + --> $DIR/inconsistent-modes.rs:20:38 + | +LL | let Ok(Ok(a) | Err(a)) | Err(ref a) = Err(0); + | - ^ bound in different ways + | | + | first binding + +error[E0409]: variable `a` is bound in inconsistent ways within the same match arm + --> $DIR/inconsistent-modes.rs:24:34 + | +LL | let Ok([ Ok((Ok(ref a) | Err(a),)) | Err(a) ]) | Err(a) = Err(&1); + | - ^ bound in different ways + | | + | first binding + +error[E0308]: mismatched types + --> $DIR/inconsistent-modes.rs:11:25 + | +LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0); + | ^^^^^^^^^ types differ in mutability + | + = note: expected type `&&u8` + found type `&mut &mut u8` + +error[E0308]: mismatched types + --> $DIR/inconsistent-modes.rs:14:31 + | +LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0)); + | ^^^^^^^^^ types differ in mutability + | + = note: expected type `&{integer}` + found type `&mut _` + +error: aborting due to 9 previous errors + +Some errors have detailed explanations: E0308, E0409. +For more information about an error, try `rustc --explain E0308`. |
