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

Non-ascii prefix in enum variant names causes compiler panic #7869

Closed
lmjk opened this issue Oct 24, 2021 · 6 comments · Fixed by #7873
Closed

Non-ascii prefix in enum variant names causes compiler panic #7869

lmjk opened this issue Oct 24, 2021 · 6 comments · Fixed by #7873
Assignees
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@lmjk
Copy link

lmjk commented Oct 24, 2021

The following enum definition in src/main.rs causes panic when running cargo clippy:

enum Tila {
    TyöAlkoi,
    TyöKeskeytyi,
    TyöValmis,
}

fn main() {}

Error message:

thread 'rustc' panicked at 'byte index 3 is not a char boundary; it is inside 'ö' (bytes 2..4) of `Työ`', src/tools/clippy/clippy_lints/src/enum_variants.rs:180:16
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new

note: Clippy version: clippy 0.1.56 (09c42c4 2021-10-18)
@llogiq llogiq added the I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ label Oct 24, 2021
@xFrednet
Copy link
Member

@rustbot claim

@xFrednet
Copy link
Member

The backtrace looks like this:

stack backtrace:
   0: rust_begin_unwind
             at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panicking.rs:495:5
   1: core::panicking::panic_fmt
             at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/core/src/panicking.rs:107:14
   2: core::str::slice_error_fail
   3: core::str::traits::<impl core::slice::index::SliceIndex<str> for core::ops::range::RangeTo<usize>>::index
             at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/core/src/str/traits.rs:289:21
   4: core::str::traits::<impl core::ops::index::Index<I> for str>::index
             at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/core/src/str/traits.rs:64:9
   5: clippy_lints::enum_variants::check_variant
             at ./clippy_lints/src/enum_variants.rs:180:16
   6: <clippy_lints::enum_variants::EnumVariantNames as rustc_lint::passes::LateLintPass>::check_item
             at ./clippy_lints/src/enum_variants.rs:301:17
   7: <rustc_lint::late::LateLintPassObjects as rustc_lint::passes::LateLintPass>::check_item
   8: rustc_hir::intravisit::Visitor::visit_nested_item
   9: rustc_hir::intravisit::walk_mod
  10: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_mod
  11: rustc_middle::hir::map::Map::walk_toplevel_module
  12: rustc_lint::late::late_lint_pass_crate
  13: rustc_session::utils::<impl rustc_session::session::Session>::time
  14: rustc_session::utils::<impl rustc_session::session::Session>::time
  15: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  16: rustc_session::utils::<impl rustc_session::session::Session>::time
  17: rustc_interface::passes::analysis
  18: rustc_query_system::query::plumbing::try_execute_query
  19: rustc_query_system::query::plumbing::get_query
  20: rustc_interface::passes::QueryContext::enter
  21: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  22: rustc_span::with_source_map
  23: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@llogiq
Copy link
Contributor

llogiq commented Oct 24, 2021

The problem is that the code indexes the string by a number of chars which is not the right thing.

@xFrednet
Copy link
Member

Jup, I'm currently trying to find a native split function which uses the character index 😅

@llogiq
Copy link
Contributor

llogiq commented Oct 24, 2021

I'd rewrite the partial_match function to use char_indices instead of chars and return an index (and perhaps the last char) instead of the char count so far. And similarly partial_rmatch.

@xFrednet
Copy link
Member

My solution looks similar, I've added a new struct in clippy_uitls called StrIndex which provides the byte and character index, then we can always be sure what is being used. Guess this is something worth discussing in the PR once we see how it looks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants