Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
rudib opened this issue Dec 27, 2020 · 8 comments · Fixed by #109968
Closed

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

rudib opened this issue Dec 27, 2020 · 8 comments · Fixed by #109968
Assignees
Labels
A-inference Area: Type inference A-lifetimes Area: Lifetimes / regions 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

@rudib
Copy link

rudib commented Dec 27, 2020

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

@rudib rudib 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 Dec 27, 2020
@jyn514 jyn514 added the A-inference Area: Type inference label Dec 27, 2020
@jyn514
Copy link
Member

jyn514 commented Dec 27, 2020

Minimized a little:

use std::marker::PhantomData;

struct FsmBuilder<TFsm> {
    _fsm: PhantomData<TFsm>,
}

impl<TFsm> FsmBuilder<TFsm> {
	fn state(&mut self) -> FsmStateBuilder<TFsm> {
    	todo!()
	}
}


struct FsmStateBuilder<TFsm> {
	_state: PhantomData<TFsm>,
}

impl<TFsm> FsmStateBuilder<TFsm> {
	fn on_entry<TAction: Fn(&mut StateContext<'_, TFsm>)>(&self, _action: TAction) {}
}

trait Fsm {
    type Context;
}

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

fn main() {
    let mut builder: FsmBuilder<usize> = todo!();
    builder.state().on_entry(|_| {});
}

@jyn514 jyn514 changed the title Internal compiler error with a builder pattern ICE infering higher-ranked lifetime with a builder pattern Dec 27, 2020
@jyn514 jyn514 added the A-lifetimes Area: Lifetimes / regions label Dec 27, 2020
@jyn514
Copy link
Member

jyn514 commented Dec 27, 2020

Note the error goes away if you add impl Fsm for usize, or if you change &'a TFsm::Context to &'a TFsm. So I think the bug is that the trait bound is not being checked.

cc @matthewjasper

fanninpm added a commit to fanninpm/glacier that referenced this issue Dec 29, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 31, 2020
@Spoonbender
Copy link

Triage: no change

@matthiaskrgr
Copy link
Member

No longe crashes with master toolchain

@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 10, 2023
@JohnTitor JohnTitor self-assigned this Apr 5, 2023
JohnTitor added a commit to JohnTitor/rust that referenced this issue Apr 5, 2023
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 5, 2023
…errors

Add regression test for rust-lang#80409

r? `@compiler-errors`
Closes rust-lang#80409
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 5, 2023
Rollup of 7 pull requests

Successful merges:

 - rust-lang#109909 (Deny `use`ing tool paths)
 - rust-lang#109921 (Don't ICE when encountering `dyn*` in statics or consts)
 - rust-lang#109922 (Disable `has_thread_local` on OpenHarmony)
 - rust-lang#109926 (write threads info into log only when debugging)
 - rust-lang#109968 (Add regression test for rust-lang#80409)
 - rust-lang#109969 (Add regression test for rust-lang#86351)
 - rust-lang#109973 (rustdoc: Improve logo display very small screen)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 1424268 Apr 6, 2023
@matthiaskrgr
Copy link
Member

Crashing again after #118553

@matthiaskrgr matthiaskrgr reopened this Jan 18, 2024
@matthiaskrgr
Copy link
Member

This is also a compiles -> ice regression

@matthiaskrgr matthiaskrgr added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Jan 18, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 18, 2024
@jackh726
Copy link
Member

This never should have passed.

Removing regression label; this can remain open to track the ICE.

@jackh726 jackh726 removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 18, 2024
@lolbinarycat
Copy link
Contributor

no longer produces an ICE as of rust 1.81.0

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-inference Area: Type inference A-lifetimes Area: Lifetimes / regions 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.

9 participants