Skip to content

rustc unwraps on a None value in index_hir #81886

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
ZhangZhuoSJTU opened this issue Feb 8, 2021 · 5 comments · Fixed by #91111
Closed

rustc unwraps on a None value in index_hir #81886

ZhangZhuoSJTU opened this issue Feb 8, 2021 · 5 comments · Fixed by #91111
Assignees
Labels
A-HIR Area: The high-level intermediate representation (HIR) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-extended_key_value_attributes `#![feature(extended_key_value_attributes)] I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ZhangZhuoSJTU
Copy link

I got a very large poc file, and reduce it into following code. But after reducing (via a simple delta debugging tech), the code looks kind of confusing. Please let me know if anyone prefers a better-formed but long test-case, and I will try me best to get one.

Code

#[c]

fn e() {
    (#[p=#[k] {fn n({(}[}0

md5: ee8b18d572cb8cc464d220338b0be46d

Meta

The bug is reproduced with nightly and beta versions, but not with stable version.

rustc --version --verbose:

rustc 1.52.0-nightly (9778068cb 2021-02-07)
binary: rustc
commit-hash: 9778068cbc1e06cc3685422323ff38a2f397de26
commit-date: 2021-02-07
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

rustc 1.50.0-beta.9 (2efd07024 2021-02-06)
binary: rustc
commit-hash: 2efd07024a6d1dc0d4ea0a538ddbcec7cc3a4eeb
commit-date: 2021-02-06
host: x86_64-unknown-linux-gnu
release: 1.50.0-beta.9

Error output

The output is from nightly.

➜  playground rustc poc.rs
error: this file contains an unclosed delimiter
 --> poc.rs:4:28
  |
3 | fn e() {
  |        - unclosed delimiter
4 |     (#[p=#[k] {fn n({(}[}0
  |     - - unclosed delimiter ^
  |     |
  |     unclosed delimiter

error: expected parameter name, found `{`
 --> poc.rs:4:21
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |                     ^ expected parameter name

error: expected one of `->`, `;`, `where`, or `{`, found `}`
 --> poc.rs:4:25
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |                   -     ^ expected one of `->`, `;`, `where`, or `{`
  |                   |
  |                   while parsing this `fn`

error: expected one of `.`, `?`, `]`, or an operator, found `0`
 --> poc.rs:4:26
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |                        - ^ help: `]` may belong here
  |                        |
  |                        unclosed delimiter

error: expected one of `)`, `.`, `;`, `?`, `}`, or an operator, found `]`
 --> poc.rs:4:28
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |                      -    -^
  |                      |    |
  |                      |    help: `)` may belong here
  |                      unclosed delimiter

error: expected expression, found `]`
 --> poc.rs:4:28
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |                            ^ expected expression

error[E0658]: attributes on expressions are experimental
 --> poc.rs:4:6
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |      ^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

error[E0658]: attributes on expressions are experimental
 --> poc.rs:4:10
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |          ^^^^
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

error: unexpected token: `#[k] {
         fn n((/*ERROR*/));
     }`
 --> poc.rs:4:15
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |               ^^^^^^^^^^^

error: cannot find attribute `c` in this scope
 --> poc.rs:1:3
  |
1 | #[c]
  |   ^

error: cannot find attribute `p` in this scope
 --> poc.rs:4:8
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |        ^

error: cannot find attribute `k` in this scope
 --> poc.rs:4:12
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |            ^

error[E0658]: arbitrary expressions in key-value attributes are unstable
 --> poc.rs:4:15
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |               ^^^^^^^^^^^
  |
  = note: see issue #78835 <https://github.com/rust-lang/rust/issues/78835> for more information
  = help: add `#![feature(extended_key_value_attributes)]` to the crate attributes to enable

warning: unnecessary parentheses around block return value
 --> poc.rs:4:5
  |
4 |     (#[p=#[k] {fn n({(}[}0
  |     ^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
  |
  = note: `#[warn(unused_parens)]` on by default

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_middle/src/hir/map/collector.rs:157:78
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (9778068cb 2021-02-07) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [index_hir] index HIR
#1 [hir_owner] HIR owner of `{misc#0}`
end of query stack
error: aborting due to 13 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0658`.
Backtrace

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_middle/src/hir/map/collector.rs:157:78
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9778068cbc1e06cc3685422323ff38a2f397de26/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/9778068cbc1e06cc3685422323ff38a2f397de26/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/9778068cbc1e06cc3685422323ff38a2f397de26/library/core/src/panicking.rs:50:5
   3: rustc_middle::hir::map::collector::NodeCollector::finalize_and_compute_crate_hash
   4: rustc_middle::hir::map::index_hir
   5: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
   6: rustc_data_structures::stack::ensure_sufficient_stack
   7: rustc_query_system::query::plumbing::force_query_with_job
   8: rustc_query_system::query::plumbing::get_query_impl
   9: core::ops::function::FnOnce::call_once
  10: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  11: rustc_data_structures::stack::ensure_sufficient_stack
  12: rustc_query_system::query::plumbing::force_query_with_job
  13: rustc_query_system::query::plumbing::get_query_impl
  14: rustc_middle::hir::map::Map::expect_item
  15: rustc_middle::hir::map::Map::visit_item_likes_in_module
  16: rustc_passes::hir_id_validator::check_crate
  17: rustc_interface::passes::analysis
  18: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  19: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  20: rustc_data_structures::stack::ensure_sufficient_stack
  21: rustc_query_system::query::plumbing::force_query_with_job
  22: rustc_query_system::query::plumbing::get_query_impl
  23: rustc_interface::passes::QueryContext::enter
  24: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  25: rustc_span::with_source_map
  26: rustc_interface::interface::create_compiler_and_run
  27: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@ZhangZhuoSJTU ZhangZhuoSJTU added 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 Feb 8, 2021
@jonas-schievink jonas-schievink added A-HIR Area: The high-level intermediate representation (HIR) I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 8, 2021
@estebank
Copy link
Contributor

estebank commented Feb 8, 2021

This can be "solved" by using get and create a delay_span_bug instead of panicking.

@apiraino apiraino added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 10, 2021
@apiraino
Copy link
Contributor

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@jyn514 jyn514 added the F-extended_key_value_attributes `#![feature(extended_key_value_attributes)] label Mar 22, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 22, 2021

A reproduction with fewer errors:

#![feature(extended_key_value_attributes)]
#![doc = {enum b {}}]
error: unexpected token: `{
    enum b { }
}`
 --> src/main.rs:2:10
  |
2 | #![doc = {enum b {}}]
  |          ^^^^^^^^^^^

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_middle/src/hir/map/mod.rs:299:38

@Badel2
Copy link
Contributor

Badel2 commented Nov 20, 2021

The provided examples do not panic anymore, can this issue be closed or does it need tests?

@estebank estebank added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Nov 20, 2021
@estebank
Copy link
Contributor

@Badel2 lets keep it open purely to track adding regression tests for these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-HIR Area: The high-level intermediate representation (HIR) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-extended_key_value_attributes `#![feature(extended_key_value_attributes)] I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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.

7 participants