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 when using associated types with lifetimes #124563

Closed
AlexSherbinin opened this issue Apr 30, 2024 · 1 comment · Fixed by #126884
Closed

ICE when using associated types with lifetimes #124563

AlexSherbinin opened this issue Apr 30, 2024 · 1 comment · Fixed by #126884
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@AlexSherbinin
Copy link

Code

use std::marker::PhantomData;

pub trait Trait {}

pub trait Foo {
    type Trait: Trait;
    type Bar: Bar;
    fn foo(&mut self);
}

pub struct FooImpl<'a, 'b, A: Trait>(PhantomData<&'a &'b A>);

impl<'a, 'b, T> Foo for FooImpl<'a, 'b, T>
where
    T: Trait,
{
    type Trait = T;
    type Bar = BarImpl<'a, 'b, T>;

    fn foo(&mut self) {
        self.enter_scope(|ctx| {
            BarImpl(ctx);
        });
    }
}

impl<'a, 'b, T> FooImpl<'a, 'b, T>
where
    T: Trait,
{
    fn enter_scope(&mut self, _scope: impl FnOnce(&mut Self)) {}
}
pub trait Bar {
    type Foo: Foo;
}

pub struct BarImpl<'a, 'b, T: Trait>(&'b mut FooImpl<'a, 'b, T>);

impl<'a, 'b, T> Bar for BarImpl<'a, 'b, T>
where
    T: Trait,
{
    type Foo = FooImpl<'a, 'b, T>;
}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (a8a1d3a77 2024-04-29)
binary: rustc
commit-hash: a8a1d3a771850e1e364eb9010e98789ce758a817
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

Error output

error[E0478]: lifetime bound not satisfied
  --> rustyui/src/lib.rs:18:16
   |
18 |     type Bar = BarImpl<'a, 'b, T>;
   |                ^^^^^^^^^^^^^^^^^^
   |
note: lifetime parameter instantiated with the lifetime `'a` as defined here
  --> rustyui/src/lib.rs:13:6
   |
13 | impl<'a, 'b, T> Foo for FooImpl<'a, 'b, T>
   |      ^^
note: but lifetime parameter must outlive the lifetime `'b` as defined here
  --> rustyui/src/lib.rs:13:10
   |
13 | impl<'a, 'b, T> Foo for FooImpl<'a, 'b, T>
   |          ^^

error: internal compiler error: compiler/rustc_middle/src/ty/generic_args.rs:836:13: Unexpected parameter Type(&'{erased} mut FooImpl<'{erased}, '{erased}, T/#2>) when instantiating in region 'a (index=0)
Backtrace

thread 'rustc' panicked at compiler/rustc_middle/src/ty/generic_args.rs:836:13:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_middle::ty::generic_args::ArgFolder as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_region::region_param_invalid
   7: <rustc_middle::ty::generic_args::ArgFolder as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
   8: <rustc_middle::ty::generic_args::ArgFolder as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
   9: <rustc_middle::ty::generic_args::ArgFolder as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
  10: <rustc_middle::ty::predicate::Clause as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with::<rustc_middle::ty::generic_args::ArgFolder>
  11: <rustc_middle::ty::generics::GenericPredicates>::instantiate_into
  12: <rustc_middle::ty::generics::GenericPredicates>::instantiate
  13: <rustc_borrowck::MirBorrowckCtxt>::report_general_error
  14: <rustc_borrowck::MirBorrowckCtxt>::report_region_error
  15: rustc_borrowck::do_mir_borrowck
  16: rustc_borrowck::mir_borrowck
      [... omitted 5 frames ...]
  17: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  18: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/alex/Projects/Rust/rustyui/rustc-ice-2024-04-30T17_49_51-67262.txt` to your bug report

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `<impl at rustyui/src/lib.rs:13:1: 15:14>::foo::{closure#0}`
#1 [analysis] running analysis passes on this crate
end of query stack
there was a panic while trying to force a dep node
try_mark_green dep node stack:
#0 mir_borrowck(rustyui[c9e2]::{impl#0}::foo)
end of try_mark_green dep node stack

@AlexSherbinin AlexSherbinin 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 Apr 30, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 30, 2024
@lqd lqd added A-diagnostics Area: Messages for errors, warnings, and lints and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 30, 2024
@lqd
Copy link
Member

lqd commented Apr 30, 2024

This looks to be a recent regression from #122213 cc @estebank and is on beta 1.79, but is just in diagnostics.

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label May 9, 2024
estebank added a commit to estebank/rust that referenced this issue Jun 24, 2024
Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid.

Fix rust-lang#125634, fix rust-lang#124563.
compiler-errors added a commit to compiler-errors/rust that referenced this issue Jun 25, 2024
Do not ICE when suggesting dereferencing closure arg

Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid.

Fix rust-lang#125634, fix rust-lang#124563.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 25, 2024
Do not ICE when suggesting dereferencing closure arg

Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid.

Fix rust-lang#125634, fix rust-lang#124563.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Jun 25, 2024
Do not ICE when suggesting dereferencing closure arg

Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid.

Fix rust-lang#125634, fix rust-lang#124563.
@bors bors closed this as completed in a2298a6 Jun 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 26, 2024
Rollup merge of rust-lang#126884 - estebank:issue-125634, r=Nadrieril

Do not ICE when suggesting dereferencing closure arg

Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid.

Fix rust-lang#125634, fix rust-lang#124563.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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.

4 participants