Skip to content

rustc unwraps on a None value in index_hir #81886

Closed
@ZhangZhuoSJTU

Description

@ZhangZhuoSJTU

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.

Metadata

Metadata

Assignees

Labels

A-HIRArea: The high-level intermediate representation (HIR)C-bugCategory: This is a bug.E-needs-testCall 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-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