rust-lang/rust

[ICE]: rustdoc: `unexpected const parent in type_of(): TraitRef ..`

matthiaskrgr opened this issue · 3 comments

Code

use std::ops::Generator;

fn gen() -> impl Generator<{}> {}

Affected release channels

  • Previous Stable
  • Current Stable
  • Current Beta
  • Current Nightly

Rust Version

rustc 1.68.0-nightly (333ee6c46 2023-01-18)
binary: rustc
commit-hash: 333ee6c466972185973d5097f8b5fb0f9fb13fa5
commit-date: 2023-01-18
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6

Current error output

No response

Backtrace

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: unexpected const parent in type_of(): TraitRef(TraitRef { path: Path { span: a.rs:3:18: 3:31 (#0), res: Def(Trait, DefId(2:2969 ~ core[830d]::ops::generator::Generator)), segments: [PathSegment { ident: Generator#0, hir_id: HirId(DefId(0:6 ~ a[6282]::gen::{opaque#0}).4), res: Def(Trait, DefId(2:2969 ~ core[830d]::ops::generator::Generator)), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId(DefId(0:6 ~ a[6282]::gen::{opaque#0}).1), def_id: DefId(0:5 ~ a[6282]::gen::{constant#0}), body: BodyId { hir_id: HirId(DefId(0:6 ~ a[6282]::gen::{opaque#0}).2) } }, span: a.rs:3:28: 3:30 (#0) })], bindings: [], parenthesized: false, span_ext: a.rs:3:27: 3:31 (#0) }), infer_args: false }] }, hir_ref_id: HirId(DefId(0:6 ~ a[6282]::gen::{opaque#0}).5) })
  |
  = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
             1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
             2: <rustc_middle::ty::context::TyCtxt>::ty_error_with_message::<rustc_span::span_encoding::Span>
             3: rustc_hir_analysis::collect::type_of::type_of
             4: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::type_of, rustc_query_impl::plumbing::QueryCtxt, rustc_middle::dep_graph::dep_node::DepKind>
             5: rustdoc::clean::clean_const
             6: <core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_hir::hir::GenericArg>, rustdoc::clean::clean_generic_args::{closure#1}> as core::iter::traits::iterator::Iterator>::fold::<(), core::iter::traits::iterator::Iterator::for_each::call<rustdoc::clean::types::GenericArg, <alloc::vec::Vec<rustdoc::clean::types::GenericArg>>::extend_trusted<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_hir::hir::GenericArg>, rustdoc::clean::clean_generic_args::{closure#1}>>::{closure#0}>::{closure#0}>
             7: <alloc::vec::Vec<rustdoc::clean::types::GenericArg> as alloc::vec::spec_from_iter::SpecFromIter<rustdoc::clean::types::GenericArg, core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_hir::hir::GenericArg>, rustdoc::clean::clean_generic_args::{closure#1}>>>::from_iter
             8: rustdoc::clean::clean_generic_args
             9: <thin_vec::ThinVec<rustdoc::clean::types::PathSegment> as core::iter::traits::collect::FromIterator<rustdoc::clean::types::PathSegment>>::from_iter::<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_hir::hir::PathSegment>, rustdoc::clean::clean_path::{closure#0}>>
            10: rustdoc::clean::clean_poly_trait_ref
            11: rustdoc::clean::clean_generic_bound
            12: <alloc::vec::Vec<rustdoc::clean::types::GenericBound> as alloc::vec::spec_from_iter::SpecFromIter<rustdoc::clean::types::GenericBound, core::iter::adapters::filter_map::FilterMap<core::slice::iter::Iter<rustc_hir::hir::GenericBound>, rustdoc::clean::clean_trait_item::{closure#0}::{closure#1}>>>::from_iter
            13: rustdoc::clean::clean_ty
            14: rustdoc::clean::utils::enter_impl_trait::<rustdoc::clean::clean_function::{closure#0}, (rustdoc::clean::types::Generics, rustdoc::clean::types::FnDecl)>
            15: rustdoc::clean::clean_fn_or_proc_macro
            16: <rustdoc::core::DocContext>::with_param_env::<alloc::vec::Vec<rustdoc::clean::types::Item>, rustdoc::clean::clean_maybe_renamed_item::{closure#1}>
            17: <&mut rustdoc::clean::clean_doc_module::{closure#2} as core::ops::function::FnOnce<(&(&rustc_hir::hir::Item, core::option::Option<rustc_span::symbol::Symbol>, core::option::Option<rustc_hir::hir_id::HirId>),)>>::call_once
            18: <alloc::vec::Vec<rustdoc::clean::types::Item> as alloc::vec::spec_extend::SpecExtend<rustdoc::clean::types::Item, core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<(&rustc_hir::hir::Item, core::option::Option<rustc_span::symbol::Symbol>, core::option::Option<rustc_hir::hir_id::HirId>)>, alloc::vec::Vec<rustdoc::clean::types::Item>, rustdoc::clean::clean_doc_module::{closure#2}>>>::spec_extend
            19: rustdoc::clean::clean_doc_module
            20: rustdoc::clean::utils::krate
            21: <rustc_session::session::Session>::time::<rustdoc::clean::types::Crate, rustdoc::core::run_global_ctxt::{closure#4}>
            22: rustdoc::core::run_global_ctxt
            23: <rustc_session::session::Session>::time::<(rustdoc::clean::types::Crate, rustdoc::config::RenderOptions, rustdoc::formats::cache::Cache), rustdoc::main_args::{closure#1}::{closure#0}::{closure#1}::{closure#0}>
            24: <rustc_interface::passes::QueryContext>::enter::<rustdoc::main_args::{closure#1}::{closure#0}::{closure#1}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            25: <rustc_interface::interface::Compiler>::enter::<rustdoc::main_args::{closure#1}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            26: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}::{closure#0}>
            27: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            28: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
            29: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            30: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/333ee6c466972185973d5097f8b5fb0f9fb13fa5/library/alloc/src/boxed.rs:1988:9
            31: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/333ee6c466972185973d5097f8b5fb0f9fb13fa5/library/alloc/src/boxed.rs:1988:9
            32: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/333ee6c466972185973d5097f8b5fb0f9fb13fa5/library/std/src/sys/unix/thread.rs:108:17
            33: <unknown>
            34: <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.68.0-nightly (333ee6c46 2023-01-18) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
thread panicked while panicking. aborting.
[2]    2838854 IOT instruction (core dumped)  rustdoc a.rs

Anything else?

No response

Hm, this has to do with the fact that we don't check well-formedness during rustdoc, even though we really should at least be checking that the code in question has the right substs and stuff...

So does rustdoc proceed with anything that can be parsed into HIR? cargo check rejects this with can't put a constant there.
What should the code do here in that case?.

  • Make a dummy type and proceed with dock gen anyway.
  • Actually run the type checking before generating docs.
  • error without ICE and just print some general error message.
  • Could also run the type check conditionality if something failed to type I guess and print the message from that.
fmease commented

This issue was fixed in #108576 but never closed. It now errors with:

error[E0747]: constant provided when a type was expected
 --> ice-107093.rs:3:28
  |
3 | fn gen() -> impl Generator<{}> {}
  |                            ^^

error: aborting due to previous error

I don't think that we need a regression test for this. The linked PR has added enough already.