mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
make it possible to enable const_precise_live_drops per-function
This commit is contained in:
parent
717aec0f8e
commit
5412499ad5
@ -9,13 +9,19 @@ use super::check::Qualifs;
|
||||
use super::ops::{self, NonConstOp};
|
||||
use super::qualifs::{NeedsNonConstDrop, Qualif};
|
||||
use super::ConstCx;
|
||||
use crate::check_consts::rustc_allow_const_fn_unstable;
|
||||
|
||||
/// Returns `true` if we should use the more precise live drop checker that runs after drop
|
||||
/// elaboration.
|
||||
pub fn checking_enabled(ccx: &ConstCx<'_, '_>) -> bool {
|
||||
// Const-stable functions must always use the stable live drop checker.
|
||||
// Const-stable functions must always use the stable live drop checker...
|
||||
if ccx.is_const_stable_const_fn() {
|
||||
return false;
|
||||
// ...except if they have the feature flag set via `rustc_allow_const_fn_unstable`.
|
||||
return rustc_allow_const_fn_unstable(
|
||||
ccx.tcx,
|
||||
ccx.body.source.def_id().expect_local(),
|
||||
sym::const_precise_live_drops,
|
||||
);
|
||||
}
|
||||
|
||||
ccx.tcx.features().const_precise_live_drops
|
||||
|
@ -0,0 +1,12 @@
|
||||
error[E0493]: destructor of `Option<T>` cannot be evaluated at compile-time
|
||||
--> $DIR/precise-drop-allow-const-fn-unstable.rs:11:24
|
||||
|
|
||||
LL | pub const fn unwrap<T>(this: Option<T>) -> T {
|
||||
| ^^^^ the destructor for this type cannot be evaluated in constant functions
|
||||
...
|
||||
LL | }
|
||||
| - value is dropped here
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0493`.
|
17
tests/ui/consts/precise-drop-allow-const-fn-unstable.rs
Normal file
17
tests/ui/consts/precise-drop-allow-const-fn-unstable.rs
Normal file
@ -0,0 +1,17 @@
|
||||
//@ revisions: allow not_allow
|
||||
//@ compile-flags: --crate-type=lib -Cinstrument-coverage -Zno-profiler-runtime
|
||||
//@[allow] check-pass
|
||||
|
||||
#![feature(staged_api, rustc_allow_const_fn_unstable)]
|
||||
#![stable(feature = "rust_test", since = "1.0.0")]
|
||||
|
||||
#[stable(feature = "rust_test", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "rust_test", since = "1.0.0")]
|
||||
#[cfg_attr(allow, rustc_allow_const_fn_unstable(const_precise_live_drops))]
|
||||
pub const fn unwrap<T>(this: Option<T>) -> T {
|
||||
//[not_allow]~^ ERROR: cannot be evaluated
|
||||
match this {
|
||||
Some(x) => x,
|
||||
None => panic!(),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user