-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The original proposal allows reference patterns with "compatible" mutability, however it's not clear what that means so for now we require an exact match. I don't know the type system code well, so if something seems to not make sense it's probably because I made a mistake
- Loading branch information
1 parent
877d36b
commit f37a4d5
Showing
11 changed files
with
257 additions
and
29 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 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 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 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 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 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 |
---|---|---|
|
@@ -380,6 +380,7 @@ symbols! { | |
alu32, | ||
always, | ||
and, | ||
and_pat_everywhere, | ||
and_then, | ||
anon, | ||
anon_adt, | ||
|
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,12 @@ | ||
#![allow(incomplete_features)] | ||
#![feature(and_pat_everywhere)] | ||
pub fn main() { | ||
if let Some(&x) = Some(0) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
if let &Some(x) = &mut Some(0) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/ui/match/and_pat_everywhere-mutability-mismatch.stderr
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,29 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/and_pat_everywhere-mutability-mismatch.rs:4:17 | ||
| | ||
LL | if let Some(&x) = Some(0) { | ||
| ^^ ------- this expression has type `Option<{integer}>` | ||
| | | ||
| expected integer, found `&_` | ||
| | ||
= note: expected type `{integer}` | ||
found reference `&_` | ||
help: consider removing `&` from the pattern | ||
| | ||
LL | if let Some(x) = Some(0) { | ||
| ~ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/and_pat_everywhere-mutability-mismatch.rs:8:12 | ||
| | ||
LL | if let &Some(x) = &mut Some(0) { | ||
| ^^^^^^^^ ------------ this expression has type `&mut Option<{integer}>` | ||
| | | ||
| types differ in mutability | ||
| | ||
= note: expected mutable reference `&mut Option<{integer}>` | ||
found reference `&_` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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,15 @@ | ||
//@ run-pass | ||
#![allow(incomplete_features)] | ||
#![feature(and_pat_everywhere)] | ||
|
||
pub fn main() { | ||
if let Some(Some(&x)) = &Some(&Some(0)) { | ||
let _: u32 = x; | ||
} | ||
if let Some(&Some(x)) = &Some(Some(0)) { | ||
let _: u32 = x; | ||
} | ||
if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ||
let _: u32 = x; | ||
} | ||
} |
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,14 @@ | ||
pub fn main() { | ||
if let Some(Some(&x)) = &Some(&Some(0)) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
if let Some(&Some(x)) = &Some(Some(0)) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) { | ||
//~^ ERROR: mismatched types [E0308] | ||
let _: u32 = x; | ||
} | ||
} |
Oops, something went wrong.