Skip to content

ICE: panic in a destructor during cleanup #131298

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

Closed
matthiaskrgr opened this issue Oct 5, 2024 · 2 comments · Fixed by #128440
Closed

ICE: panic in a destructor during cleanup #131298

matthiaskrgr opened this issue Oct 5, 2024 · 2 comments · Fixed by #128440
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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

@matthiaskrgr
Copy link
Member

Code

#![feature(type_alias_impl_trait)]

trait Trait {
    type Gat<'lt>;
}

fn dyn_hoops<T: Trait>(_: T) -> *const dyn for<'b> Iterator<Item = impl Sized + Captures<'a>> {
    loop {}
}

mod typeck {
    use super::*;
    type Opaque = impl Sized;
    fn define() -> Option<Opaque> {
        let _: Opaque = dyn_hoops::<u8>(0);
        None
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (f559d6188 2024-10-05)
binary: rustc
commit-hash: f559d6188828b738ce7e7c2e4d99bf03111336d6
commit-date: 2024-10-05
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Error output

<output>
Backtrace

error[E0261]: use of undeclared lifetime name `'a`
 --> a.rs:7:90
  |
7 | fn dyn_hoops<T: Trait>(_: T) -> *const dyn for<'b> Iterator<Item = impl Sized + Captures<'a>> {
  |                                                                                          ^^ undeclared lifetime
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
  |
7 | fn dyn_hoops<T: Trait>(_: T) -> *const dyn for<'b> Iterator<Item = impl Sized + for<'a> Captures<'a>> {
  |                                                                                 +++++++
help: consider making the bound lifetime-generic with a new `'a` lifetime
  |
7 | fn dyn_hoops<T: Trait>(_: T) -> *const dyn for<'a, 'b> Iterator<Item = impl Sized + Captures<'a>> {
  |                                                +++
help: consider introducing lifetime `'a` here
  |
7 | fn dyn_hoops<'a, T: Trait>(_: T) -> *const dyn for<'b> Iterator<Item = impl Sized + Captures<'a>> {
  |              +++

error[E0405]: cannot find trait `Captures` in this scope
 --> a.rs:7:81
  |
7 | fn dyn_hoops<T: Trait>(_: T) -> *const dyn for<'b> Iterator<Item = impl Sized + Captures<'a>> {
  |                                                                                 ^^^^^^^^ not found in this scope

thread 'rustc' panicked at core/src/panicking.rs:229:5:
panic in a destructor during cleanup

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

note: please attach the file at `/tmp/im/rustc-ice-2024-10-05T15_12_11-2721517.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `typeck::define`
#1 [type_of_opaque] computing type of opaque `typeck::Opaque::{opaque#0}`
#2 [type_of] computing type of `typeck::Opaque::{opaque#0}`
#3 [check_well_formed] checking that `typeck::Opaque::{opaque#0}` is well-formed
#4 [check_mod_type_wf] checking that types are well-formed in module `typeck`
#5 [analysis] running analysis passes on this crate
end of query stack
thread caused non-unwinding panic. aborting.

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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 Oct 5, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 5, 2024
@cyrgani
Copy link
Contributor

cyrgani commented Oct 5, 2024

Reduced:

fn dyn_hoops<T>() -> *const dyn Iterator<Item = impl Captures> {
    loop {}
}

mod typeck {
    type Opaque = impl Sized;
    fn define() -> Opaque {
        let _: Opaque = super::dyn_hoops::<u8>();
    }
}

@matthiaskrgr
Copy link
Member Author

bisects to #125001

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Oct 12, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 15, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 11, 2025
Add `#[define_opaques]` attribute and require it for all type-alias-impl-trait sites that register a hidden type

Instead of relying on the signature of items to decide whether they are constraining an opaque type, the opaque types that the item constrains must be explicitly listed.

A previous version of this PR used an actual attribute, but had to keep the resolved `DefId`s in a side table.

Now we just lower to fields in the AST that have no surface syntax, instead a builtin attribute macro fills in those fields where applicable.

Note that for convenience referencing opaque types in associated types from associated methods on the same impl will not require an attribute. If that causes problems `#[defines()]` can be used to overwrite the default of searching for opaques in the signature.

One wart of this design is that closures and static items do not have generics. So since I stored the opaques in the generics of functions, consts and methods, I would need to add a custom field to closures and statics to track this information. During a T-types discussion we decided to just not do this for now.

fixes rust-lang#131298
@bors bors closed this as completed in 6650252 Mar 11, 2025
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Mar 14, 2025
Add `#[define_opaques]` attribute and require it for all type-alias-impl-trait sites that register a hidden type

Instead of relying on the signature of items to decide whether they are constraining an opaque type, the opaque types that the item constrains must be explicitly listed.

A previous version of this PR used an actual attribute, but had to keep the resolved `DefId`s in a side table.

Now we just lower to fields in the AST that have no surface syntax, instead a builtin attribute macro fills in those fields where applicable.

Note that for convenience referencing opaque types in associated types from associated methods on the same impl will not require an attribute. If that causes problems `#[defines()]` can be used to overwrite the default of searching for opaques in the signature.

One wart of this design is that closures and static items do not have generics. So since I stored the opaques in the generics of functions, consts and methods, I would need to add a custom field to closures and statics to track this information. During a T-types discussion we decided to just not do this for now.

fixes rust-lang#131298
bjorn3 pushed a commit to bjorn3/rust that referenced this issue Mar 25, 2025
Add `#[define_opaques]` attribute and require it for all type-alias-impl-trait sites that register a hidden type

Instead of relying on the signature of items to decide whether they are constraining an opaque type, the opaque types that the item constrains must be explicitly listed.

A previous version of this PR used an actual attribute, but had to keep the resolved `DefId`s in a side table.

Now we just lower to fields in the AST that have no surface syntax, instead a builtin attribute macro fills in those fields where applicable.

Note that for convenience referencing opaque types in associated types from associated methods on the same impl will not require an attribute. If that causes problems `#[defines()]` can be used to overwrite the default of searching for opaques in the signature.

One wart of this design is that closures and static items do not have generics. So since I stored the opaques in the generics of functions, consts and methods, I would need to add a custom field to closures and statics to track this information. During a T-types discussion we decided to just not do this for now.

fixes rust-lang#131298
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. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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
4 participants