Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

or-patterns: Uniformly use PatKind::Or in AST & Fix/Cleanup resolve #64111

Merged
merged 27 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
af06bfb
resolve: extract `resolve_params`.
Centril Aug 28, 2019
f8835ee
resolve: cleanup using `with_rib`, etc.
Centril Aug 28, 2019
6d537d4
resolve: simplify `resolve_arm`.
Centril Aug 28, 2019
219ddde
resolve: extract `try_resolve_as_non_binding`.
Centril Aug 28, 2019
f343e84
resolve: add `type IdentMap<T>` alias.
Centril Aug 28, 2019
fd3b441
resolve: move `fresh_binding`.
Centril Aug 28, 2019
dc91e22
resolve: move `resolve_block` to a better place.
Centril Aug 28, 2019
70cae78
resolve: already-bound-check: account for or-patterns.
Centril Aug 28, 2019
166a558
resolve: revamp already-bound check -- fix some bugs.
Centril Sep 1, 2019
498ec59
resolve: add tests for already-bound check.
Centril Sep 1, 2019
896a1c7
resolve: account for general or-patterns in consistency checking.
Centril Sep 1, 2019
33317c7
resolve: add test for missing bindings in or-patterns.
Centril Sep 1, 2019
aa7a02b
resolve: test binding mode consistency for or-patterns.
Centril Sep 1, 2019
dbe6873
resolve: test consistent or-patterns being allowed.
Centril Sep 3, 2019
ca968a1
or-patterns: syntax: simplify `Arm.pats` and `ExprKind::Let.0`.
Centril Aug 27, 2019
998060b
or-patterns: syntax: adjust `visit` and `mut_visit`.
Centril Aug 27, 2019
ad3db72
or-patterns: syntax: adjust parser removing a hack.
Centril Aug 27, 2019
424492a
or-patterns: syntax: adjust pretty printing.
Centril Aug 27, 2019
76625eb
or-patterns: syntax: adjust derive, format, and building.
Centril Aug 27, 2019
3fccbac
or-patterns: adjust librustc_lint.
Centril Aug 27, 2019
d8ef907
or-patterns: adjust lowering of `ast::Arm` & `ast::ExprKind::Let`.
Centril Aug 28, 2019
a867c5f
resolve: merge `resolve_pats` and `resolve_pattern_top`.
Centril Sep 1, 2019
be95dee
or-patterns: adjust save_analysis wrt. `process_var_decl{_multi}`.
Centril Sep 2, 2019
d70b0c5
or-patterns: fix pprust-expr-roundtrip due to AST change.
Centril Sep 3, 2019
a7db1a4
or-patterns: address review comments.
Centril Sep 4, 2019
0341b78
resolve: bool -> enum PatBoundCtx
Centril Sep 4, 2019
16ba502
or-patterns: fix fallout from #664128.
Centril Sep 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
resolve: test binding mode consistency for or-patterns.
  • Loading branch information
Centril committed Sep 5, 2019
commit aa7a02b02966d464bb06560c581f92355825fc56
26 changes: 26 additions & 0 deletions src/test/ui/or-patterns/inconsistent-modes.rs
Original file line number Diff line number Diff line change
@@ -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
}
72 changes: 72 additions & 0 deletions src/test/ui/or-patterns/inconsistent-modes.stderr
Original file line number Diff line number Diff line change
@@ -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`.