The functions below in the standard library are const fn with individual feature gates for calling them in constant expressions. This issue is tracking the stabilization of such calls.
CC https://github.com/rust-lang/rust/issues/24111, the super-set feature which also includes defining new const fn items.
std::sync::Once::newcore::cell::Cell::newcore::cell::RefCell::newcore::cell::UnsafeCell::newcore::sync::AtomicBool::newcore::sync::AtomicPtr::newcore::sync::Atomic$IntegerType::newcore::mem::size_ofcore::mem::align_ofcore::ptr::nullcore::ptr::null_mut<$IntegerType>::max_value<$IntegerType>::min_valueItems in core:: are also re-exported in std::.
Feature gates are:
const_once_newconst_cell_newconst_refcell_newconst_unsafe_cell_newconst_size_ofconst_align_ofconst_ptr_nullconst_ptr_null_mutconst_min_valueconst_max_valueconst_atomic_bool_newconst_atomic_ptr_newconst_atomic_i8_newconst_atomic_u8_newconst_atomic_i16_newconst_atomic_u16_newconst_atomic_i32_newconst_atomic_u32_newconst_atomic_i64_newconst_atomic_u64_newconst_atomic_isize_newconst_atomic_usize_newKicking off stabilization discussion for the const-ness of these functions in std.
@rfcbot fcp merge
Team member @aturon has proposed to merge this. The next step is review by the rest of the tagged teams:
No concerns currently listed.
Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
:bell: This is now entering its final comment period, as per the review above. :bell:
How to about mark std::time::Duration::{from_millis, new, from_secs, from_micros} as const_fn?
new can panic so it can't be const.
@sfackler sure it can, the same way an indexing expression can be const (panic turns into const evaluation error).
@durka How?
#![feature(const_fn)]
const fn foo(a: i32) {
if a > 10 {
panic!();
}
}
fn main() {}
error[E0019]: constant function contains unimplemented expression type
--> src/main.rs:4:5
|
4 | / if a > 10 {
5 | | panic!();
6 | | }
| |_____^
error: aborting due to previous error
#![feature(const_fn)]
const fn foo(a: i32) {
panic!();
}
fn main() {}
error[E0015]: calls in constant functions are limited to constant functions, struct and enum constructors
--> src/main.rs:4:5
|
4 | panic!();
| ^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate
error: aborting due to previous error
I think this is "what is allowed right now" vs "what we could allow" (i.e. miri evaluates panics just fine).
Yeah sorry, I just meant that in theory we could translate panics to
compile errors.
On Nov 17, 2017 7:37 PM, "Eduard-Mihai Burtescu" notifications@github.com
wrote:
I think this is "what is allowed right now" vs "what we could allow" (i.e.
miri evaluates panics just fine).—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/rust-lang/rust/issues/46038#issuecomment-345402469,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAC3n43M19qfGrHiLnHUOfS_2uTSttq9ks5s3ibbgaJpZM4QgrK5
.
There are many more fns that could be made const once miri lands, and we should definitely consider them then. This issue is specifically about those that are already const, and stabilizing calls to them Very Soon®.
The final comment period is now complete.
I’ve submitted https://github.com/rust-lang/rust/pull/46287
Most helpful comment
There are many more
fns that could be madeconstonce miri lands, and we should definitely consider them then. This issue is specifically about those that are alreadyconst, and stabilizing calls to them Very Soon®.