rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.99k stars 1.55k forks source link

Tuple pattern failure causes panic in Rust Analyzer debug build #17585

Closed ShoyuVanilla closed 1 month ago

ShoyuVanilla commented 1 month ago

Edit: At first, I thought that this was regression between lastest release and HEAD, but this happens debug but not on release profile 🤔

rust-analyzer version: HEAD of master branch, ffbc5ad993d5cd2f3b8bcf9a511165470944ab91

rustc version: rustc 1.79.0 (129f3b996 2024-06-10)

code snippet to reproduce:

fn main() {
    let (_, _, _, ..) = (true, 42);
}

Running rust-analyzer diagnostics on the following code in ffbc5ad993d5cd2f3b8bcf9a511165470944ab91 with debug profile panics with following;

thread 'BIG_STACK_THREAD' panicked at crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs:507:9:
internal error: entered unreachable code: uncaught type error: pattern <write_variant_name unsupported>(_ : Bool, _ : Int(I32), _ : {error}) has inconsistent arity (expected arity <= 2)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

while running it on the same revision with release profile works just fine;

2024-07-12T21:39:03.778314Z ERROR hir_ty::diagnostics::match_check::pat_analysis: uncaught type error: pattern <write_variant_name unsupported>(_ : Bool, _ : Int(I32), _ : {error}) has inconsistent arity (expected arity <=
2)
Diagnostic { code: RustcHardError("E0308"), message: "expected (bool, i32), found (bool, i32, {unknown})", range: FileRange { file_id: FileId(11), range: 20..33 }, severity: Error, unused: false, experimental: true, fixes:
None, main_node: None }

diagnostic scan complete

Error: diagnostic error detected
ShoyuVanilla commented 1 month ago

I'll try bisect some hours later this happens between debug and release profiles 🤔

lnicola commented 1 month ago

We panic on some errors in development builds.

ShoyuVanilla commented 1 month ago

Oh, I see. I'll dig into this more. @rustbot claim

lnicola commented 1 month ago

The code that calls bug is in rustc_pattern_analysis, which isn't robust to type errors. In other places we try to ignore them, see https://github.com/rust-lang/rust-analyzer/pull/17534.

ShoyuVanilla commented 1 month ago

The code that calls bug is in rustc_pattern_analysis, which isn't robust to type errors.

That's sad 😢

Veykril commented 1 month ago

We are already doing mismatch checks for match exhaustiveness checking, we are probably not doing the same for checking let statements?