You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0308]: mismatched types
--> src/main.rs:2:5
|
2 | / match maybe_bool {
3 | | Some(a_bool) => a_bool,
4 | | None => true
5 | | } && bool_slice[0]
| | ^- help: consider using a semicolon here
| |_____|
| expected `()`, found `bool`
error[E0308]: mismatched types
--> src/main.rs:5:7
|
1 | fn test_match_bool(bool_slice: &[bool], maybe_bool: Option<bool>) -> bool {
| ---- expected `bool` because of return type
...
5 | } && bool_slice[0]
| ^^^^^^^^^^^^^^^^ expected `bool`, found `&&bool`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.
It looks like the compiler fails to understand that the expression continues after the match expression, and then reads && bool_slice[0] as being a new expression of type &&bool.
Oddly enough, prepending a return keyword to the whole expression:
Hi Rust team! First of all, sorry if this has been already reported, but I couldn't find any issue related to this one.
Using a
match
expression as abool
and combining it with otherbool
s using boolean operators yields compiler errors which appear to be unexpected.Example code that reproduces the compiler errors:
This yields the following compiler errors:
It looks like the compiler fails to understand that the expression continues after the
match
expression, and then reads&& bool_slice[0]
as being a new expression of type&&bool
.Oddly enough, prepending a
return
keyword to the whole expression:causes the compiler to compile the code successfully.
This happens both on stable and nightly compilers.
The text was updated successfully, but these errors were encountered: