Rust-GCC / Rust-GCC/gccrs

ICE when trying to compile enums with non-const discriminants.

Open
#3,635 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

Code
fn main() {
    let y = 3;
    enum Foo {
    Bar = y,       
    }
}
Version

b79c452e07c

Error output
crab1: internal compiler error: Segmentation fault
0x12fa2c3 crash_signal
        ../../gccrs/gcc/toplev.cc:319
0xb7ac50 Rust::TyTy::VariantDef::as_string[abi:cxx11]() const
        ../../gccrs/gcc/rust/typecheck/rust-tyty.cc:1541
0xb7afbb Rust::TyTy::ADTType::as_string[abi:cxx11]() const
        ../../gccrs/gcc/rust/typecheck/rust-tyty.cc:1677
0xb975cb Rust::TyTy::VarianceAnalysis::GenericTyVisitorCtx::process_type(Rust::TyTy::ADTType&)
        ../../gccrs/gcc/rust/typecheck/rust-tyty-variance-analysis.cc:236
0xb977f3 Rust::TyTy::VarianceAnalysis::GenericTyPerCrateCtx::process_type(Rust::TyTy::ADTType&)
        ../../gccrs/gcc/rust/typecheck/rust-tyty-variance-analysis.cc:131
0xbb59c7 Rust::Resolver::TypeCheckItem::visit(Rust::HIR::Enum&)
        ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-item.cc:391
0xbb073b Rust::Resolver::TypeCheckItem::Resolve(Rust::HIR::Item&)
        ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-item.cc:59
0xbb073b Rust::Resolver::TypeCheckItem::Resolve(Rust::HIR::Item&)
        ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-item.cc:45
rustc output
error[E0435]: attempt to use a non-constant value in a constant
 --> <source>:6:11
  |
6 |     Bar = y,      
  |           ^ non-constant value
  |
help: consider using `const` instead of `let

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the enum example with gccrs, then start in rust-tyty.cc at VariantDef::as_string and follow the enum path through rust-tyty-variance-analysis.cc and rust-hir-type-check-item.cc. Compare the result with the shown rustc diagnostic; done means this input no longer causes an internal compiler error and reports the invalid non-constant discriminant appropriately.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.