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: can't project out of PlaceTy #101696

Closed
DavidVonDerau opened this issue Sep 11, 2022 · 0 comments · Fixed by #101708
Closed

ICE: can't project out of PlaceTy #101696

DavidVonDerau opened this issue Sep 11, 2022 · 0 comments · Fixed by #101708
Assignees
Labels
C-bug Category: This is a bug. 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

@DavidVonDerau
Copy link

DavidVonDerau commented Sep 11, 2022

Code

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e1f37488310d72e62fde9ec19c072203

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.

@DavidVonDerau DavidVonDerau 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 11, 2022
BGR360 added a commit to BGR360/glacier that referenced this issue Sep 12, 2022
@compiler-errors compiler-errors self-assigned this Sep 12, 2022
matthiaskrgr pushed a commit to matthiaskrgr/glacier that referenced this issue Sep 18, 2022
@bors bors closed this as completed in 9279c54 Sep 23, 2022
matthiaskrgr pushed a commit to matthiaskrgr/glacier that referenced this issue Sep 23, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. 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.

3 participants