
Description
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>