Closed
Description
I'm seeing an internal compiler error on the following input, found by fuzz-rustc:
Code
// ţ must be the last character in this file, it cannot be followed by a newline
fn main() {
0: u8(ţ
Error output
error: this file contains an unclosed delimiter
--> src/main.rs:3:12
|
2 | fn main() {
| - unclosed delimiter
3 | 0: u8(ţ
| - ^
| |
| unclosed delimiter
error[E0412]: cannot find type `ţ` in this scope
--> src/main.rs:3:11
|
3 | 0: u8(ţ
| ^ expecting a type here because of type ascription
thread 'rustc' panicked at 'byte index 4 is not a char boundary; it is inside 'ţ' (bytes 3..5) of `u8(ţ`', compiler/rustc_ast_lowering/src/path.rs:236:49
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Affected versions: I tried nightly 2021-11-25 and stable 1.56.1 and they both show the same ICE.
Backtrace
Compiling playground v0.0.1 (/playground)
error: this file contains an unclosed delimiter
--> src/main.rs:3:12
|
2 | fn main() {
| - unclosed delimiter
3 | 0: u8(ţ
| - ^
| |
| unclosed delimiter
error[E0412]: cannot find type `ţ` in this scope
--> src/main.rs:3:11
|
3 | 0: u8(ţ
| ^ expecting a type here because of type ascription
thread 'rustc' panicked at 'byte index 4 is not a char boundary; it is inside 'ţ' (bytes 3..5) of `u8(ţ`', compiler/rustc_ast_lowering/src/path.rs:236:49
stack backtrace:
0: rust_begin_unwind
at /rustc/dd549dcab404ec4c7d07b5a83aca5bdd7171138f/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/dd549dcab404ec4c7d07b5a83aca5bdd7171138f/library/core/src/panicking.rs:107:14
2: core::str::slice_error_fail
3: <rustc_ast_lowering::LoweringContext>::lower_qpath
4: <rustc_ast_lowering::LoweringContext>::lower_ty_direct
5: <rustc_ast_lowering::LoweringContext>::lower_ty
6: rustc_data_structures::stack::ensure_sufficient_stack::<rustc_hir::hir::Expr, <rustc_ast_lowering::LoweringContext>::lower_expr_mut::{closure#0}>
7: <rustc_ast_lowering::LoweringContext>::lower_stmts
8: <rustc_ast_lowering::LoweringContext>::lower_block
9: <rustc_ast_lowering::LoweringContext>::lower_maybe_async_body
10: <rustc_ast_lowering::LoweringContext>::with_hir_id_owner::<<rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_item::{closure#0}>
11: rustc_ast_lowering::lower_crate
12: <rustc_interface::passes::boxed_resolver::BoxedResolver>::access::<rustc_interface::passes::create_global_ctxt::{closure#0}, &rustc_hir::hir::Crate>
13: rustc_interface::passes::create_global_ctxt
14: <rustc_interface::queries::Queries>::global_ctxt
15: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
16: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
17: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
18: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.58.0-nightly (dd549dcab 2021-11-25) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
For more information about this error, try `rustc --explain E0412`.
error: could not compile `playground` due to 2 previous errors
Thanks to the detailed error message I was able to quickly locate the issue, on this line:
rust/compiler/rustc_ast_lowering/src/path.rs
Line 236 in 6d246f0
It is assumed that the last character of snippet
will be a )
, so using snippet.len() - 1
as an index should be safe. However as we see in the input code, it is possible to enter that branch without a closing )
, and it will trigger the panic if the last character happens to be multibyte.