Skip to content

rustdoc ICEs on free calls, method calls & type-relative paths in anon consts under --generate-link-to-definition #156418

@fmease

Description

@fmease

rustdoc "$FILE" --generate-link-to-definition -Zunstable-options:

fn scope() {
    struct X<const N: usize>;
    let _ = X::<{ std::convert::identity(0) }>;
}

rustdoc output (excerpt):

error: internal compiler error: `type_of` called on const argument's anon const before the const argument was lowered
 --> file.rs:3:17
  |
3 |     let _ = X::<{ std::convert::identity(0) }>;
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
rustdoc output (full)
note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: `type_of` called on const argument's anon const before the const argument was lowered
 --> file.rs:3:17
  |
3 |     let _ = X::<{ std::convert::identity(0) }>;
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: delayed at /rustc-dev/c935696dd07ca51e6fba2f6579919eea2a50863b/compiler/rustc_hir_analysis/src/collect/type_of.rs:398:14
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: rustc_hir_analysis::collect::type_of::type_of
         5: rustc_query_impl::query_impl::type_of::invoke_provider_fn::__rust_begin_short_backtrace
         6: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefIdCache<rustc_middle::query::erase::ErasedData<[u8; 8]>>, false>
         7: rustc_query_impl::query_impl::type_of::execute_query_non_incr::__rust_end_short_backtrace
         8: rustc_hir_typeck::typeck_with_inspect::{closure#0}
         9: rustc_hir_typeck::typeck_root
        10: <rustdoc::core::create_config::{closure#3}::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
        11: rustc_query_impl::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
        12: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 8]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        13: rustc_query_impl::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
        14: <rustc_middle::ty::context::TyCtxt>::typeck_body
        15: <rustdoc::html::render::span_map::SpanMapVisitor>::infer_id
        16: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_expr
        17: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_block
        18: rustc_hir::intravisit::walk_const_arg::<rustdoc::html::render::span_map::SpanMapVisitor>
        19: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_qpath
        20: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_block
        21: rustc_hir::intravisit::walk_item::<rustdoc::html::render::span_map::SpanMapVisitor>
        22: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_mod
        23: <rustdoc::html::render::context::Context>::init
        24: rustdoc::main_args::{closure#2}::{closure#0}
        25: rustc_interface::interface::run_compiler::<(), rustdoc::main_args::{closure#2}>::{closure#1}
        26: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustdoc::main_args::{closure#2}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        27: <std::thread::lifecycle::spawn_unchecked<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustdoc::main_args::{closure#2}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        28: <std::sys::thread::unix::Thread>::new::thread_start
        29: <unknown>
        30: <unknown>

 --> file.rs:3:17
  |
3 |     let _ = X::<{ std::convert::identity(0) }>;
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.97.0-nightly (c935696dd 2026-04-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options

query stack during panic:
end of query stack
fn scope() {
    struct X<const N: usize>;
    let _ = X::<{ 0usize.saturating_add(1) }>;
}

rustdoc output (excerpt):

error: internal compiler error: `type_of` called on const argument's anon const before the const argument was lowered
 --> file.rs:3:17
  |
3 |     let _ = X::<{ 0usize.saturating_add(1) }>;
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
rustdoc output (full)
note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: `type_of` called on const argument's anon const before the const argument was lowered
 --> file.rs:3:17
  |
3 |     let _ = X::<{ 0usize.saturating_add(1) }>;
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: delayed at /rustc-dev/c935696dd07ca51e6fba2f6579919eea2a50863b/compiler/rustc_hir_analysis/src/collect/type_of.rs:398:14
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: rustc_hir_analysis::collect::type_of::type_of
         5: rustc_query_impl::query_impl::type_of::invoke_provider_fn::__rust_begin_short_backtrace
         6: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefIdCache<rustc_middle::query::erase::ErasedData<[u8; 8]>>, false>
         7: rustc_query_impl::query_impl::type_of::execute_query_non_incr::__rust_end_short_backtrace
         8: rustc_hir_typeck::typeck_with_inspect::{closure#0}
         9: rustc_hir_typeck::typeck_root
        10: <rustdoc::core::create_config::{closure#3}::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
        11: rustc_query_impl::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
        12: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 8]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        13: rustc_query_impl::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
        14: <rustc_middle::ty::context::TyCtxt>::typeck_body
        15: <rustdoc::html::render::span_map::SpanMapVisitor>::infer_id
        16: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_expr
        17: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_block
        18: rustc_hir::intravisit::walk_const_arg::<rustdoc::html::render::span_map::SpanMapVisitor>
        19: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_qpath
        20: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_block
        21: rustc_hir::intravisit::walk_item::<rustdoc::html::render::span_map::SpanMapVisitor>
        22: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_mod
        23: <rustdoc::html::render::context::Context>::init
        24: rustdoc::main_args::{closure#2}::{closure#0}
        25: rustc_interface::interface::run_compiler::<(), rustdoc::main_args::{closure#2}>::{closure#1}
        26: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustdoc::main_args::{closure#2}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        27: <std::thread::lifecycle::spawn_unchecked<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustdoc::main_args::{closure#2}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        28: <std::sys::thread::unix::Thread>::new::thread_start
        29: <unknown>
        30: <unknown>

 --> file.rs:3:17
  |
3 |     let _ = X::<{ 0usize.saturating_add(1) }>;
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.97.0-nightly (c935696dd 2026-04-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options

query stack during panic:
end of query stack
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

trait Trait { const CT: usize; }

fn scope<T: Trait>() {
    struct X<const N: usize>;
    let _ = X::<{ T::CT }>;
}

rustdoc output (excerpt):

error: internal compiler error: `type_of` called on const argument's anon const before the const argument was lowered
 --> file.rs:8:17
  |
8 |     let _ = X::<{ T::CT }>;
  |                 ^^^^^^^^^
rustdoc output (full)
note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: `type_of` called on const argument's anon const before the const argument was lowered
 --> file.rs:8:17
  |
8 |     let _ = X::<{ T::CT }>;
  |                 ^^^^^^^^^
  |
note: delayed at /rustc-dev/c935696dd07ca51e6fba2f6579919eea2a50863b/compiler/rustc_hir_analysis/src/collect/type_of.rs:398:14
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: rustc_hir_analysis::collect::type_of::type_of
         5: rustc_query_impl::query_impl::type_of::invoke_provider_fn::__rust_begin_short_backtrace
         6: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefIdCache<rustc_middle::query::erase::ErasedData<[u8; 8]>>, false>
         7: rustc_query_impl::query_impl::type_of::execute_query_non_incr::__rust_end_short_backtrace
         8: rustc_hir_typeck::typeck_with_inspect::{closure#0}
         9: rustc_hir_typeck::typeck_root
        10: <rustdoc::core::create_config::{closure#3}::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
        11: rustc_query_impl::query_impl::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
        12: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 8]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        13: rustc_query_impl::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
        14: <rustc_middle::ty::context::TyCtxt>::typeck_body
        15: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_qpath
        16: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_block
        17: rustc_hir::intravisit::walk_const_arg::<rustdoc::html::render::span_map::SpanMapVisitor>
        18: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_qpath
        19: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_block
        20: rustc_hir::intravisit::walk_item::<rustdoc::html::render::span_map::SpanMapVisitor>
        21: <rustdoc::html::render::span_map::SpanMapVisitor as rustc_hir::intravisit::Visitor>::visit_mod
        22: <rustdoc::html::render::context::Context>::init
        23: rustdoc::main_args::{closure#2}::{closure#0}
        24: rustc_interface::interface::run_compiler::<(), rustdoc::main_args::{closure#2}>::{closure#1}
        25: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustdoc::main_args::{closure#2}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        26: <std::thread::lifecycle::spawn_unchecked<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustdoc::main_args::{closure#2}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        27: <std::sys::thread::unix::Thread>::new::thread_start
        28: <unknown>
        29: <unknown>

 --> file.rs:8:17
  |
8 |     let _ = X::<{ T::CT }>;
  |                 ^^^^^^^^^

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.97.0-nightly (c935696dd 2026-04-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options

query stack during panic:
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-link-to-definitionrustdoc --generate-link-to-definition nightly-only featureC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions