Skip to content

Non-primitive-types static assertions result in an LLVM failure #22056

Closed
@LeoTestard

Description

@LeoTestard

The code:

struct S;

#[static_assert]
static FOO: S = S;

fn main() {}

results in:

issue-13951.rs:1:1: 1:10 warning: struct is never used: `S`, #[warn(dead_code)] on by default
issue-13951.rs:1 struct S;
                 ^~~~~~~~~
issue-13951.rs:4:1: 4:19 warning: static item is never used: `FOO`, #[warn(dead_code)] on by default
issue-13951.rs:4 static FOO: S = S;
                 ^~~~~~~~~~~~~~~~~~
rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/llvm/include/llvm/Support/Casting.h:237: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::ConstantInt; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type = llvm::ConstantInt*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

This has no meaning and should be at least warned about. Putting #[static_assert] on non-static items (like struct definitions... ) is silently ignored.
I think that we should restrict #[static_assert] to boolean statics, and emit a warning or an error in the other cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions