Skip to content

ICE infering higher-ranked lifetime with a builder pattern #80409

Closed
@rudib

Description

@rudib

I haven't been able to minimize this yet. The similar, already resolved, bug report #56199 doesn't seem to help - changing the on_entry's return signature from Self to the full definition doesn't help here.

Code

use std::marker::PhantomData;

pub struct FsmBuilder<TFsm, TContext> {
    _fsm: PhantomData<TFsm>,
    _context: PhantomData<TContext>
}

impl<TFsm, TContext> FsmBuilder<TFsm, TContext> {
	pub fn state<TState>(&mut self) -> FsmStateBuilder<TFsm, TContext, TState> {
		FsmStateBuilder {
			_state: PhantomData::default(),
			_fsm: self
		}
	}
}


pub struct FsmStateBuilder<'a, TFsm, TContext, TState> {
	_state: PhantomData<TState>,
	_fsm: &'a FsmBuilder<TFsm, TContext>
}

impl<'a, TFsm, TContext, TState> FsmStateBuilder<'a, TFsm, TContext, TState> {
	pub fn on_entry<TAction: Fn(&mut TState, &mut StateContext<'a, TFsm>)>(&self, _action: TAction) -> &Self {
		self
	}
}

pub trait Fsm where Self: Sized {
    type Context;
}

pub struct StateContext<'a, TFsm: Fsm> {
    pub context: &'a mut TFsm::Context
}

struct SampleFsm;
struct SampleFsmCtx;

struct StateA { _val: u32 }

fn main() {
    let mut builder: FsmBuilder<SampleFsm, SampleFsmCtx> = FsmBuilder {
        _fsm: PhantomData::default(),
        _context: PhantomData::default()
    };
    
    builder.state::<StateA>().on_entry(|_state, _ctx| { });
}

Meta

The bug is also present in the nightly build (bb1fbbf84 2020-12-22).

rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-pc-windows-msvc
release: 1.48.0
LLVM version: 11.0

Error output

error: internal compiler error: unresolved inference variable in outlives: _#19t
  --> fsm_tests\tests\fsm_fn.rs:44:36
   |
44 |       fsm.state::<StateA>().on_entry(|state_a, ctx| {
   |  ____________________________________^
45 | |         state_a.counter += 1;
46 | |     });
   | |_____^
   |
   = note: delayed at compiler\rustc_infer\src\infer\outlives\obligations.rs:318:35

error: internal compiler error: unresolved inference variable in outlives: _#0t
  |
  = note: delayed at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\compiler\rustc_infer\src\infer\outlives\obligations.rs:318:35
Backtrace

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler\rustc_errors\src\lib.rs:961:13
stack backtrace:
   0:     0x7ffce68ca4a9 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hba5f685a77e920dc
   1:     0x7ffce68f748b - core::fmt::write::h7e2938de326daa9d
   2:     0x7ffce68bb998 - <std::io::IoSlice as core::fmt::Debug>::fmt::h6db1280adf9c872d
   3:     0x7ffce68cf8d4 - std::panicking::take_hook::hfb0d507d25fcd861
   4:     0x7ffce68cf4b8 - std::panicking::take_hook::hfb0d507d25fcd861
   5:     0x7ffcb122aa45 - rustc_driver::report_ice::he237f3b59ed412a9
   6:     0x7ffce68d0330 - std::panicking::rust_panic_with_hook::h67dee359ed61e799
   7:     0x7ffce68cfe65 - rust_begin_unwind
   8:     0x7ffce68cad8f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hba5f685a77e920dc
   9:     0x7ffce68cfe19 - rust_begin_unwind
  10:     0x7ffce68cfdcc - std::panicking::begin_panic_fmt::h8d7269719d1216e5
  11:     0x7ffcb58e7634 - rustc_errors::HandlerInner::delay_as_bug::h722d622a33e90806
  12:     0x7ffcb58e3424 - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::h53a3b47c2a6749e8
  13:     0x7ffcb1295257 - <rustc_expand::mbe::macro_parser::MatcherPosHandle as core::ops::deref::DerefMut>::deref_mut::h5acc804ee7cddfed
  14:     0x7ffcb129afda - <rustc_expand::mbe::macro_parser::MatcherPosHandle as core::ops::deref::DerefMut>::deref_mut::h5acc804ee7cddfed
  15:     0x7ffcb1250bfc - rustc_span::MultiSpan::primary_spans::h1017427bb4c1e209
  16:     0x7ffcb124a8bb - rustc_span::MultiSpan::primary_spans::h1017427bb4c1e209
  17:     0x7ffcb126d0b4 - <rustc_expand::mbe::macro_parser::MatcherPosHandle as core::ops::deref::DerefMut>::deref_mut::h5acc804ee7cddfed
  18:     0x7ffcb1275d53 - <rustc_expand::mbe::macro_parser::MatcherPosHandle as core::ops::deref::DerefMut>::deref_mut::h5acc804ee7cddfed
  19:     0x7ffcb11f8b53 - chalk_engine::TimeStamp::increment::h4493be1e979912d6
  20:     0x7ffce68e0207 - std::sys::windows::thread::Thread::new::hb28370ce7bd0d890
  21:     0x7ffd551e7034 - BaseThreadInitThunk
  22:     0x7ffd56ebd0d1 - RtlUserThreadStart

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.48.0 (7eac88abb 2020-11-16) running on x86_64-pc-windows-msvc

note: compiler flags: -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

Metadata

Metadata

Assignees

Labels

A-inferenceArea: Type inferenceA-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions