Repository navigation
Constant is being evaluated despite failing const_precise_live_drops #163973
Copy link
Copy link
Open
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
The point of const_precise_live_drops is to ensure that the program can never execute a non-const drop during CTFE. The following code must therefore be rejected:
#![feature(const_precise_live_drops)]
struct NotConstDestruct;
impl Drop for NotConstDestruct {
fn drop(&mut self) {}
}
// Mutable borrow of a type with drop impl.
pub const A1: () = {
let mut x = None;
let mut y = Some(NotConstDestruct);
let a = &mut x;
let b = &mut y;
std::mem::swap(a, b);
std::mem::forget(y);
};And it is:
error[E0493]: destructor of `Option<NotConstDestruct>` cannot be evaluated at compile-time
--> src/lib.rs:11:9
|
11 | let mut x = None;
| ^^^^^ the destructor for this type cannot be evaluated in constants
...
17 | };
| - value is dropped here
However, for some reason, we are then still executing this code, which obviously cannot work as the destructor is non-const:
error[E0080]: calling non-const function `<NotConstDestruct as Drop>::drop`
--> src/lib.rs:17:1
|
17 | };
| ^ evaluation of `A1` failed inside this call
That second error should never be reached in normal operation. Apparently we're failing to properly taint this MIR body or so? @oli-obk any idea what is happening here?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
oli-obk commentedon Oct 8, 2026
Oh I think we never made const_precise_live_drops taint the MIR
martonmoro commentedon Oct 8, 2026
@rustbot claim
martonmoro commentedon Oct 8, 2026
Hi @RalfJung I'd be happy to work on this :)
RalfJung commentedon Oct 8, 2026
That's great! But I just reported the issue, that doesn't mean I have the time or knowledge to mentor someone for how to fix it. Please be mindful when pinging people, don't just ping random folks that show up in the issue.
In this case @oli-obk added the E-mentor label so it looks like he may have the capacity to mentor this.
Rollup merge of rust-lang#163972 - RalfJung:non-const-eval, r=oli-obk
Rollup merge of rust-lang#163972 - RalfJung:non-const-eval, r=oli-obk
Rollup merge of rust-lang#163972 - RalfJung:non-const-eval, r=oli-obk
Rollup merge of rust-lang#163972 - RalfJung:non-const-eval, r=oli-obk
Rollup merge of rust-lang#163972 - RalfJung:non-const-eval, r=oli-obk
Unrolled build for #163972 in rollup 164052
matthiaskrgr commentedon Oct 10, 2026
RalfJung commentedon Oct 11, 2026
Yes, that's an expected side-effect of #163972.
ligmitz commentedon Oct 12, 2026
Hey @martonmoro, is there any further discussion regarding this issue on Zulip apart from the comments in this thread? I would like to follow, thanks !