Closed
Description
Code
use std::marker::PhantomData;
#[derive(Default)]
struct MyType<'a> {
field: usize,
_phantom: PhantomData<&'a ()>,
}
#[derive(Default)]
struct MyTypeVariant<'a> {
field: usize,
_phantom: PhantomData<&'a ()>,
}
trait AsVariantTrait {
type Type;
}
impl <'a> AsVariantTrait for MyType<'a> {
type Type = MyTypeVariant<'a>;
}
type Variant<G> = <G as AsVariantTrait>::Type;
fn foo<T: Default, F: FnOnce(T)>(f: F) {
let input = T::default();
f(input);
}
fn main() {
foo(|a: Variant<MyType>| {
a.field;
});
}
The following causes the same ICE:
fn main() {
foo(|a: <MyType as AsVariantTrait>::Type| {
a.field;
});
}
This is a trivial example of using the direct type, just to prove that the type is well-formed -- this works:
fn main() {
foo(|a: MyTypeVariant| {
a.field;
});
}
This causes an ambiguous associated type
error:
fn main() {
foo(|a: MyType::Type| {
a.field;
});
}
error[[E0223]](https://doc.rust-lang.org/beta/error-index.html#E0223): ambiguous associated type
--> src/main.rs:31:13
|
31 | foo(|a: MyType::Type| {
| ^^^^^^^^^^^^ help: use fully-qualified syntax: `<MyType<'_> as Trait>::Type`
For more information about this error, try `rustc --explain E0223`.
Meta
rustc 1.63.0 (4b91a6ea7 2022-08-08) running on x86_64-unknown-linux-gnu
rustc 1.64.0-beta.6 (25912c097 2022-09-09) running on x86_64-unknown-linux-gnu
rustc 1.65.0-nightly (228710758 2022-09-10) running on x86_64-unknown-linux-gnu
Error output
error: internal compiler error: no errors encountered even though `delay_span_bug` issued
error: internal compiler error: broken MIR in DefId(0:17 ~ playground[da9a]::main::{closure#0}) ((_2.0: usize)): can't project out of PlaceTy { ty: <MyType<'_> as AsVariantTrait>::Type, variant_index: None }
--> src/main.rs:32:9
|
32 | a.field;
| ^^^^^^^
|
= note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:863:31
error: internal compiler error: TyKind::Error constructed but no error reported
|
= note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:798:20
error: internal compiler error: TyKind::Error constructed but no error reported
|
= note: delayed at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/compiler/rustc_middle/src/ty/relate.rs:419:59
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.63.0 (4b91a6ea7 2022-08-08) running on x86_64-unknown-linux-gnu
note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
Backtrace
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1425:13
stack backtrace:
0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
1: std::panic::panic_any::<rustc_errors::ExplicitBug>
2: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
3: core::ptr::drop_in_place::<rustc_session::parse::ParseSess>
4: <alloc::rc::Rc<rustc_session::session::Session> as core::ops::drop::Drop>::drop
5: core::ptr::drop_in_place::<rustc_interface::interface::Compiler>
6: 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}>
7: <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.