Skip to content

ICE with generic associated types + higher ranked trait bounds #102899

Closed
@kawogi

Description

@kawogi

Got this while trying to implement a GAT and higher ranked trait bounds. The code is likely flawed because I was in the middle of a refactoring.

Code

pub trait BufferTrait<'buffer> {
    type Subset<'channel>
    where
        'buffer: 'channel;

    fn for_each_subset<F>(&self, f: F)
    where
        F: for<'channel> Fn(Self::Subset<'channel>);
}

pub struct SomeBuffer<'buffer> {
    samples: &'buffer [()],
}

impl<'buffer> BufferTrait<'buffer> for SomeBuffer<'buffer> {
    type Subset<'subset> = Subset<'subset> where 'buffer: 'subset;

    fn for_each_subset<F>(&self, _f: F)
    where
        F: for<'subset> Fn(Subset<'subset>),
    {
        todo!()
    }
}

pub struct Subset<'subset> {
    buffer: &'subset [()],
}

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (81f391930 2022-10-09)
binary: rustc
commit-hash: 81f391930301afbc121b7c468138069daa354bf8
commit-date: 2022-10-09
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2

Error output

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

error: internal compiler error: failed region resolution while normalizing ParamEnv { caller_bounds: [Binder(ProjectionPredicate(ProjectionTy { substs: [F, (<SomeBuffer<'buffer> as BufferTrait<'buffer>>::Subset<'channel>,)], item_def_id: DefId(2:3645 ~ core[2f45]::ops::function::FnOnce::Output) }, Term::Ty(())), [Region(BrNamed(DefId(0:9 ~ raw_sample[811b]::BufferTrait::for_each_subset::'channel), 'channel))]), Binder(TraitPredicate(<F as std::ops::Fn<(<SomeBuffer<'buffer> as BufferTrait<'buffer>>::Subset<'channel>,)>>, polarity:Positive), [Region(BrNamed(DefId(0:9 ~ raw_sample[811b]::BufferTrait::for_each_subset::'channel), 'channel))]), Binder(TraitPredicate(<F as std::ops::FnMut<(<SomeBuffer<'buffer> as BufferTrait<'buffer>>::Subset<'channel>,)>>, polarity:Positive), [Region(BrNamed(DefId(0:9 ~ raw_sample[811b]::BufferTrait::for_each_subset::'channel), 'channel))]), Binder(TraitPredicate(<F as std::ops::FnOnce<(<SomeBuffer<'buffer> as BufferTrait<'buffer>>::Subset<'channel>,)>>, polarity:Positive), [Region(BrNamed(DefId(0:9 ~ raw_sample[811b]::BufferTrait::for_each_subset::'channel), 'channel))]), Binder(TraitPredicate(<F as std::marker::Sized>, polarity:Positive), [])], reveal: UserFacing, constness: NotConst }: [ConcreteFailure(RelateRegionParamBound(src/main.rs:22:5: 24:45 (#0)), RePlaceholder(Placeholder { universe: U1, name: BrNamed(DefId(0:9 ~ raw_sample[811b]::BufferTrait::for_each_subset::'channel), 'channel) }), ReEarlyBound(0, 'buffer)), ConcreteFailure(RelateRegionParamBound(src/main.rs:22:5: 24:45 (#0)), RePlaceholder(Placeholder { universe: U2, name: BrNamed(DefId(0:9 ~ raw_sample[811b]::BufferTrait::for_each_subset::'channel), 'channel) }), ReEarlyBound(0, 'buffer)), ConcreteFailure(RelateRegionParamBound(src/main.rs:22:5: 24:45 (#0)), RePlaceholder(Placeholder { universe: U3, name: BrNamed(DefId(0:9 ~ raw_sample[811b]::BufferTrait::for_each_subset::'channel), 'channel) }), ReEarlyBound(0, 'buffer)), ConcreteFailure(RelateRegionParamBound(src/main.rs:22:5: 24:45 (#0)), RePlaceholder(Placeholder { universe: U4, name: BrNamed(DefId(0:9 ~ raw_sample[811b]::BufferTrait::for_each_subset::'channel), 'channel) }), ReEarlyBound(0, 'buffer))]
  --> src/main.rs:22:5
   |
22 | /     fn for_each_subset<F>(&self, _f: F)
23 | |     where
24 | |         F: for<'subset> Fn(Subset<'subset>),
   | |____________________________________________^
   |
   = note: delayed at compiler/rustc_trait_selection/src/traits/mod.rs:257:18
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1537:13
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::flush_delayed::<alloc::vec::Vec<rustc_errors::diagnostic::Diagnostic>, &str>
   3: <rustc_errors::Handler>::flush_delayed
   4: <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>>
   5: <rustc_interface::queries::Queries>::ongoing_codegen
   6: <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>>
   7: 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}>
   8: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
   9: <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.66.0-nightly (81f391930 2022-10-09) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)C-bugCategory: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATsI-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