Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kawogi opened this issue Oct 10, 2022 · 1 comment · Fixed by #102945
Closed

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

kawogi opened this issue Oct 10, 2022 · 1 comment · Fixed by #102945
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kawogi
Copy link

kawogi commented Oct 10, 2022

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

@kawogi kawogi added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 10, 2022
@compiler-errors
Copy link
Member

I wonder if this is related to or a duplicate of #100689? It seems so, since @danielhenrymantilla's solution of replacing (in this case) 'buffer: 'channel with &'buffer (): 'channel seems to make the code compile.

@compiler-errors compiler-errors added the F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs label Oct 10, 2022
@bors bors closed this as completed in d02a221 Oct 17, 2022
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants