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.
Auto merge of rust-lang#86853 - usbalbin:const_try, r=oli-obk
Constify ?-operator for Result and Option Try to make `?`-operator usable in `const fn` with `Result` and `Option`, see rust-lang#74935 . Note that the try-operator itself was constified in rust-lang#87237. TODO * [x] Add tests for const T -> T conversions * [x] cleanup commits * [x] Remove `#![allow(incomplete_features)]` * [?] Await decision in rust-lang#86808 - I'm not sure * [x] Await support for parsing `~const` in bootstrapping compiler * [x] Tracking issue(s)? - rust-lang#88674
- Loading branch information
Showing
7 changed files
with
58 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#[test] | ||
fn convert() { | ||
const fn from(x: i32) -> i32 { | ||
i32::from(x) | ||
} | ||
|
||
const FOO: i32 = from(42); | ||
assert_eq!(FOO, 42); | ||
|
||
const fn into(x: Vec<String>) -> Vec<String> { | ||
x.into() | ||
} | ||
|
||
const BAR: Vec<String> = into(Vec::new()); | ||
assert_eq!(BAR, Vec::<String>::new()); | ||
} |
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,23 @@ | ||
// run-pass | ||
|
||
#![feature(try_trait_v2)] | ||
#![feature(const_trait_impl)] | ||
#![feature(const_try)] | ||
#![feature(const_convert)] | ||
|
||
fn main() { | ||
const fn result() -> Result<bool, ()> { | ||
Err(())?; | ||
Ok(true) | ||
} | ||
|
||
const FOO: Result<bool, ()> = result(); | ||
assert_eq!(Err(()), FOO); | ||
|
||
const fn option() -> Option<()> { | ||
None?; | ||
Some(()) | ||
} | ||
const BAR: Option<()> = option(); | ||
assert_eq!(None, BAR); | ||
} |