forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
#[rustc_force_min_const_fn]
.
The attribute will force a `const fn` to adhere to the `qualify_min_const_fn` check and as a result be callable inside a `#[stable] const fn` one on stable Rust. The attribute has two purposes: 1. Make `#[unstable] const fn` details in the standard library usable in `#[stable] const fn`s. 2. Prepare a `#[stable] #[rustc_unstable_const(..)] const fn` for eventually removing the `#[rustc_unstable_const(..)]`.
- Loading branch information
Showing
3 changed files
with
15 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,21 +42,27 @@ impl<'tcx> TyCtxt<'tcx> { | |
|
||
/// Returns `true` if this function must conform to `min_const_fn` | ||
pub fn is_min_const_fn(self, def_id: DefId) -> bool { | ||
// Bail out if the signature doesn't contain `const` | ||
// Bail out if the signature doesn't contain `const`. | ||
if !self.is_const_fn_raw(def_id) { | ||
return false; | ||
} | ||
|
||
if self.has_attr(def_id, sym::rustc_force_min_const_fn) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Centril
Author
Owner
|
||
// The `const fn` has `#[rustc_force_min_const_fn]`. | ||
// We have been ordered to interpret this as a `min_const_fn` no matter what. | ||
return true; | ||
} | ||
|
||
if self.features().staged_api { | ||
// in order for a libstd function to be considered min_const_fn | ||
// it needs to be stable and have no `rustc_const_unstable` attribute | ||
// For a libstd function to be considered `min_const_fn`, | ||
// it needs to be stable and have no `rustc_const_unstable` attribute. | ||
match self.lookup_stability(def_id) { | ||
// stable functions with unstable const fn aren't `min_const_fn` | ||
// Stable functions with `rustc_const_unstable` aren't `min_const_fn`. | ||
Some(&attr::Stability { const_stability: Some(_), .. }) => false, | ||
// unstable functions don't need to conform | ||
// Unstable functions don't need to conform. | ||
Some(&attr::Stability { ref level, .. }) if level.is_unstable() => false, | ||
// everything else needs to conform, because it would be callable from | ||
// other `min_const_fn` functions | ||
// Everything else needs to conform, because it would be callable from | ||
// other `min_const_fn` functions. | ||
_ => true, | ||
} | ||
} else { | ||
|
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
One thing that could be done is what's essentially the opposite scheme. Everything requires
min_const_fn
by default, unless it has an additionalrustc_not_min_const_fn
attribute (which makes the function uncallable from anymin_const_fn
).Or rename the attribute to
rustc_require_min_const_fn
, to make it sound less like an override