-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand the docs for ops::ControlFlow a bit
Since I was writing some examples for an RFC anyway.
- Loading branch information
Showing
4 changed files
with
104 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use core::intrinsics::discriminant_value; | ||
use core::ops::ControlFlow; | ||
|
||
#[test] | ||
fn control_flow_discriminants_match_result() { | ||
// This isn't stable surface area, but helps keep `?` cheap between them, | ||
// even if LLVM can't always take advantage of it right now. | ||
// (Sadly Result and Option are inconsistent, so ControlFlow can't match both.) | ||
|
||
assert_eq!( | ||
discriminant_value(&ControlFlow::<i32, i32>::Break(3)), | ||
discriminant_value(&Result::<i32, i32>::Err(3)), | ||
); | ||
assert_eq!( | ||
discriminant_value(&ControlFlow::<i32, i32>::Continue(3)), | ||
discriminant_value(&Result::<i32, i32>::Ok(3)), | ||
); | ||
} |