Skip to content

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

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

Closed
CodeSteak opened this issue Apr 19, 2019 · 1 comment · Fixed by #60119
Closed

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

CodeSteak opened this issue Apr 19, 2019 · 1 comment · Fixed by #60119
Assignees
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CodeSteak
Copy link

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
@jonas-schievink jonas-schievink added A-parser Area: The lexing & parsing of Rust source code to an AST C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 19, 2019
@jonas-schievink
Copy link
Contributor

First appeared in 1.33.0, 1.32.0 gives this error:

error: missing `fn` or `struct` for method or struct definition
 --> test.rs:2:8
  |
2 |     pub some_name();
  |     ---^--------- help: if you meant to call a macro, try: `some_name!`

error: aborting due to previous error

@jonas-schievink jonas-schievink added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Apr 19, 2019
@estebank estebank self-assigned this Apr 19, 2019
bors added a commit that referenced this issue Apr 21, 2019
Remove assumption from recovery code

Fix #60115.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants