Skip to content

Crash of 1.76.0 compiler with generics #120922

Description

@kpouer

Code

Hey,I encountered a panic in the compiler version 1.76.0.
Using nightly 1.78.0 helps as it points the error in my code and do not crash the reason is that my first argument:
fn serialize_price_matrix<T, S>(_: &Vec<Vec>, serializer: S should be

fn serialize_price_matrix<T, S>(_: &T, serializer: S

12 |     #[serde(serialize_with = "serialize_price_matrix")]
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `serialize_price_matrix`
use serde::{Serialize, Serializer};

fn serialize_price_matrix<T, S>(_: &Vec<Vec<f64>>, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
    where
        S: Serializer,
{
    serializer.serialize_f64(0.0)
}

#[derive(Serialize)]
pub(crate) struct Matrix {
    #[serde(serialize_with = "serialize_price_matrix")]
    matrix: Vec<Vec<f64>>,
}

fn main() {
}

Meta

Using the stable version 1.76.0.

rustc --version --verbose:

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/typeck_results.rs:498:9: node HirId(DefId(0:14 ~ test_rust[7abd]::_::{impl#0}::serialize).40) (expr `Serialize`) cannot be placed in TypeckResults with hir_owner DefId(0:22 ~ test_rust[7abd]::_::{impl#0}::serialize::{impl#0}::serialize)
Backtrace

thread 'rustc' panicked at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/compiler/rustc_errors/src/lib.rs:1119:75:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic_builder::Bug as rustc_errors::diagnostic_builder::EmissionGuarantee>::diagnostic_builder_emit_producing_guarantee
   2: <rustc_errors::DiagCtxt>::bug::<alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: 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::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}, !>
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_middle::ty::typeck_results::invalid_hir_id_for_typeck_results
   8: <rustc_middle::ty::typeck_results::TypeckResults>::expr_ty
   9: rustc_hir_typeck::typeck
      [... omitted 1 frame ...]
  10: rustc_hir_analysis::check_crate
  11: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  12: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Feb 11, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 11, 2024
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 14, 2024
  4. jiker-burce commented on Mar 4, 2024

    @jiker-burce

    I encountered the same issue, I just rollback the version to 1.75.0, then it worked for every project.

  5. flokli commented on Apr 12, 2024

    @flokli

    You don't use T anywhere, do you? Does it work if you replace fn serialize_price_matrix<T, S> with fn serialize_price_matrix<S>?

  6. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Jun 3, 2025
  7. lsunsi commented on Aug 12, 2026

    @lsunsi
    Contributor

    @rustbot claim

  8. added a commit that references this issue on Aug 26, 2026
    e522309
  9. added a commit that references this issue on Aug 26, 2026
    bd37eaa
  10. added a commit that references this issue on Aug 27, 2026
    cddf60c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions