Skip to content

ICE when using "Generic Associated Types" feature with references for impl block #80433

Closed

Description

@rxcompile

Code

#![allow(incomplete_features)]
#![feature(generic_associated_types)]

#[derive(Default)]
struct E<T> {
    data: T,
}

trait TestMut {
    type Output<'a>;
    fn test_mut<'a>(&'a mut self) -> Self::Output<'a>;
}

impl<T> TestMut for E<T>
where
    T: 'static,
{
    type Output<'a> = &'a mut T;
    fn test_mut<'a>(&'a mut self) -> Self::Output<'a> {
        &mut self.data
    }
}

fn test_simpler<'a>(dst: &'a mut impl TestMut<Output = &'a mut f32>)
{
    for n in 0i16..100 {
        *dst.test_mut() = n.into();
    }
}

fn main() {
    let mut t1: E<f32> = Default::default();
    test_simpler(&mut t1);
}

Meta

rustc --version --verbose:

rustc 1.50.0-nightly (bb178237c 2020-12-25)
binary: rustc
commit-hash: bb178237c5539c75e1b85ab78a8ab902b1f333d5
commit-date: 2020-12-25
host: x86_64-apple-darwin
release: 1.50.0-nightly

Error output

error: internal compiler error: impl item and trait item have different parameter counts
  --> src/main.rs:33:5
   |
33 |     test_simpler(&mut t1);
   |     ^^^^^^^^^^^^
   |
   = note: delayed at compiler/rustc_trait_selection/src/traits/project.rs:1418:23

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at /rustc/bb178237c5539c75e1b85ab78a8ab902b1f333d5/compiler/rustc_middle/src/ty/relate.rs:347:59

error: internal compiler error: impl item and trait item have different parameter counts
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/project.rs:1418:23

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:974:13
Backtrace

   0:        0x1107200dc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha6f5ddd5259d3e16
   1:        0x110784c8d - core::fmt::write::hefe95a44532fe6ed
   2:        0x110711e86 - std::io::Write::write_fmt::hf513c99961415bff
   3:        0x110723d89 - std::panicking::default_hook::{{closure}}::h70a3a940826edea5
   4:        0x110723910 - std::panicking::default_hook::h9520f36dd50be056
   5:        0x108cb1458 - rustc_driver::report_ice::h64178aa7cd01307c
   6:        0x11072456e - std::panicking::rust_panic_with_hook::h102f8bee4e0ef4c7
   7:        0x110724075 - std::panicking::begin_panic_handler::{{closure}}::hb72eee9aad2e147c
   8:        0x110720598 - std::sys_common::backtrace::__rust_end_short_backtrace::h372ff87ecb2667f3
   9:        0x110723fda - _rust_begin_unwind
  10:        0x1107ab27b - std::panicking::begin_panic_fmt::hf0e714fa3e981e6e
  11:        0x10d3472a6 - rustc_errors::HandlerInner::flush_delayed::he9da53448a9bd660
  12:        0x10d3434eb - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h44af1dc5df0a1fa4
  13:        0x108ccba5a - core::ptr::drop_in_place::hd03156b954b70984
  14:        0x108ccefb8 - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::hd4c9eabf652375d9
  15:        0x108cc8112 - core::ptr::drop_in_place::h83698f86dd7e4a49
  16:        0x108cb3ab1 - rustc_span::with_source_map::hb3cfcc431ed11000
  17:        0x108ce7694 - rustc_interface::interface::create_compiler_and_run::he8e7b2281c1964ad
  18:        0x108cbff94 - std::sys_common::backtrace::__rust_begin_short_backtrace::h9bf0a320b59d4a76
  19:        0x108c56799 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hb43737fa064e4b63
  20:        0x11073150d - std::sys::unix::thread::Thread::new::thread_start::h93dd3097fa4fa219
  21:     0x7fff20358950 - __pthread_start

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 Dec 28, 2020
  2. changed the title [-]ICE when using "Generic Assotiated Types" feature with mutable borrows[/-] [+]ICE when using "Generic Assotiated Types" feature with mutable references[/+] on Dec 28, 2020
  3. changed the title [-]ICE when using "Generic Assotiated Types" feature with mutable references[/-] [+]ICE when using "Generic Associated Types" feature with mutable references[/+] on Dec 28, 2020
  4. changed the title [-]ICE when using "Generic Associated Types" feature with mutable references[/-] [+]ICE when using "Generic Associated Types" feature with references for impl block[/+] on Dec 28, 2020
  5. fanninpm commented on Dec 29, 2020

    @fanninpm
    Contributor
  6. added a commit that references this issue on Dec 29, 2020
  7. jyn514 commented on Dec 29, 2020

    @jyn514
    Member

    Slightly smaller:

    #![allow(incomplete_features)]
    #![feature(generic_associated_types)]
    
    struct E {}
    
    trait TestMut {
        type Output<'a>;
        fn test_mut(&mut self) -> Self::Output<'static>;
    }
    
    impl TestMut for E {
        type Output<'a> = usize;
        fn test_mut(&mut self) -> Self::Output<'static> {
            todo!()
        }
    }
    
    fn test_simpler(_: impl TestMut<Output = usize>) {}
    
    fn main() {
        test_simpler(E {});
    }

    Playground

  8. added
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Dec 29, 2020
  9. b-naber commented on Jan 10, 2021

    @b-naber
    Contributor

    This should work once #79554 lands using fn test_simpler<'a>(dst: &'a mut impl TestMut<Output<'a> = &'a mut f32>)

  10. b-naber commented on Feb 3, 2021

    @b-naber
    Contributor

    There's another error in @rxcompile 's code, you mutably borrow in the loop, you might be able to fix this if you re-borrow.

  11. added 2 commits that reference this issue on Feb 5, 2021
    9096865
    deec6a9
  12. added
    A-GATsArea: Generic associated types (GATs)
    on Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions