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: no errors encountered even though delay_span_bug issued, expected ReFree to map to ReEarlyBound #108580

Closed
jswrenn opened this issue Feb 28, 2023 · 2 comments · Fixed by #122988
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` 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

@jswrenn
Copy link
Member

jswrenn commented Feb 28, 2023

Code

(Playground)

#![feature(associated_type_bounds, return_position_impl_trait_in_trait)]
#![allow(incomplete_features)]

trait Iterator {
    type Item;
}

trait IntoIterator {
    fn into_iterator(&self) -> impl Iterator<Item:> + '_;
}

struct IntoIterFn<F, I>
{
    f: F,
    _marker: core::marker::PhantomData<I>,
}

impl<F, I> IntoIterator for IntoIterFn<F, I>
where
    F: Fn() -> I,
    I: Iterator,
{
    fn into_iterator(&self) -> impl Iterator<Item: '_> {
        (self.f)()
    }
}

Meta

Version:

rustc 1.69.0-nightly (7281249a1 2023-02-27)

Error output

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

error: internal compiler error: expected ReFree to map to ReEarlyBound
  --> src/lib.rs:23:32
   |
23 |     fn into_iterator(&self) -> impl Iterator<Item: '_> {
   |                                ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
              1: <rustc_session::session::Session>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
              2: rustc_hir_analysis::check::compare_impl_item::collect_return_position_impl_trait_in_trait_tys::{closure#0}::{closure#2}
              3: rustc_middle::ty::util::fold_list::<rustc_middle::ty::fold::RegionFolder, rustc_middle::ty::subst::GenericArg, <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with<rustc_middle::ty::fold::RegionFolder>::{closure#0}>
              4: <rustc_middle::ty::Ty as rustc_type_ir::fold::TypeSuperFoldable<rustc_middle::ty::context::TyCtxt>>::super_fold_with::<rustc_middle::ty::fold::RegionFolder>
              5: <rustc_middle::ty::context::TyCtxt>::fold_regions::<rustc_middle::ty::Ty, rustc_hir_analysis::check::compare_impl_item::collect_return_position_impl_trait_in_trait_tys::{closure#0}::{closure#2}>
              6: rustc_hir_analysis::check::compare_impl_item::collect_return_position_impl_trait_in_trait_tys
              7: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::collect_return_position_impl_trait_in_trait_tys, rustc_query_impl::plumbing::QueryCtxt>
              8: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_return_position_impl_trait_in_trait_tys
              9: <rustc_middle::ty::context::TyCtxt>::bound_return_position_impl_trait_in_trait_tys
             10: rustc_trait_selection::traits::project::opt_normalize_projection_type
             11: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
             12: <&rustc_middle::ty::list::List<rustc_middle::ty::Ty> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
             13: <rustc_infer::infer::at::At as rustc_trait_selection::traits::project::NormalizeExt>::normalize::<rustc_middle::ty::sty::FnSig>
             14: rustc_hir_analysis::check::compare_impl_item::compare_method_predicate_entailment
             15: rustc_hir_analysis::check::compare_impl_item::compare_impl_method
             16: rustc_hir_analysis::check::check::check_impl_items_against_trait
             17: rustc_hir_analysis::check::check::check_mod_item_types
             18: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::check_mod_item_types, rustc_query_impl::plumbing::QueryCtxt>
             19: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
             20: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#6}>
             21: rustc_hir_analysis::check_crate
             22: rustc_interface::passes::analysis
             23: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
             24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
             25: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             26: rustc_span::with_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
             27: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             28: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             29: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/7281249a19a9755e9d889ee251ec323629caadab/library/alloc/src/boxed.rs:1988:9
             30: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                        at /rustc/7281249a19a9755e9d889ee251ec323629caadab/library/alloc/src/boxed.rs:1988:9
             31: std::sys::unix::thread::Thread::new::thread_start
                        at /rustc/7281249a19a9755e9d889ee251ec323629caadab/library/std/src/sys/unix/thread.rs:108:17
             32: start_thread
             33: clone
           

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.69.0-nightly (7281249a1 2023-02-27) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

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

query stack during panic:
end of query stack
@jswrenn jswrenn 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 Feb 28, 2023
@compiler-errors compiler-errors self-assigned this Feb 28, 2023
@compiler-errors compiler-errors added F-associated_type_bounds `#![feature(associated_type_bounds)]` F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` labels Feb 28, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Feb 28, 2023

This is also not related to associated type bounds:

#![feature(return_position_impl_trait_in_trait)]

trait Foo {
    fn bar(&self) -> impl Iterator<Item = impl Sized> + '_;
}

impl Foo for () {
    fn bar(&self) -> impl Iterator + '_ {
        vec![()].into_iter()
    }
}

This was fixed by #105255, which was subsequently reverted in #106759. The fix here is to make opaque types inherit their parent's generics, which can probably be done if #106729 lands.

@compiler-errors compiler-errors removed the F-associated_type_bounds `#![feature(associated_type_bounds)]` label Feb 28, 2023
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 21, 2023
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Jul 1, 2023
…ures, r=oli-obk

Error when RPITITs' hidden types capture more lifetimes than their trait definitions

This implements a stricter set of captures rules for RPITITs. They now may only capture:
1. Lifetimes from the impl header (both the self type and any trait substs -- we may want to restrict just to the self type's lifetimes, but the PR makes that easy to do, too)
2. Lifetimes mentioned by the `impl Trait` in the trait method's definition.

Namely, they may not mention lifetimes from the method (early or late) that are not mentioned in the `impl Trait`.

cc rust-lang#105258 which I think was trying to do this too, though I'm not super familiar with what exactly differs from that or why that one was broken.
cc rust-lang#112194 (doesn't fix this issue per se, because it's still an open question, but I think this is objectively better than the status quo, and gets us closer to resolving that issue.)

Technically is a fix for the ICE in rust-lang#108580, but it turns that issue into an error now. We can decide separately whether or not nested RPITITs should capture lifetimes from their parents.

r? `@oli-obk`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 1, 2023
…ures, r=oli-obk

Error when RPITITs' hidden types capture more lifetimes than their trait definitions

This implements a stricter set of captures rules for RPITITs. They now may only capture:
1. Lifetimes from the impl header (both the self type and any trait substs -- we may want to restrict just to the self type's lifetimes, but the PR makes that easy to do, too)
2. Lifetimes mentioned by the `impl Trait` in the trait method's definition.

Namely, they may not mention lifetimes from the method (early or late) that are not mentioned in the `impl Trait`.

cc rust-lang#105258 which I think was trying to do this too, though I'm not super familiar with what exactly differs from that or why that one was broken.
cc rust-lang#112194 (doesn't fix this issue per se, because it's still an open question, but I think this is objectively better than the status quo, and gets us closer to resolving that issue.)

Technically is a fix for the ICE in rust-lang#108580, but it turns that issue into an error now. We can decide separately whether or not nested RPITITs should capture lifetimes from their parents.

r? ``@oli-obk``
@compiler-errors
Copy link
Member

Triage: This no longer iCEs, now it errors with the following message

error: return type captures more lifetimes than trait definition
 --> src/lib.rs:8:22
  |
8 |     fn bar(&self) -> impl Iterator + '_ {
  |            -         ^^^^^^^^^^^^^^^^^^
  |            |
  |            this lifetime was captured
  |
note: hidden type must only reference lifetimes captured by this impl trait
 --> src/lib.rs:4:43
  |
4 |     fn bar(&self) -> impl Iterator<Item = impl Sized> + '_;
  |                                           ^^^^^^^^^^
  = note: hidden type inferred to be `<impl Iterator + '_ as Iterator>::Item`

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jul 8, 2023
@compiler-errors compiler-errors removed their assignment Jul 31, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 24, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 25, 2024
Rollup merge of rust-lang#122988 - matthiaskrgr:icetests, r=petrochenkov

add even more tests!

Fixes rust-lang#109869
Fixes rust-lang#110453
Fixes rust-lang#109020
Fixes rust-lang#108580
Fixes rust-lang#108220
Fixes rust-lang#113045
Fixes rust-lang#113133
Fixes rust-lang#114464
Fixes rust-lang#116599
Fixes rust-lang#119731
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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` 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.

4 participants