Uh oh!
There was an error while loading. Please reload this page.
Add feature gates for for and ? in consts - #87237
Conversation
This comment has been minimized.
This comment has been minimized.
oli-obk
commented
Jul 18, 2021
maybe #86857 helps here? |
jonas-schievink
commented
Jul 18, 2021
In theory, yeah, this works: #![feature(const_refs_to_cell)]#![feature(const_mut_refs)]#![feature(const_fn_trait_bound)]#![feature(const_trait_impl)]traitIter:Copy + Sized{typeItem:Copy;fnnext(&mutself) -> Option<Self::Item>;#[default_method_body_is_const]fncount(mutself) -> usize{letmut count = 0;whileself.next().is_some(){
count += 1;}
count
}}#[derive(Copy,Clone)]structConstIter{next:Option<u8>,}implconstIterforConstIter{typeItem = u8;fnnext(&mutself) -> Option<u8>{matchself.next{Some(val) => {self.next = val.checked_add(1);Some(val)}None => None,}}}const _:() = {let c = ConstIter{next:Some(0)}.count();if c != 256{[()][4];}};...but it requires a lot of feature gates and |
oli-obk
commented
Jul 18, 2021
Then I would say we don't add a const_for feature gate, we can start figuring out const iterators without it. |
jonas-schievink
commented
Jul 18, 2021
But we'll need one eventually, right? Why not add it now? |
oli-obk
commented
Jul 18, 2021
Yea. Just right now it doesn't really get us anything actionable. I guess as long as we have a canary test showing the behaviour of the feature gate it should be ok to have an unusable feature gate. Just thought it unusual. |
bors
commented
Jul 27, 2021
☔ The latest upstream changes (presumably #83484) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
commented
Jul 29, 2021
☔ The latest upstream changes (presumably #86998) made this pull request unmergeable. Please resolve the merge conflicts. |
usbalbin
commented
Jul 29, 2021
#86853 is a PR which might have some overlap with the try-operator part of this. My goal there was to try and constify the most trivial conversion impls to enable basic usage with |
usbalbin
commented
Jul 29, 2021
jonas-schievink
commented
Jul 29, 2021
Yes, these tracking issues are pretty hard to discover |
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
| --> $DIR/const-for.rs:5:14 | ||
| | | ||
| LL | for _ in 0..5 {} | ||
| | ^^^^ |
There was a problem hiding this comment.
I guess we should start printing the function's name in the diagnostic. Very uninformative this error XD
oli-obk
commented
Jul 30, 2021
@bors r+ |
bors
commented
Jul 30, 2021
📌 Commit c5a29f9 has been approved by |
bors
commented
Jul 30, 2021
bors
commented
Jul 30, 2021
☀️ Test successful - checks-actions |
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
These operations seems relatively straightforward to support, and only seem to be blocked on
impl const Trait.I have included a working test for
const_try, butconst_foris currently unusable without reimplementing every single defaultedIteratormethod, so I didn't do that.(both features still need tracking issues before this is merged)