forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#68856 - Centril:or-pat-ref-pat, r=matthewja…
…sper typeck: clarify def_bm adjustments & add tests for or-patterns Clarify the adjustment algorithm for the expected type / default binding-modes when type checking patterns with more documentation and tweaks that make the algorithm more independent of the pattern forms. Also resolve the FIXME noted for or-patterns by deciding that the current implementation is correct, noting the rationale and adding tests for the current implementation. cc rust-lang#54883 r? @oli-obk @varkor
- Loading branch information
Showing
6 changed files
with
447 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
src/test/ui/or-patterns/or-patterns-binding-type-mismatch.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Here we test type checking of bindings when combined with or-patterns. | ||
// Specifically, we ensure that introducing bindings of different types result in type errors. | ||
|
||
#![feature(or_patterns)] | ||
|
||
fn main() { | ||
enum Blah { | ||
A(isize, isize, usize), | ||
B(isize, isize), | ||
} | ||
|
||
match Blah::A(1, 1, 2) { | ||
Blah::A(_, x, y) | Blah::B(x, y) => {} //~ ERROR mismatched types | ||
} | ||
|
||
match Some(Blah::A(1, 1, 2)) { | ||
Some(Blah::A(_, x, y) | Blah::B(x, y)) => {} //~ ERROR mismatched types | ||
} | ||
|
||
match (0u8, 1u16) { | ||
(x, y) | (y, x) => {} //~ ERROR mismatched types | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
match Some((0u8, Some((1u16, 2u32)))) { | ||
Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {} | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
//~| ERROR mismatched types | ||
//~| ERROR mismatched types | ||
_ => {} | ||
} | ||
|
||
if let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2) { | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
if let Some(Blah::A(_, x, y) | Blah::B(x, y)) = Some(Blah::A(1, 1, 2)) { | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
if let (x, y) | (y, x) = (0u8, 1u16) { | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
} | ||
|
||
if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
//~| ERROR mismatched types | ||
//~| ERROR mismatched types | ||
= Some((0u8, Some((1u16, 2u32)))) | ||
{} | ||
|
||
let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2); | ||
//~^ ERROR mismatched types | ||
|
||
let (x, y) | (y, x) = (0u8, 1u16); | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
|
||
fn f1((Blah::A(_, x, y) | Blah::B(x, y)): Blah) {} | ||
//~^ ERROR mismatched types | ||
|
||
fn f2(((x, y) | (y, x)): (u8, u16)) {} | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
} |
Oops, something went wrong.