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

Match check usefulness index out of bounds #15808

Closed
l4l opened this issue Oct 27, 2023 · 5 comments
Closed

Match check usefulness index out of bounds #15808

l4l opened this issue Oct 27, 2023 · 5 comments
Labels
A-pattern pattern handling related things C-bug Category: bug I-panic

Comments

@l4l
Copy link

l4l commented Oct 27, 2023

rust-analyzer version: rust-analyzer 1 (862a300 2023-09-24)
rustc version: 1.72.1 (d5c2e9c34 2023-09-13)
relevant settings: nothing special
editor: helix 23.05

At the editing encountered panic at hir diagnostic:

thread 'Worker' panicked at 'index out of bounds: the len is 0 but the index is 0', crates/hir-ty/src/diagnostics/match_check/usefulness.rs:371:9

preceded with the following message:

[ERROR hir_ty::diagnostics::match_check::deconstruct_pat] trying to compare incompatible constructors Single and IntRange(IntRange { range: 1..=1 })

The code doesn't compiles, though syntax check passes. Unfortunately I'm unable to share the code, nor figure out where MRE. The multi-line stacktrace is shrunk by the editor logger, so I'm only able get stack backtrace:\n 😮‍💨

@l4l l4l added the C-bug Category: bug label Oct 27, 2023
@l4l
Copy link
Author

l4l commented Oct 27, 2023

I guess the problem happens there:

fn specialize_constructor(&self, pcx: PatCtxt<'_, 'p>, ctor: &Constructor) -> Matrix<'p> {
let mut matrix = Matrix::empty();
for row in &self.patterns {
if ctor.is_covered_by(pcx, row.head().ctor()) {
let new_row = row.pop_head_constructor(pcx.cx, ctor);
matrix.push(new_row);
}
}
matrix
}
}

and probably is_covered_by at least should return false for that case

@Veykril
Copy link
Member

Veykril commented Nov 10, 2023

Do you happen to have an example code snippet that triggers this?

@iDawer
Copy link
Contributor

iDawer commented Nov 13, 2023

The error says that a pattern's type is not the same as it should be in a matched type. Such type mismatches should had the whole match check ruled out earlier but on this case it somehow left undetected. Also the error hints that the affecting match expression might involve boolean pattern true.

@l4l Reproducible example would greatly help here.
Some basic instructions of extracting the affecting match expression could be:

  1. Having the affecting file backed up somehow;
  2. Inside that file, start by halving the content off (bisect) or by removing function bodies until the expression is found.
  3. Extract the expression into it's own function with an input argument of type of it's scrutinee expression.
  4. Strip off items that do not affect reproducibility while checking it still reproduces.
  5. Remove contents of the match's arms.
  6. Include unpublished dependency types used in the expression. Their fields aren't necessary if not matched against.
  7. Rename things you feel can't be published.

@Veykril
Copy link
Member

Veykril commented Nov 13, 2023

Note a similar panic being reported here #15883

@Nadrieril Nadrieril added the A-pattern pattern handling related things label Jan 24, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 24, 2024
pattern_analysis: Gracefully abort on type incompatibility

This leaves the option for a consumer of the crate to return `Err` instead of panicking on type error. rust-analyzer could use that (e.g. rust-lang/rust-analyzer#15808).

Since the only use of `TypeCx::bug` is in `Constructor::is_covered_by`, it is tempting to return `false` instead of `Err()`, but that would cause "non-exhaustive match" false positives.

r? `@compiler-errors`
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 5, 2024
…-errors

pattern_analysis: Gracefully abort on type incompatibility

This leaves the option for a consumer of the crate to return `Err` instead of panicking on type error. rust-analyzer could use that (e.g. rust-lang/rust-analyzer#15808).

Since the only use of `TypeCx::bug` is in `Constructor::is_covered_by`, it is tempting to return `false` instead of `Err()`, but that would cause "non-exhaustive match" false positives.

r? `@compiler-errors`
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Feb 6, 2024
pattern_analysis: Gracefully abort on type incompatibility

This leaves the option for a consumer of the crate to return `Err` instead of panicking on type error. rust-analyzer could use that (e.g. rust-lang/rust-analyzer#15808).

Since the only use of `TypeCx::bug` is in `Constructor::is_covered_by`, it is tempting to return `false` instead of `Err()`, but that would cause "non-exhaustive match" false positives.

r? `@compiler-errors`
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
pattern_analysis: Gracefully abort on type incompatibility

This leaves the option for a consumer of the crate to return `Err` instead of panicking on type error. rust-analyzer could use that (e.g. rust-lang#15808).

Since the only use of `TypeCx::bug` is in `Constructor::is_covered_by`, it is tempting to return `false` instead of `Err()`, but that would cause "non-exhaustive match" false positives.

r? `@compiler-errors`
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
pattern_analysis: Gracefully abort on type incompatibility

This leaves the option for a consumer of the crate to return `Err` instead of panicking on type error. rust-analyzer could use that (e.g. rust-lang#15808).

Since the only use of `TypeCx::bug` is in `Constructor::is_covered_by`, it is tempting to return `false` instead of `Err()`, but that would cause "non-exhaustive match" false positives.

r? `@compiler-errors`
@Veykril
Copy link
Member

Veykril commented Jul 7, 2024

Closing as non-reproducible

@Veykril Veykril closed this as completed Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pattern pattern handling related things C-bug Category: bug I-panic
Projects
None yet
Development

No branches or pull requests

4 participants