Skip to content

Parser panics on Invalid syntax pub some_name(); when inside mod #60115

Closed
@CodeSteak

Description

@CodeSteak

Hi,

I got the compiler to panic with this invalid code:

mod test {
    pub some_name();
}

The panic does not happen when the code is outside mod.

Happens on

rustc 1.36.0-nightly (5d20ff4d2 2019-04-18)
binary: rustc
commit-hash: 5d20ff4d2718c820632b38c1e49d4de648a9810b
commit-date: 2019-04-18
host: x86_64-unknown-linux-gnu
release: 1.36.0-nightly
LLVM version: 8.0

Backtrace :

> RUST_BACKTRACE=1 rustc +nightly test.rs                                                                              thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 1', /rustc/5d20ff4d2718c820632b38c1e49d4de648a9810b/src/libcore/slice/mod.rs:2693:14
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   6: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:381
   7: rust_begin_unwind
             at src/libstd/panicking.rs:308
   8: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   9: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:61
  10: syntax::parse::parser::Parser::parse_item_
  11: syntax::parse::parser::Parser::parse_item
  12: syntax::parse::parser::Parser::parse_mod_items
  13: syntax::parse::parser::Parser::parse_item_implementation
  14: syntax::parse::parser::Parser::parse_item_
  15: syntax::parse::parser::Parser::parse_item
  16: syntax::parse::parser::Parser::parse_mod_items
  17: syntax::parse::parser::Parser::parse_crate_mod
  18: syntax::parse::parse_crate_from_file
  19: rustc_interface::passes::parse::{{closure}}
  20: rustc::util::common::time
  21: rustc_interface::passes::parse
  22: rustc_interface::queries::Query<T>::compute
  23: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::parse
  24: rustc_interface::interface::run_compiler_in_existing_thread_pool
  25: std::thread::local::LocalKey<T>::with
  26: scoped_tls::ScopedKey<T>::set
  27: syntax::with_globals
query stack during panic:
end of query stack

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.36.0-nightly (5d20ff4d2 2019-04-18) running on x86_64-unknown-linux-gnu

and also on

rustc 1.34.0 (91856ed52 2019-04-10)
binary: rustc
commit-hash: 91856ed52c58aa5ba66a015354d1cc69e9779bdf
commit-date: 2019-04-10
host: x86_64-unknown-linux-gnu
release: 1.34.0
LLVM version: 8.0

Backtrace :

> RUST_BACKTRACE=1 rustc test.rs                                                                                         
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 1', /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/libcore/slice/mod.rs:2545:14
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   5: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:385
   6: rust_begin_unwind
             at src/libstd/panicking.rs:312
   7: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   8: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:61
   9: syntax::parse::parser::Parser::parse_item_
  10: syntax::parse::parser::Parser::parse_item
  11: syntax::parse::parser::Parser::parse_mod_items
  12: syntax::parse::parser::Parser::parse_item_implementation
  13: syntax::parse::parser::Parser::parse_item_
  14: syntax::parse::parser::Parser::parse_item
  15: syntax::parse::parser::Parser::parse_mod_items
  16: syntax::parse::parser::Parser::parse_crate_mod
  17: syntax::parse::parse_crate_from_file
  18: rustc_driver::driver::phase_1_parse_input::{{closure}}
  19: rustc::util::common::time
  20: rustc_driver::driver::phase_1_parse_input
  21: rustc_driver::driver::compile_input
  22: rustc_driver::run_compiler_with_pool
  23: <scoped_tls::ScopedKey<T>>::set
  24: rustc_driver::run_compiler
  25: syntax::with_globals
  26: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:87
  27: <F as alloc::boxed::FnBox<A>>::call_box
  28: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf/src/liballoc/boxed.rs:759
             at src/libstd/sys_common/thread.rs:14
             at src/libstd/sys/unix/thread.rs:81
  29: start_thread
  30: clone

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.34.0 (91856ed52 2019-04-10) running on x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions