Skip to content

ICE (failed to get layout for [type error]) when attempting to doc-test an internal struct of rustfmt #103027

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
anforowicz opened this issue Oct 13, 2022 · 1 comment
Labels
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.

Comments

@anforowicz
Copy link
Contributor

Code

To repro, try the following steps:

  1. Get a local copy of https://github.com/rust-lang/rustfmt.git
  2. Apply the patch from https://github.com/anforowicz/rustfmt/tree/doc-test-ice-repro (see the git diff output below)
  3. Run cargo test against rustfmt

I haven't yet tried minimizing this example, because it seems that part of the repro may require depending on the internal rustc_foo crates (like rustfmt does AFAIU). At least the following does not repro the problem:

$ cat src/lib.rs
struct SomeStruct(i32);

impl SomeStruct {
    /// ```
    /// use ice_20221013::SomeStruct;
    /// SomeStruct::foo();
    /// ```
    fn foo() {
    }
}

$ cargo test
...
error[E0603]: struct `SomeStruct` is private
...

Meta

rustc --version --verbose:

rustc 1.64.0-nightly (affe0d3a0 2022-08-05)
binary: rustc
commit-hash: affe0d3a00e92fa7885e3f5d2c5073fde432d154
commit-date: 2022-08-05
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6

I've tried to see if the ICE also repros on a more recent nightly, but with rustc 1.66.0-nightly (c0983a9aa 2022-10-12) I've hit much earlier, different errors when running cargo test against rustfmt.

Error output

$ cd ~/src/github/rustfmt
$ git diff fork/master
diff --git a/src/comment.rs b/src/comment.rs
index 4d565afc..32e1e57b 100644
--- a/src/comment.rs
+++ b/src/comment.rs
@@ -417,6 +417,12 @@ impl CodeBlockAttribute {
     /// Parse comma separated attributes list. Return rust only if all
     /// attributes are valid rust attributes
     /// See <https://doc.rust-lang.org/rustdoc/print.html#attributes>
+    ///
+    /// Example:
+    /// ```
+    /// use rustfmt::comment::CodeBlockAttribute;
+    /// let _ = CodeBlockAttribute::new("rust");
+    /// ```
     fn new(attributes: &str) -> CodeBlockAttribute {
         for attribute in attributes.split(',') {
             match attribute.trim() {

$ RUST_BACKTRACE=1 cargo test
...

   Doc-tests rustfmt-nightly

running 3 tests
test src/comment.rs - comment::CodeBlockAttribute::new (line 422) ... FAILED
test src/utils.rs - utils::trim_left_preserve_layout (line 560) - compile fail ... ok
test src/utils.rs - utils::trim_left_preserve_layout (line 546) - compile fail ... ok

failures:

---- src/comment.rs - comment::CodeBlockAttribute::new (line 422) 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/comment.rs:422:38
  |
2 | fn main() { #[allow(non_snake_case)] fn _doctest_main_src_comment_rs_422_0() {
  |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/affe0d3a00e92fa7885e3f5d2c5073fde432d154/compiler/rustc_errors/src/lib.rs:1332:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::span_bug::<rustc_span::span_encoding::Span, &alloc::string::String>
   3: <rustc_errors::Handler>::span_bug::<rustc_span::span_encoding::Span, &alloc::string::String>
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_codegen_llvm::context::CodegenCx as rustc_middle::ty::layout::LayoutOfHelpers>::handle_layout_err
   8: <rustc_codegen_llvm::context::CodegenCx as rustc_middle::ty::layout::LayoutOf>::spanned_layout_of::{closure#0}
   9: <core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::mir::LocalDecl>, rustc_codegen_ssa::mir::analyze::non_ssa_locals<rustc_codegen_llvm::builder::Builder>::{closure#0}> as core::iter::traits::iterator::Iterator>::fold::<(), core::iter::traits::iterator::Iterator::for_each::call<rustc_codegen_ssa::mir::analyze::LocalKind, <alloc::vec::Vec<rustc_codegen_ssa::mir::analyze::LocalKind> as alloc::vec::spec_extend::SpecExtend<rustc_codegen_ssa::mir::analyze::LocalKind, core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::mir::LocalDecl>, rustc_codegen_ssa::mir::analyze::non_ssa_locals<rustc_codegen_llvm::builder::Builder>::{closure#0}>>>::spec_extend::{closure#0}>::{closure#0}>
  10: rustc_codegen_ssa::mir::analyze::non_ssa_locals::<rustc_codegen_llvm::builder::Builder>
  11: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
  12: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  13: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::symbol::Symbol, rustc_codegen_ssa::ModuleCodegen<rustc_codegen_llvm::ModuleLlvm>>
  14: rustc_codegen_llvm::base::compile_codegen_unit
  15: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  16: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  17: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  18: <rustc_interface::passes::QueryContext>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_errors::ErrorGuaranteed>>
  19: <rustc_interface::queries::Queries>::ongoing_codegen
  20: <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::ErrorGuaranteed>>
  21: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  22: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  23: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
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.64.0-nightly (affe0d3a0 2022-08-05) 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/comment.rs - comment::CodeBlockAttribute::new (line 422)

test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s

error: test failed, to rerun pass '--doc'
@anforowicz anforowicz 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 Oct 13, 2022
@anforowicz anforowicz changed the title ICE when attempting to doc-test an internal struct of rustfmt ICE (failed to get layout for [type error]) when attempting to doc-test an internal struct of rustfmt Oct 13, 2022
@anforowicz
Copy link
Contributor Author

Ooops... I see that this is probably a duplicate of issue #102366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

No branches or pull requests

1 participant