Repository: rust
Issue: ICE: failed to get layout for `[type error]`: the type `[type error]` has an unknown layout
Labels: I-ICE,T-compiler,C-bug,S-has-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/

-->

Hello! This is a strange bug that I'm reporting. I don't have the slightest idea of what it does, nor is it very relevant how I encountered this bug. I report it because it might unveil something important. Anyway, here it is.

### Code

Make a new lib with `cargo new --lib rustc-bug` and put this in `src/lib.rs`:

````rust
/*!
```rust
use rustfmt::lexer::{lex_tokens, Token};
assert!(lex_tokens("Hello!") == Ok(("", vec![Token::Command])));
```
*/
````

That's it: an empty module with a single documentation comment with a doc-test.

Now, if you are ready for the bang, run `cargo test --doc` and you'll be welcomed with

```
error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:974:13: failed to get layout for `[type error]`: the type `[type error]` has an unknown layout
 --> src/lib.rs:1:38
  |
2 | fn main() { #[allow(non_snake_case)] fn _doctest_main_src_lib_rs_1_0() {
  |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

The full backtrace is at the end.

### 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 --version --verbose`:
```
rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-unknown-linux-gnu
release: 1.64.0
LLVM version: 14.0.6
```

The same bug persists if I run it with this nightly version:
```
rustc 1.66.0-nightly (8b705839c 2022-09-26)
binary: rustc
commit-hash: 8b705839cd656d202e920efa8769cbe43a5ee269
commit-date: 2022-09-26
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.0
```

### Error output

<!--
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>

```
running 1 test
test src/lib.rs - (line 1) ... FAILED

failures:

---- src/lib.rs - (line 1) stdout ----
error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:974:13: failed to get layout for `[type error]`: the type `[type error]` has an unknown layout
 --> src/lib.rs:1:38
  |
2 | fn main() { #[allow(non_snake_case)] fn _doctest_main_src_lib_rs_1_0() {
  |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/compiler/rustc_errors/src/lib.rs:1332:9
stack backtrace:
   0:     0x7f8ec2bb919d - std::backtrace_rs::backtrace::libunwind::trace::h9135f25bc195152c
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f8ec2bb919d - std::backtrace_rs::backtrace::trace_unsynchronized::h015ee85be510df51
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f8ec2bb919d - std::sys_common::backtrace::_print_fmt::h5fad03caa9652a2c
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f8ec2bb919d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2b42ca28d244e5c7
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f8ec2c146ac - core::fmt::write::h401e827d053130ed
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/fmt/mod.rs:1198:17
   5:     0x7f8ec2baa4e1 - std::io::Write::write_fmt::hffec93268f5cde32
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/io/mod.rs:1672:15
   6:     0x7f8ec2bbbeb5 - std::sys_common::backtrace::_print::h180c4c706ee1d3fb
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f8ec2bbbeb5 - std::sys_common::backtrace::print::hd0c35d18765761c9
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f8ec2bbbeb5 - std::panicking::default_hook::{{closure}}::h1f023310983bc730
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:295:22
   9:     0x7f8ec2bbbbd1 - std::panicking::default_hook::h188fec3334afd5be
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:314:9
  10:     0x7f8ec1645484 - rustc_driver[4568cc0a685fd94d]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f8ec2bbc5ea - std::panicking::rust_panic_with_hook::hf26e9d4f97b40096
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:702:17
  12:     0x7f8ec16fc491 - std[306a94a967d8f5ee]::panicking::begin_panic::<rustc_errors[5fcb1a1f56a762e6]::ExplicitBug>::{closure#0}
  13:     0x7f8ec16fc196 - std[306a94a967d8f5ee]::sys_common::backtrace::__rust_end_short_backtrace::<std[306a94a967d8f5ee]::panicking::begin_panic<rustc_errors[5fcb1a1f56a762e6]::ExplicitBug>::{closure#0}, !>
  14:     0x7f8ec1726bd6 - std[306a94a967d8f5ee]::panicking::begin_panic::<rustc_errors[5fcb1a1f56a762e6]::ExplicitBug>
  15:     0x7f8ec1742d96 - std[306a94a967d8f5ee]::panic::panic_any::<rustc_errors[5fcb1a1f56a762e6]::ExplicitBug>
  16:     0x7f8ec1742531 - <rustc_errors[5fcb1a1f56a762e6]::HandlerInner>::span_bug::<rustc_span[721a57c036170ce]::span_encoding::Span, &alloc[6d6f83537459af52]::string::String>
  17:     0x7f8ec1741d90 - <rustc_errors[5fcb1a1f56a762e6]::Handler>::span_bug::<rustc_span[721a57c036170ce]::span_encoding::Span, &alloc[6d6f83537459af52]::string::String>
  18:     0x7f8ec172e888 - rustc_middle[b6cf56a787d1e2a1]::ty::context::tls::with_opt::<rustc_middle[b6cf56a787d1e2a1]::util::bug::opt_span_bug_fmt<rustc_span[721a57c036170ce]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f8ec172e726 - rustc_middle[b6cf56a787d1e2a1]::util::bug::opt_span_bug_fmt::<rustc_span[721a57c036170ce]::span_encoding::Span>
  20:     0x7f8ec0167d04 - rustc_middle[b6cf56a787d1e2a1]::util::bug::span_bug_fmt::<rustc_span[721a57c036170ce]::span_encoding::Span>
  21:     0x7f8ec17377a1 - <rustc_codegen_llvm[3e0bcdafb62c313]::context::CodegenCx as rustc_middle[b6cf56a787d1e2a1]::ty::layout::LayoutOfHelpers>::handle_layout_err
  22:     0x7f8ec1731721 - <rustc_codegen_llvm[3e0bcdafb62c313]::context::CodegenCx as rustc_middle[b6cf56a787d1e2a1]::ty::layout::LayoutOf>::spanned_layout_of::{closure#0}
  23:     0x7f8ec01813be - rustc_codegen_ssa[5936c3af92679481]::mir::analyze::non_ssa_locals::<rustc_codegen_llvm[3e0bcdafb62c313]::builder::Builder>
  24:     0x7f8ec014d8bd - rustc_codegen_ssa[5936c3af92679481]::mir::codegen_mir::<rustc_codegen_llvm[3e0bcdafb62c313]::builder::Builder>
  25:     0x7f8ec105bf23 - rustc_codegen_llvm[3e0bcdafb62c313]::base::compile_codegen_unit::module_codegen
  26:     0x7f8ec0b23b19 - <rustc_query_system[8caf4755e287670e]::dep_graph::graph::DepGraph<rustc_middle[b6cf56a787d1e2a1]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[b6cf56a787d1e2a1]::ty::context::TyCtxt, rustc_span[721a57c036170ce]::symbol::Symbol, rustc_codegen_ssa[5936c3af92679481]::ModuleCodegen<rustc_codegen_llvm[3e0bcdafb62c313]::ModuleLlvm>>
  27:     0x7f8ec0b224b9 - rustc_codegen_llvm[3e0bcdafb62c313]::base::compile_codegen_unit
  28:     0x7f8ec0b20ace - <rustc_codegen_llvm[3e0bcdafb62c313]::LlvmCodegenBackend as rustc_codegen_ssa[5936c3af92679481]::traits::backend::CodegenBackend>::codegen_crate
  29:     0x7f8ec0dc5bac - <rustc_session[98f7faf1d37bb5fb]::session::Session>::time::<alloc[6d6f83537459af52]::boxed::Box<dyn core[6fcc70bcc91a5bf5]::any::Any>, rustc_interface[f934826ba4c12dd9]::passes::start_codegen::{closure#0}>
  30:     0x7f8ec0dc53b3 - <rustc_interface[f934826ba4c12dd9]::passes::QueryContext>::enter::<<rustc_interface[f934826ba4c12dd9]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[6fcc70bcc91a5bf5]::result::Result<alloc[6d6f83537459af52]::boxed::Box<dyn core[6fcc70bcc91a5bf5]::any::Any>, rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>>
  31:     0x7f8ec0dbda0f - <rustc_interface[f934826ba4c12dd9]::queries::Queries>::ongoing_codegen
  32:     0x7f8ec0dbc9b2 - <rustc_interface[f934826ba4c12dd9]::interface::Compiler>::enter::<rustc_driver[4568cc0a685fd94d]::run_compiler::{closure#1}::{closure#2}, core[6fcc70bcc91a5bf5]::result::Result<core[6fcc70bcc91a5bf5]::option::Option<rustc_interface[f934826ba4c12dd9]::queries::Linker>, rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>>
  33:     0x7f8ec0db186a - rustc_span[721a57c036170ce]::with_source_map::<core[6fcc70bcc91a5bf5]::result::Result<(), rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>, rustc_interface[f934826ba4c12dd9]::interface::create_compiler_and_run<core[6fcc70bcc91a5bf5]::result::Result<(), rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>, rustc_driver[4568cc0a685fd94d]::run_compiler::{closure#1}>::{closure#1}>
  34:     0x7f8ec0db11a2 - <scoped_tls[80743de900a7f844]::ScopedKey<rustc_span[721a57c036170ce]::SessionGlobals>>::set::<rustc_interface[f934826ba4c12dd9]::interface::run_compiler<core[6fcc70bcc91a5bf5]::result::Result<(), rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>, rustc_driver[4568cc0a685fd94d]::run_compiler::{closure#1}>::{closure#0}, core[6fcc70bcc91a5bf5]::result::Result<(), rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>>
  35:     0x7f8ec0daf5cf - std[306a94a967d8f5ee]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[f934826ba4c12dd9]::util::run_in_thread_pool_with_globals<rustc_interface[f934826ba4c12dd9]::interface::run_compiler<core[6fcc70bcc91a5bf5]::result::Result<(), rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>, rustc_driver[4568cc0a685fd94d]::run_compiler::{closure#1}>::{closure#0}, core[6fcc70bcc91a5bf5]::result::Result<(), rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>>::{closure#0}, core[6fcc70bcc91a5bf5]::result::Result<(), rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>>
  36:     0x7f8ec14690b9 - <<std[306a94a967d8f5ee]::thread::Builder>::spawn_unchecked_<rustc_interface[f934826ba4c12dd9]::util::run_in_thread_pool_with_globals<rustc_interface[f934826ba4c12dd9]::interface::run_compiler<core[6fcc70bcc91a5bf5]::result::Result<(), rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>, rustc_driver[4568cc0a685fd94d]::run_compiler::{closure#1}>::{closure#0}, core[6fcc70bcc91a5bf5]::result::Result<(), rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>>::{closure#0}, core[6fcc70bcc91a5bf5]::result::Result<(), rustc_errors[5fcb1a1f56a762e6]::ErrorGuaranteed>>::{closure#1} as core[6fcc70bcc91a5bf5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  37:     0x7f8ec2bc6723 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h56d5fc072706762b
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/alloc/src/boxed.rs:1935:9
  38:     0x7f8ec2bc6723 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h41deef8e33b824bb
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/alloc/src/boxed.rs:1935:9
  39:     0x7f8ec2bc6723 - std::sys::unix::thread::Thread::new::thread_start::ha6436304a1170bba
                               at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys/unix/thread.rs:108:17
  40:     0x7f8ebea9f822 - start_thread
  41:     0x7f8ebea3f450 - clone3
  42:                0x0 - <unknown>

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.64.0 (a55dd71d5 2022-09-19) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C codegen-units=1 -C embed-bitcode=no

query stack during panic:
end of query stack
error: aborting due to previous error

Couldn't compile the test.

failures:
    src/lib.rs - (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s

error: test failed, to rerun pass '--doc'
```

</p>
</details>