Skip to content

Failing evaluation of constant not reported in cargo check #116936

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
hniksic opened this issue Oct 19, 2023 · 2 comments
Closed

Failing evaluation of constant not reported in cargo check #116936

hniksic opened this issue Oct 19, 2023 · 2 comments
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@hniksic
Copy link
Contributor

hniksic commented Oct 19, 2023

This function rejects zero-sized types at compile-time. (That's a minimal example, real code would check other properties of the type not expressed via a trait, e.g. its alignment, etc., for unsafe/FFI/serialization purposes.)

fn reject_zst<T>(_value: T) {
    struct Check<T>(T);
    impl<T> Check<T> {
        const NON_ZERO_SIZE: () = assert!(std::mem::size_of::<T>() != 0);
    }
    let _ = Check::<T>::NON_ZERO_SIZE;
}

fn main() {
    reject_zst(3.14f64); // compiles
    reject_zst(()); // doesn't compile
}

With cargo build the code is rejected, as expected. However with cargo check it passes compilation.

I expected the compilation to fail with both cargo check and cargo build.

Tested in Rust 1.71.0.

@hniksic hniksic added the C-bug Category: This is a bug. label Oct 19, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 19, 2023
@saethlin saethlin removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 19, 2023
@bjorn3
Copy link
Member

bjorn3 commented Oct 20, 2023

cargo check doesn't report post-monomorphization errors like this. This is tracked at several places like #99682. I believe there was a discussion about if we should guarantee that all post-monomorphization will result in an error for cargo check or not, but I can't find it anymore.

@jieyouxu jieyouxu added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 18, 2024
@RalfJung
Copy link
Member

RalfJung commented Mar 18, 2024

Closing as duplicate of #99682 -- and also as not-a-bug; this is currently intended behavior since checking these constants requires doing a monomorphization pass which would massively slow down cargo check.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
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

6 participants