Skip to content

ICE: uncaught type error: pattern ... has inconsistent arity (expected arity <= ...) in rustc_pattern_analysis/src/rustc.rs #125914

Closed

Description

Code

(hand-reduced)

enum AstKind<'ast> {
    ExprInt,
}

enum Foo {
    Bar(isize),
    Baz,
}

enum Other {
    Other1(Foo),
    Other2(AstKind),
}

fn main() {
    match Other::Other1(Foo::Baz) {
        ::Other::Other2(::Foo::Bar(..)) => {}
    }
}
(original)

type Ast<'ast> = &'ast AstStructure<'ast>;

struct AstStructure<'ast> {
    id: NodeId,
    _: AstKind<'ast>
}

enum AstKind<'ast> {
    ExprInt,
    ExprLambda(Ast<'ast>),
}

fn compute_types<'tcx,'ast>(ast: Ast<'ast>) -> Type<'tcx>
{
    match ast.kind {}
}


//@ run-pass
#![allow(dead_code)]

enum Foo {
    Bar(isize),
    Baz,
}

enum Other {
    Other1(Foo),
    Other2(AstKind, Foo),
}

fn main() {
    match Foo::Baz {
        ::Foo::Bar(3) => panic!(),
        ::Foo::Bar(_) if false => panic!(),
        ::Foo::Bar(..) if false => panic!(),
        ::Foo::Bar(_n) => panic!(),
        ::Foo::Baz => {}
    }
    match Foo::Bar(3) {
        ::Foo::Bar(3) => {}
        ::Foo::Bar(_) if false => panic!(),
        ::Foo::Bar(..) if false => panic!(),
        ::Foo::Bar(_n) => panic!(),
        ::Foo::Baz => panic!(),
    }
    match Foo::Bar(4) {
        ::Foo::Bar(3) => panic!(),
        ::Foo::Bar(_) if false => panic!(),
        ::Foo::Bar(..) if false => panic!(),
        ::Foo::Bar(n) => assert_eq!(n, 4),
        ::Foo::Baz => panic!(),
    }

    match Other::Other1(Foo::Baz) {
        ::Other::Other1(::Foo::Baz) => {}
        ::Other::Other1(::Foo::Bar(_)) => {}
        ::Other::Other2(::Foo::Baz, ::Foo::Bar(_)) => {}
        ::Other::Other2(::Foo::Bar(..), ::Foo::Baz) => {}
        ::Other::Other2(..) => {}
    }
}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (032af18af 2024-06-02)
binary: rustc
commit-hash: 032af18af578f4283a2927fb43b90df2bbb72b67
commit-date: 2024-06-02
host: x86_64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6

Error output

Command: rustc

error[E0106]: missing lifetime specifier
  --> r_pattern_FA0651A.rs:12:12
   |
12 |     Other2(AstKind),
   |            ^^^^^^^ expected named lifetime parameter
   |
help: consider introducing a named lifetime parameter
   |
10 ~ enum Other<'a> {
11 |     Other1(Foo),
12 ~     Other2(AstKind<'a>),
   |

error[E0392]: lifetime parameter `'ast` is never used
 --> r_pattern_FA0651A.rs:1:14
  |
1 | enum AstKind<'ast> {
  |              ^^^^ unused lifetime parameter
  |
  = help: consider removing `'ast`, referring to it in a field, or using a marker such as `PhantomData`
Backtrace

error: internal compiler error: compiler/rustc_pattern_analysis/src/rustc.rs:898:9: uncaught type error: pattern Bar(_) has inconsistent arity (expected arity <= 0)
  --> r_pattern_FA0651A.rs:16:11
   |
16 |     match Other::Other1(Foo::Baz) {
   |           ^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_pattern_analysis/src/rustc.rs:898:9:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: <rustc_errors::DiagCtxt>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis::rustc::RustcPatCtxt>
   8: rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis::rustc::RustcPatCtxt>
   9: rustc_pattern_analysis::analyze_match
  10: <rustc_mir_build::thir::pattern::check_match::MatchVisitor>::analyze_patterns
  11: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  12: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  13: rustc_middle::thir::visit::walk_block::<rustc_mir_build::thir::pattern::check_match::MatchVisitor>
  14: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  15: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  16: rustc_mir_build::thir::pattern::check_match::check_match
      [... omitted 1 frame ...]
  17: rustc_mir_build::build::mir_build
  18: rustc_mir_transform::mir_built
      [... omitted 1 frame ...]
  19: rustc_mir_build::check_unsafety::check_unsafety
      [... omitted 1 frame ...]
  20: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  21: rustc_interface::passes::run_required_analyses
  22: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  23: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  24: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/Volumes/T7/workspace/240602_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-03T05_51_05-52215.txt` to your bug report

query stack during panic:
#0 [check_match] match-checking `main`
#1 [mir_built] building MIR for `main`
#2 [check_unsafety] unsafety-checking `main`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0106, E0392.
For more information about an error, try `rustc --explain E0106`.

Note

  • ICE location: rustc_pattern_analysis/src/rustc.rs L898
    fn bug(&self, fmt: fmt::Arguments<'_>) -> Self::Error {
    span_bug!(self.scrut_span, "{}", fmt)
    }
  • ICE message can be found at: rustc_pattern_analysis/src/usefulness.rs L1010 (fn pop_head_constructor)
    if head_pat.as_pat().is_some_and(|pat| pat.arity() > ctor_arity) {
    // Arity can be smaller in case of variable-length slices, but mustn't be larger.
    return Err(cx.bug(format_args!(
    "uncaught type error: pattern {:?} has inconsistent arity (expected arity <= {ctor_arity})",
    head_pat.as_pat().unwrap()
    )));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions