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

Compiler panics when creating a trait object for a trait which uses generic_associated_types #76535

Closed
ghost opened this issue Sep 9, 2020 · 2 comments · Fixed by #79554
Closed
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 glacier ICE tracked in rust-lang/glacier. 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

@ghost
Copy link

ghost commented Sep 9, 2020

I think the trait object isn't aware of the parameters in the associated type, so it ends up with a different number of parameters than it should.

Code

main.rs:

#![feature(generic_associated_types)]

pub trait SubTrait {}

pub trait SuperTrait {
    type SubType<'a>: SubTrait;

    fn get_sub<'a>(&'a mut self) -> Self::SubType<'a>;
}

pub struct SubStruct<'a> {
    sup: &'a mut SuperStruct,
}

impl<'a> SubTrait for SubStruct<'a> {}

pub struct SuperStruct {
    value: u8,
}

impl SuperStruct {
    pub fn new(value: u8) -> SuperStruct {
        SuperStruct { value }
    }
}

impl SuperTrait for SuperStruct {
    type SubType<'a> = SubStruct<'a>;

    fn get_sub<'a>(&'a mut self) -> Self::SubType<'a> {
        SubStruct { sup: self }
    }
}

fn main() {
    let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
}

Meta

rustc --version --verbose:

rustc 1.47.0-nightly (8e21bd063 2020-08-14)
binary: rustc
commit-hash: 8e21bd0633b8d970646ee6eb706c9e8acfad19af
commit-date: 2020-08-14
host: x86_64-unknown-linux-gnu
release: 1.47.0-nightly
LLVM version: 10.0

Error output

warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(generic_associated_types)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

warning: unused variable: `sub`
  --> src/main.rs:36:9
   |
36 |     let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
   |         ^^^ help: if this is intentional, prefix it with an underscore: `_sub`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: field is never read: `sup`
  --> src/main.rs:12:5
   |
12 |     sup: &'a mut SuperStruct,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: field is never read: `value`
  --> src/main.rs:18:5
   |
18 |     value: u8,
   |     ^^^^^^^^^

warning: Error finalizing incremental compilation session directory `/home/alex/Documents/Development/ice_minimal/target/debug/incremental/ice_minimal-12sq6hsbdt9f2/s-fr1eb3vgke-1vvozop-working`: No such file or directory (os error 2)

warning: 5 warnings emitted

error: internal compiler error: impl item and trait item have different parameter counts
  |
  = note: delayed at /rustc/8e21bd0633b8d970646ee6eb706c9e8acfad19af/src/librustc_session/session.rs:441:27

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at /rustc/8e21bd0633b8d970646ee6eb706c9e8acfad19af/src/librustc_session/session.rs:441:27

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.47.0-nightly (8e21bd063 2020-08-14) running on x86_64-unknown-linux-gnu

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

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

error: could not compile `ice_minimal`.

To learn more, run the command again with --verbose.
Backtrace

```warning: the feature generic_associated_types is incomplete and may not be safe to use and/or cause compiler crashes
--> src/main.rs:1:12
|
1 | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44265 #44265 for more information

warning: unused variable: sub
--> src/main.rs:36:9
|
36 | let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
| ^^^ help: if this is intentional, prefix it with an underscore: _sub
|
= note: #[warn(unused_variables)] on by default

warning: field is never read: sup
--> src/main.rs:12:5
|
12 | sup: &'a mut SuperStruct,
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default

warning: field is never read: value
--> src/main.rs:18:5
|
18 | value: u8,
| ^^^^^^^^^

warning: Error finalizing incremental compilation session directory /home/alex/Documents/Development/ice_minimal/target/debug/incremental/ice_minimal-12sq6hsbdt9f2/s-fr1ebr4tpj-1habbbz-working: No such file or directory (os error 2)

warning: 5 warnings emitted

error: internal compiler error: impl item and trait item have different parameter counts
|
= note: delayed at /rustc/8e21bd0633b8d970646ee6eb706c9e8acfad19af/src/librustc_session/session.rs:441:27

error: internal compiler error: TyKind::Error constructed but no error reported
|
= note: delayed at /rustc/8e21bd0633b8d970646ee6eb706c9e8acfad19af/src/librustc_session/session.rs:441:27

thread 'rustc' panicked at 'no errors encountered even though delay_span_bug issued', src/librustc_errors/lib.rs:366:17
stack backtrace:
0: std::panicking::begin_panic
1: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
2: core::ptr::drop_in_place
3: <alloc::rc::Rc as core::ops::drop::Drop>::drop
4: core::ptr::drop_in_place
5: rustc_span::with_source_map
6: rustc_interface::interface::create_compiler_and_run
7: rustc_span::with_session_globals
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

error: internal compiler error: unexpected panic

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.47.0-nightly (8e21bd0 2020-08-14) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
end of query stack
error: could not compile ice_minimal.

To learn more, run the command again with --verbose.


</p>
</details>

@ghost ghost 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 Sep 9, 2020
@jonas-schievink jonas-schievink added the F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs label Sep 9, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Sep 24, 2020
@matthiaskrgr
Copy link
Member

Might be caused by 08e2d46 (When I check the code without the feature flag, rustc panics on the code since that commit)

@nikomatsakis
Copy link
Contributor

Might be fixed by #79554

m-ou-se added a commit to m-ou-se/rust that referenced this issue Feb 5, 2021
…-trait-paths, r=jackh726

Generic associated types in trait paths

This is the second part of rust-lang#78978

This should fix:

Fixes rust-lang#67510
Fixes rust-lang#68648
Fixes rust-lang#68649
Fixes rust-lang#68650
Fixes rust-lang#68652
Fixes rust-lang#74684
Fixes rust-lang#76535
Fixes rust-lang#79422
Fixes rust-lang#80433

and implement the remaining functionality needed for rust-lang#44265

r? `@matthewjasper`
@bors bors closed this as completed in deec6a9 Feb 5, 2021
@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 glacier ICE tracked in rust-lang/glacier. 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
Development

Successfully merging a pull request may close this issue.

5 participants