Repository: rust
Issue: ICE when get_adt_def called on a non-ADT DefId(33:288 ~ syntax[67bd]::ptr::SyntaxNodePtr)
Labels: I-ICE,T-compiler,C-bug,E-needs-mcve

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.

http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/

-->
Error happened while trying to build latest [Rust Analyzer](https://github.com/rust-analyzer/rust-analyzer) from the repo.

### Code

```
commit b706ae22dc94231bdbb4bf91632e3ea45dfccce6 (HEAD -> master, origin/staging, origin/master, origin/HEAD)
Merge: bc81dca3d 65a1538dd
Author: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Date:   Sun Jan 2 03:48:38 2022 +0000

    Merge #11160
    
    11160: internal: Use basic `NonEmptyVec` in mbe::syntax_bridge r=Veykril a=Veykril
    
    There are some places in the ide crates where this can be used as well if memory serves right.
    bors r+
    
    Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
```


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc +nightly --version --verbose`:
```
rustc 1.58.0-nightly (e90c5fbbc 2021-11-12)
binary: rustc
commit-hash: e90c5fbbc5df5c81267747daeb937d4e955ce6ad
commit-date: 2021-11-12
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

```

### Error output

```
korvin@epsilon:~/work/research/rust/rust-analyzer$ cargo +nightly xtask install
    Finished dev [unoptimized] target(s) in 0.12s
     Running `target/debug/xtask install`
$ cargo install --path crates/rust-analyzer --locked --force --features force-always-assert
  Installing rust-analyzer v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/rust-analyzer)
    Updating crates.io index
   Compiling parser v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/parser)
   Compiling stdx v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/stdx)
   Compiling tt v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/tt)
   Compiling test_utils v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/test_utils)
   Compiling flycheck v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/flycheck)
   Compiling syntax v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/syntax)
   Compiling cfg v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/cfg)
   Compiling proc_macro_api v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/proc_macro_api)
   Compiling mbe v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/mbe)
   Compiling base_db v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/base_db)
   Compiling project_model v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/project_model)
   Compiling hir_expand v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/hir_expand)
   Compiling proc_macro_srv v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/proc_macro_srv)
   Compiling hir_def v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/hir_def)
   Compiling hir_ty v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/hir_ty)
   Compiling hir v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/hir)
   Compiling ide_db v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/ide_db)
   Compiling ide_ssr v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/ide_ssr)
   Compiling ide_assists v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/ide_assists)
   Compiling ide_completion v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/ide_completion)
error: internal compiler error: compiler/rustc_metadata/src/rmeta/decoder.rs:898:18: get_adt_def called on a non-ADT DefId(33:288 ~ syntax[67bd]::ptr::SyntaxNodePtr)

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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 (e90c5fbbc 2021-11-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [adt_def] computing ADT definition for `syntax::ptr::SyntaxNodePtr`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `ide_assists`
warning: build failed, waiting for other jobs to finish...
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
korvin@epsilon:~/work/research/rust/rust-analyzer$ RUST_BACKTRACE=1 cargo +nightly xtask install             
    Finished dev [unoptimized] target(s) in 0.05s
     Running `target/debug/xtask install`
$ cargo install --path crates/rust-analyzer --locked --force --features force-always-assert
  Installing rust-analyzer v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/rust-analyzer)
    Updating crates.io index
   Compiling ide_assists v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/ide_assists)
   Compiling ide_diagnostics v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/ide_diagnostics)
error: internal compiler error: compiler/rustc_metadata/src/rmeta/decoder.rs:898:18: get_adt_def called on a non-ADT DefId(33:288 ~ syntax[67bd]::ptr::SyntaxNodePtr)

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug
   3: <rustc_errors::Handler>::bug
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_metadata::creader::CrateMetadataRef>::get_adt_def
   8: rustc_metadata::rmeta::decoder::cstore_impl::provide_extern::adt_def
   9: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId, &rustc_middle::ty::adt::AdtDef>
  10: rustc_data_structures::stack::ensure_sufficient_stack::<(&rustc_middle::ty::adt::AdtDef, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::DefId, &rustc_middle::ty::adt::AdtDef>::{closure#3}>
  11: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, &rustc_middle::ty::adt::AdtDef>>
  12: rustc_query_system::query::plumbing::force_query::<rustc_query_impl::queries::adt_def, rustc_query_impl::plumbing::QueryCtxt>
  13: rustc_query_impl::query_callbacks::adt_def::force_from_dep_node
  14: <rustc_middle::ty::context::TyCtxt as rustc_query_system::dep_graph::DepContext>::try_force_from_dep_node
  15: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  16: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  17: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  18: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  19: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  20: rustc_query_system::query::plumbing::ensure_must_run::<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>
  21: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  22: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_interface::passes::analysis::{closure#2}::{closure#0}>
  23: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#2}>
  24: rustc_interface::passes::analysis
  25: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorReported>>
  26: rustc_data_structures::stack::ensure_sufficient_stack::<(core::result::Result<(), rustc_errors::ErrorReported>, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (), core::result::Result<(), rustc_errors::ErrorReported>>::{closure#3}>
  27: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
  28: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  29: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
  30: <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>>
  31: 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}>
  32: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  33: <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.

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 (e90c5fbbc 2021-11-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [adt_def] computing ADT definition for `syntax::ptr::SyntaxNodePtr`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `ide_diagnostics`
warning: build failed, waiting for other jobs to finish...
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug
   3: <rustc_errors::Handler>::bug
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_metadata::creader::CrateMetadataRef>::get_adt_def
   8: rustc_metadata::rmeta::decoder::cstore_impl::provide_extern::adt_def
   9: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId, &rustc_middle::ty::adt::AdtDef>
  10: rustc_data_structures::stack::ensure_sufficient_stack::<(&rustc_middle::ty::adt::AdtDef, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::DefId, &rustc_middle::ty::adt::AdtDef>::{closure#3}>
  11: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, &rustc_middle::ty::adt::AdtDef>>
  12: rustc_query_system::query::plumbing::force_query::<rustc_query_impl::queries::adt_def, rustc_query_impl::plumbing::QueryCtxt>
  13: rustc_query_impl::query_callbacks::adt_def::force_from_dep_node
  14: <rustc_middle::ty::context::TyCtxt as rustc_query_system::dep_graph::DepContext>::try_force_from_dep_node
  15: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  16: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  17: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  18: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  19: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::try_mark_previous_green::<rustc_query_impl::plumbing::QueryCtxt>
  20: rustc_query_system::query::plumbing::ensure_must_run::<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>
  21: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  22: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_interface::passes::analysis::{closure#2}::{closure#0}>
  23: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#2}>
  24: rustc_interface::passes::analysis
  25: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorReported>>
  26: rustc_data_structures::stack::ensure_sufficient_stack::<(core::result::Result<(), rustc_errors::ErrorReported>, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (), core::result::Result<(), rustc_errors::ErrorReported>>::{closure#3}>
  27: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
  28: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  29: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
  30: <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>>
  31: 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}>
  32: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  33: <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.

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 (e90c5fbbc 2021-11-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [adt_def] computing ADT definition for `syntax::ptr::SyntaxNodePtr`
#1 [analysis] running analysis passes on this crate
end of query stack
error: failed to compile `rust-analyzer v0.0.0 (/home/korvin/work/research/rust/rust-analyzer/crates/rust-analyzer)`, intermediate artifacts can be found at `/home/korvin/work/research/rust/rust-analyzer/target`

Caused by:
  build failed
Error: install server

Caused by:
    command `cargo install --path crates/rust-analyzer --locked --force --features force-always-assert` failed, exit status: 101

Stack backtrace:
   0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
   1: <core::result::Result<T,F> as core::ops::try_trait::FromResidual<core::result::Result<core::convert::Infallible,E>>>::from_residual
   2: xtask::install::install_server
   3: xtask::install::<impl xtask::flags::Install>::run
   4: xtask::main
   5: core::ops::function::FnOnce::call_once
   6: std::sys_common::backtrace::__rust_begin_short_backtrace
   7: std::rt::lang_start::{{closure}}
   8: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/core/src/ops/function.rs:259:13
   9: std::panicking::try::do_call
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/std/src/panicking.rs:406:40
  10: std::panicking::try
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/std/src/panicking.rs:370:19
  11: std::panic::catch_unwind
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/std/src/panic.rs:133:14
  12: std::rt::lang_start_internal::{{closure}}
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/std/src/rt.rs:128:48
  13: std::panicking::try::do_call
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/std/src/panicking.rs:406:40
  14: std::panicking::try
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/std/src/panicking.rs:370:19
  15: std::panic::catch_unwind
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/std/src/panic.rs:133:14
  16: std::rt::lang_start_internal
             at /rustc/e90c5fbbc5df5c81267747daeb937d4e955ce6ad/library/std/src/rt.rs:128:20
  17: std::rt::lang_start
  18: main
  19: __libc_start_main
             at /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
  20: _start
```

</p>
</details>