Type Mismatch and ICE on Slice Constant Pattern Matching in gccrs

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

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp, rust
Domain
compilers

Research direction

Reproduce the failure with the Rust snippet or the linked Godbolt example, then inspect the pattern type-checking path named in the backtrace, especially TypeCheckPattern::visit in rust/typecheck/rust-tyty-util.cc. Trace both the slice-constant coercion and the match-pattern handling; done means the example compiles without the type mismatch or ICE and preserves the expected slice-content match behavior.

Written by the indexing model from the issue text.

Description

Summary

The provided Rust code compiles successfully with rustc but fails with gccrs due to a type mismatch and an internal compiler error (ICE). The issues occur when initializing a slice constant and using it in a pattern match.

Reproducer

I tried this code:

#![allow(dead_code)]

const PATH_DOT: &[u8] = &[b'.'];// Type mismatch error here

fn match_slice(element: &[u8]) {
    match element {
        &[] => {}
        PATH_DOT => {}// ICE occurs during type checking
        _ => {}
    }
}

fn main() {}
Does the code make use of any (1.49) nightly feature ?
  • Nightly
Godbolt link

https://godbolt.org/z/8PETWKfK5

Actual behavior

:4:1: error: mismatched types, expected '& [u8]' but got '& [u8:CAPACITY]' [E0308]
4 | const PATH_DOT: &[u8] = &[b'.'];
| ^~~~~ ~ ~
:8:10: sorry, unimplemented: type checking qualified path patterns not supported
8 | &[] => {}
| ^
crab1: internal compiler error: in TyVar, at rust/typecheck/rust-tyty-util.cc:31
0x2e9eb6c internal_error(char const*, ...)
???:0
0xf5e963 fancy_abort(char const*, int, char const*)
???:0
0x12795a2 Rust::Resolver::TypeCheckPattern::visit(Rust::HIR::ReferencePattern&)
???:0
0x12793d8 Rust::Resolver::TypeCheckPattern::Resolve(Rust::HIR::Pattern*, Rust::TyTy::BaseType*)
???:0
0x127eaef Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::MatchExpr&)
???:0
0x127bd13 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*)
???:0
0x127d11d Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::BlockExpr&)
???:0
0x127bd13 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*)
???:0
0x126a82b Rust::Resolver::TypeCheckItem::visit(Rust::HIR::Function&)
???:0
0x1263750 Rust::Resolver::TypeCheckItem::Resolve(Rust::HIR::Item&)
???:0
0x122427b Rust::Resolver::TypeResolution::Resolve(Rust::HIR::Crate&)
???:0
0x109a454 Rust::Session::compile_crate(char const*)
???:0
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See https://gcc.gnu.org/bugs/ for instructions.
Compiler returned: 1

Expected behavior

The code should compile successfully. The constant PATH_DOT (type &[u8]) should be initialized from &[u8; 1] via implicit array-to-slice coercion. The match arm PATH_DOT should compare slice contents structurally.

GCC Version

14.0.1

Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
20h 2m
Merged PRs (30d)
66

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.

More from Rust-GCC/gccrs

All issues in Rust-GCC/gccrs

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.