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

Unreachable call of non-const fn from const fn is not a compilation error #110831

Open
tonowak opened this issue Apr 25, 2023 · 1 comment
Open
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tonowak
Copy link

tonowak commented Apr 25, 2023

I tried this code (playground):

fn non_const_fn(value: i64) {}

const fn witness() {
    non_const_fn(todo!());
}

I expected to see this happen: a compilation error. Calling a non-const function (even though it's unreachable) should produce a compilation error, just like it would with a i64 value instead of todo!().

The compilation error with a value instead of todo!():

error[E0015]: cannot call non-const fn `non_const_fn` in constant functions
 --> src/lib.rs:4:5
  |
4 |     non_const_fn(0);
  |     ^^^^^^^^^^^^^^^
  |

Instead, this happened: the code compiles (with a warning unreachable call).

Meta

rustc --version --verbose:

rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-unknown-linux-gnu
release: 1.67.0
LLVM version: 15.0.6

rustc 1.71.0-nightly (f5559e338 2023-04-24)
binary: rustc
commit-hash: f5559e338256f17ada6d82b429acc2dbd8facc9c
commit-date: 2023-04-24
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

@tonowak tonowak added the C-bug Category: This is a bug. label Apr 25, 2023
@Jules-Bertholet
Copy link
Contributor

Jules-Bertholet commented Apr 26, 2023

@rustbot label +A-const-fn

@jyn514 jyn514 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 26, 2023
@RalfJung RalfJung added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) and removed A-const-fn labels Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants