Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Closed
cushionbadak opened this issue Jun 3, 2024 · 2 comments · Fixed by #126320
Labels
A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

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()
    )));
@cushionbadak cushionbadak added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 3, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 3, 2024
@jieyouxu jieyouxu added A-patterns Relating to patterns and pattern matching S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 4, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jun 9, 2024
@cushionbadak
Copy link
Author

cushionbadak commented Jun 12, 2024

Regression in rust-lang-ci@fa215ae
The PR introducing the regression in this rollup is #122749: make type_flags(ReError) & HAS_ERROR

searched nightlies: from nightly-2023-01-01 to nightly-2024-05-30
regressed nightly: nightly-2024-03-22
searched commit range: 1388d7a...0ad927c
regressed commit: 6a6cd65

bisected with cargo-bisect-rustc v0.6.8

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2023-01-01 --end=2024-05-30 --regress=ice --script=rustc --preserve -- 125914.rs

@cushionbadak
Copy link
Author

Wait, above regression results is exactly same with regression results in #125805. What a coincidence.

fmease added a commit to fmease/rust that referenced this issue Jun 13, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 14, 2024
Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
@bors bors closed this as completed in 2b3fb62 Jun 14, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 14, 2024
Rollup merge of rust-lang#126320 - oli-obk:pat_ice, r=lcnr

Avoid ICES after reporting errors on erroneous patterns

fixes rust-lang#109812
fixes rust-lang#125914
fixes rust-lang#124004
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants