Skip to content

Program that uses the const VOID: ! =panic!() associated constant compiles and runs into illegal intruction. #66975

Closed
@rodrimati1992

Description

@rodrimati1992

This unsound code compiles in the playground (on Rust nightly 2019-12-01):

#![feature(const_panic)]

struct PrintName;

impl PrintName {
    const VOID: ! = panic!();
}

fn main() {
    let _ = PrintName::VOID;
}

And runs into an illegal instruction:

   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 0.65s
     Running `target/debug/playground`
timeout: the monitored command dumped core
/root/entrypoint.sh: line 8:     7 Illegal instruction     timeout --signal=KILL ${timeout} "$@"

I expected this to fail to compile because panicking in constants should cause compilation errors.

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions