rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.04k stars 12.79k forks source link

ICE with `type_alias_impl_trait` #99348

Closed JoJoJet closed 2 years ago

JoJoJet commented 2 years ago

Code

Minimum reproducible example: https://github.com/JoJoJet/bevy_param_example/blob/4ee1ab4d2ad7858df2a84a5ab2d88fc83c0d882b/src/main.rs

Meta

rustc --version --verbose:

rustc 1.64.0-nightly (7425fb293 2022-06-30)
binary: rustc
commit-hash: 7425fb293f510a6f138e82a963a3bc599a5b9e1c
commit-date: 2022-06-30
host: x86_64-pc-windows-msvc
release: 1.64.0-nightly
LLVM version: 14.0.6

Error output

    Checking bevy_param_example v0.1.0 (C:\Users\joe10\rust\projects\bevy_param_example)
warning: private type `Private` in public interface (error E0446)
  --> src\main.rs:76:9
   |
76 | /         unsafe fn get_param(
77 | |             state: &'s mut Self,
78 | |             system_meta: &bevy::ecs::system::SystemMeta,
79 | |             world: &'w bevy::ecs::world::World,
80 | |             change_tick: u32,
81 | |         ) -> Self::Item {
   | |_______________________^
   |
   = note: `#[warn(private_in_public)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>

warning: Error finalizing incremental compilation session directory `\\?\C:\Users\joe10\rust\projects\target\debug\incremental\bevy_param_example-3654vmmjs670z\s-gbpsey1uol-fv4sp2-working`: The system cannot find the file specified. (os error 2)

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: VecMap([(OpaqueTypeKey { def_id: DefId(0:14 ~ bevy_param_example[d07e]::inner::OpaqueFetch::{opaque#0}), substs: [] }, OpaqueTypeDecl { hidden_type: OpaqueHiddenType { span: src\main.rs:75:21: 75:41 (#0), ty: inner::OpaqueParamsState<(bevy::prelude::QueryState<&'static inner::Private>,)> }, origin: TyAlias })])
  |
  = note: delayed at compiler\rustc_infer\src\infer\opaque_types\table.rs:50:26

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.64.0-nightly (7425fb293 2022-06-30) running on x86_64-pc-windows-msvc

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

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

query stack during panic:
end of query stack
warning: `bevy_param_example` (bin "bevy_param_example") generated 2 warnings
error: could not compile `bevy_param_example`; 2 warnings emitted
Backtrace

``` thread 'rustc' panicked at 'Box', compiler\rustc_errors\src\lib.rs:1425:13 stack backtrace: 0: 0x7ffbc9c19fff - ::fmt::h3c410eac6bf1896a 1: 0x7ffbc9c5426a - core::fmt::write::hb34cfbd7fc8b3c9a 2: 0x7ffbc9c0c4f9 - ::fmt::h507d5d0f0254c738 3: 0x7ffbc9c1d8eb - std::panicking::default_hook::hf68d7718f0acf962 4: 0x7ffbc9c1d56b - std::panicking::default_hook::hf68d7718f0acf962 5: 0x7ffb95947106 - rustc_driver[4b277adb16bde54b]::pretty::print_after_hir_lowering 6: 0x7ffbc9c1e092 - std::panicking::rust_panic_with_hook::h395aeb81db8d4939 7: 0x7ffb9a141715 - ::fmt 8: 0x7ffb9a13d699 - ::fmt 9: 0x7ffb9a485529 - rustc_query_system[88c026d040f23148]::query::job::report_cycle 10: 0x7ffb9a0ec5f9 - ::fmt 11: 0x7ffb9a0f09bc - ::drop 12: 0x7ffb958c3fa4 - ::increment 13: 0x7ffb958ce72a - ::increment 14: 0x7ffb95958a6d - ::fmt 15: 0x7ffb95955999 - ::fmt 16: 0x7ffb958d648d - ::increment 17: 0x7ffb959000d6 - ::fmt 18: 0x7ffb95900958 - ::fmt 19: 0x7ffbc9c2e61c - std::sys::windows::thread::Thread::new::h7f265c57c73b4ff5 20: 0x7ffc2e2c7034 - BaseThreadInitThunk 21: 0x7ffc30182651 - RtlUserThreadStart ```

compiler-errors commented 2 years ago

Thank you for reporting this issue. I have minimized this into two different issues:

(1.) Checking trait and impl assoc type compatibility might constrain opaques in ways we don't observe during find_opaque_ty_constraints:

#![feature(type_alias_impl_trait)]

struct Concrete;

type Tait = impl Sized;

impl Foo for Concrete {
    type Item = Concrete;
}

impl Bar for Concrete {
    type Other = Tait;
}

trait Foo {
    type Item: Bar<Other = Self>;
}

trait Bar {
    type Other;
}

fn tait() -> Tait {}

(2.) Borrowck's opaque type constraints differ from typeck's constraints. Probably due to reachability during mir build.

#![feature(type_alias_impl_trait)]

type Tait = impl Sized;

struct One;
fn one() -> Tait { One }

struct Two<T>(T);
fn two() -> Tait { Two::<()>(todo!()) }
compiler-errors commented 2 years ago

This might be another, unrelated bug.

You were correct about this :stuck_out_tongue_winking_eye:

JoJoJet commented 2 years ago

Wow that example is much more minimal than mine 😀

compiler-errors commented 2 years ago

No worries, the fact that you provided sample code is very well appreciated.

JohnTitor commented 2 years ago

Triage: The ICE itself has been fixed by #99356 but I'm not sure why it didn't close this issue, @compiler-errors Is there a remaining task?

compiler-errors commented 2 years ago

There's another issue I pointed out in (2.) that remains, I'll file another task for just that and then close this out..