Skip to content

ICE when combining wrong syntax with Unicode string literal #64792

Closed

Description

In syntactically erroneous inputs, non-ASCII string literals can cause a compiler panic.

Being a dilettante with fingers used to C++, I tried to initialize a struct without calling its new method, and it so happened that I was passing it a non-ASCII string. This gave me a compiler panic. Here's a small example:

struct X {}

fn f() {
    let x = X("ö");
}

Meta

I am using the Manjaro (Arch Linux) rustpackage, version 1:1.37.0-2.

rustc --version --verbose:

rustc 1.37.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.37.0
LLVM version: 8.0

Backtrace:

thread 'rustc' panicked at 'byte index 38 is not a char boundary; it is inside 'ö' (bytes 37..39) of `struct X {}

fn f() {
    let x = X("ö");
}
`', src/libcore/str/mod.rs:2034:5
stack backtrace:
   0:     0x7f028b22db8b - <unknown>
   1:     0x7f028b22d867 - <unknown>
   2:     0x7f028a3914f1 - <unknown>
   3:     0x7f028b22e3e9 - std::panicking::rust_panic_with_hook::h4e663330759b90e1
   4:     0x7f028b22de82 - <unknown>
   5:     0x7f028b22dd66 - rust_begin_unwind
   6:     0x7f028b25812d - core::panicking::panic_fmt::ha8e419005b06d9fa
   7:     0x7f028b25a7a0 - core::str::slice_error_fail::h4de83ee694f497ba
   8:     0x7f0289a31332 - rust_metadata_syntax_1baa2f1ef67248f5354eb1ad9534ec0
   9:     0x7f0289a69c6a - syntax::source_map::SourceMap::span_to_snippet::h194946e102592953
  10:     0x7f028955c867 - <unknown>
  11:     0x7f028955a4fd - <unknown>
  12:     0x7f02895a9a1f - <unknown>
  13:     0x7f02895a96d2 - <unknown>
  14:     0x7f02895a87a5 - <unknown>
  15:     0x7f02895adc33 - <unknown>
  16:     0x7f02895adc48 - <unknown>
  17:     0x7f02895a3db2 - <unknown>
  18:     0x7f02895a78ba - <unknown>
  19:     0x7f02895898e4 - <rustc_resolve::Resolver as syntax::visit::Visitor>::visit_fn::h423a6899b245d8eb
  20:     0x7f028953f32c - rust_metadata_rustc_resolve_5579cc0878d821c85113ee4c903d2100
  21:     0x7f0289597a0c - <unknown>
  22:     0x7f028958f9cc - rustc_resolve::Resolver::resolve_crate::h7850549a32dca50e
  23:     0x7f028af65cc4 - <unknown>
  24:     0x7f028af73dcc - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::expansion::hc3bebb558c007928
  25:     0x7f028af74bb4 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::lower_to_hir::h4f94678c772d58ae
  26:     0x7f028af751d2 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::prepare_outputs::h3c5b38fbb69a9154
  27:     0x7f028b2d8f39 - <unknown>
  28:     0x7f028b23f31a - __rust_maybe_catch_panic
  29:     0x7f028b2df729 - <unknown>
  30:     0x7f028b210d6f - rust_metadata_std_d72cd6cf31ff9bd7b7e3914e0cf9c8c9
  31:     0x7f028b23def0 - <unknown>
  32:     0x7f02897e257f - start_thread
  33:     0x7f028b0fd0e3 - __clone
  34:                0x0 - <unknown>
query stack during panic:
end of query stack
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-resolveArea: Name resolutionA-unicodeArea: UnicodeC-bugCategory: This is a bug.E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-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