Skip to content

"should not be mangling partially substituted polymorphic instance" with impl_trait_in_assoc_type #146514

@Jules-Bertholet

Description

@Jules-Bertholet

Code

(minimized from https://github.com/Jules-Bertholet/unsized-vec/blob/master/emplacable/src/lib.rs, can probably be minimized further)

#![feature(impl_trait_in_assoc_type)]

use core::marker::PhantomData;

struct Emplacable<T: ?Sized, F> {
    phantom: PhantomData<(*const T, F)>,
}

impl<T: ?Sized, F> Emplacable<T, F> {
    fn from_fn(_: F) -> Self {
        Emplacable {
            phantom: PhantomData,
        }
    }

    fn unsize<U: ?Sized>(self) -> Emplacable<U, impl Sized> {
        Emplacable::from_fn(|| ())
    }
}

trait IntoEmplacable<T: ?Sized> {
    type Closure;

    fn into_emplacable(self) -> Emplacable<T, Self::Closure>;
}

impl<const N: usize, F> IntoEmplacable<[()]> for Emplacable<[(); N], F> {
    type Closure = impl Sized;

    fn into_emplacable(self) -> Emplacable<[()], Self::Closure> {
        self.unsize()
    }
}

impl<F> From<Emplacable<[(); 0], F>>
    for Emplacable<[()], <Emplacable<[(); 0], F> as IntoEmplacable<[()]>>::Closure>
{
    fn from(value: Emplacable<[(); 0], F>) -> Self {
        <Emplacable<[(); 0], F> as IntoEmplacable<[()]>>::into_emplacable(value)
    }
}

fn box_new_with<T: ?Sized>(_: Emplacable<T, impl Sized>) -> Box<T> {
    loop {}
}

pub fn foo() {
    let e: Emplacable<[(); 0], ()> = Emplacable {
        phantom: PhantomData,
    };
    let _: Box<[()]> = box_new_with(e.into());
}

Meta

cargo bisect-rustc

searched toolchains nightly-2025-01-02 through nightly-2025-02-15

Regression in nightly-2025-01-10

get_commits_between returning commits, len: 7

Error output

Backtrace

thread 'rustc' (29529) panicked at compiler/rustc_symbol_mangling/src/legacy.rs:437:13:
should not be mangling partially substituted polymorphic instance: DefId(0:8 ~ scratch[7233]::{impl#0}) [[(); 0_usize], F/#0]
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_symbol_mangling::legacy::LegacySymbolMangler as rustc_middle::ty::print::Printer>::default_print_def_path
   3: <rustc_symbol_mangling::legacy::LegacySymbolMangler as rustc_middle::ty::print::Printer>::default_print_def_path
   4: <rustc_symbol_mangling::legacy::LegacySymbolMangler as rustc_middle::ty::print::Printer>::default_print_def_path
   5: <rustc_symbol_mangling::legacy::LegacySymbolMangler as rustc_middle::ty::print::Printer>::default_print_def_path
   6: <rustc_symbol_mangling::legacy::LegacySymbolMangler as rustc_middle::ty::print::Printer>::default_print_def_path
   7: <rustc_symbol_mangling::legacy::LegacySymbolMangler as rustc_middle::ty::print::pretty::PrettyPrinter>::pretty_print_type
   8: <rustc_symbol_mangling::legacy::LegacySymbolMangler as rustc_middle::ty::print::Printer>::default_print_def_path
   9: <rustc_symbol_mangling::legacy::LegacySymbolMangler as rustc_middle::ty::print::Printer>::default_print_def_path
  10: rustc_symbol_mangling::legacy::mangle
  11: rustc_symbol_mangling::symbol_name_provider
      [... omitted 1 frame ...]
  12: rustc_monomorphize::partitioning::assert_symbols_are_distinct::<core::slice::iter::Iter<rustc_middle::mir::mono::MonoItem>>
  13: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 2 frames ...]
  14: rustc_codegen_ssa::back::symbol_export::exported_generic_symbols_provider_local
      [... omitted 2 frames ...]
  15: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  16: <rustc_metadata::rmeta::encoder::encode_metadata::{closure#3} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, &std::path::Path)>>::call_once
  17: <rustc_middle::dep_graph::DepsType as rustc_query_system::dep_graph::Deps>::with_deps::<<rustc_query_system::dep_graph::graph::DepGraphData<rustc_middle::dep_graph::DepsType>>::with_task<rustc_middle::ty::context::TyCtxt, &std::path::Path, ()>::{closure#1}::{closure#0}, ()>
  18: rustc_metadata::rmeta::encoder::encode_metadata
  19: rustc_metadata::fs::encode_and_write_metadata
  20: <rustc_interface::queries::Linker>::codegen_and_build_linker
  21: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  22: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: 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: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/julesbertholet/git/scratch/rustc-ice-2025-09-13T15_37_45-29527.txt` to your bug report

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C linker=clang -C incremental=[REDACTED] -C link-arg=-fuse-ld=/usr/bin/mold

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [symbol_name] computing the symbol for `<impl at src/lib.rs:35:1: 36:84>::from`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
#2 [exported_generic_symbols] collecting exported generic symbols for crate `0`
end of query stack

@rustbot label T-types requires-nightly F-impl_trait_in_assoc_type

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-impl_trait_in_assoc_type`#![feature(impl_trait_in_assoc_type)]`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.T-typesRelevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions