Auto merge of #43017 - durka:stabilize-const-invocation, r=eddyb

Individualize feature gates for const fn invocation

This PR changes the meaning of `#![feature(const_fn)]` so it is only required to declare a const fn but not to call one. Based on discussion at #24111. I was hoping we could have an FCP here in order to move that conversation forward.

This sets the stage for future stabilization of the constness of several functions in the standard library (listed below), so could someone please tag the lang team for review.

- `std::cell`
    - `Cell::new`
    - `RefCell::new`
    - `UnsafeCell::new`
- `std::mem`
    - `size_of`
    - `align_of`
- `std::ptr`
    - `null`
    - `null_mut`
- `std::sync`
    - `atomic`
        - `Atomic{Bool,Ptr,Isize,Usize}::new`
    - `once`
        - `Once::new`
- primitives
    - `{integer}::min_value`
    - `{integer}::max_value`

Some other functions are const but they are also unstable or hidden, e.g. `Unique::new` so they don't have to be considered at this time.

After this stabilization, the following `*_INIT` constants in the standard library can be deprecated. I wasn't sure whether to include those deprecations in the current PR.

- `std::sync`
    - `atomic`
        - `ATOMIC_{BOOL,ISIZE,USIZE}_INIT`
    - `once`
        - `ONCE_INIT`
This commit is contained in:
bors
2017-09-16 17:02:17 +00:00
60 changed files with 309 additions and 99 deletions

View File

@@ -292,6 +292,7 @@
#![feature(raw)]
#![feature(repr_simd)]
#![feature(rustc_attrs)]
#![cfg_attr(not(stage0), feature(rustc_const_unstable))]
#![feature(shared)]
#![feature(sip_hash_13)]
#![feature(slice_bytes)]
@@ -315,6 +316,17 @@
#![feature(doc_cfg)]
#![cfg_attr(test, feature(update_panic_count))]
#![cfg_attr(not(stage0), feature(const_max_value))]
#![cfg_attr(not(stage0), feature(const_atomic_bool_new))]
#![cfg_attr(not(stage0), feature(const_atomic_isize_new))]
#![cfg_attr(not(stage0), feature(const_atomic_usize_new))]
#![cfg_attr(all(not(stage0), windows), feature(const_atomic_ptr_new))]
#![cfg_attr(not(stage0), feature(const_unsafe_cell_new))]
#![cfg_attr(not(stage0), feature(const_cell_new))]
#![cfg_attr(not(stage0), feature(const_once_new))]
#![cfg_attr(not(stage0), feature(const_ptr_null))]
#![cfg_attr(not(stage0), feature(const_ptr_null_mut))]
#![default_lib_allocator]
// Always use alloc_system during stage0 since we don't know if the alloc_*

View File

@@ -156,6 +156,7 @@ struct Finish {
impl Once {
/// Creates a new `Once` value.
#[stable(feature = "once_new", since = "1.2.0")]
#[cfg_attr(not(stage0), rustc_const_unstable(feature = "const_once_new"))]
pub const fn new() -> Once {
Once {
state: AtomicUsize::new(INCOMPLETE),