Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue for calling standard library const fns #46038

Closed
SimonSapin opened this issue Nov 16, 2017 · 14 comments
Closed

Tracking issue for calling standard library const fns #46038

SimonSapin opened this issue Nov 16, 2017 · 14 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@SimonSapin
Copy link
Contributor

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 #24111, the super-set feature which also includes defining new const fn items.

  • std::sync::Once::new
  • core::cell::Cell::new
  • core::cell::RefCell::new
  • core::cell::UnsafeCell::new
  • core::sync::AtomicBool::new
  • core::sync::AtomicPtr::new
  • core::sync::Atomic$IntegerType::new
  • core::mem::size_of
  • core::mem::align_of
  • core::ptr::null
  • core::ptr::null_mut
  • <$IntegerType>::max_value
  • <$IntegerType>::min_value

Items in core:: are also re-exported in std::.

@SimonSapin
Copy link
Contributor Author

Feature gates are:

  • const_once_new
  • const_cell_new
  • const_refcell_new
  • const_unsafe_cell_new
  • const_size_of
  • const_align_of
  • const_ptr_null
  • const_ptr_null_mut
  • const_min_value
  • const_max_value
  • const_atomic_bool_new
  • const_atomic_ptr_new
  • const_atomic_i8_new
  • const_atomic_u8_new
  • const_atomic_i16_new
  • const_atomic_u16_new
  • const_atomic_i32_new
  • const_atomic_u32_new
  • const_atomic_i64_new
  • const_atomic_u64_new
  • const_atomic_isize_new
  • const_atomic_usize_new

@kennytm kennytm added B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Nov 16, 2017
@aturon
Copy link
Member

aturon commented Nov 16, 2017

Kicking off stabilization discussion for the const-ness of these functions in std.

@rfcbot fcp merge

@rfcbot rfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Nov 16, 2017
@rfcbot
Copy link

rfcbot commented Nov 16, 2017

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.

@rfcbot
Copy link

rfcbot commented Nov 16, 2017

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Nov 16, 2017
@chabapok
Copy link

How to about mark std::time::Duration::{from_millis, new, from_secs, from_micros} as const_fn?

@sfackler
Copy link
Member

new can panic so it can't be const.

@durka
Copy link
Contributor

durka commented Nov 17, 2017

@sfackler sure it can, the same way an indexing expression can be const (panic turns into const evaluation error).

@sfackler
Copy link
Member

@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

@eddyb
Copy link
Member

eddyb commented Nov 18, 2017

I think this is "what is allowed right now" vs "what we could allow" (i.e. miri evaluates panics just fine).

@durka
Copy link
Contributor

durka commented Nov 18, 2017 via email

@SimonSapin
Copy link
Contributor Author

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®.

@rfcbot
Copy link

rfcbot commented Nov 26, 2017

The final comment period is now complete.

@SimonSapin
Copy link
Contributor Author

I’ve submitted #46287

kennytm added a commit to kennytm/rust that referenced this issue Nov 29, 2017
Stabilize const-calling existing const-fns in std

Fixes rust-lang#46038
@solutiontracking

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants