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

Internal compiler error when lifetime bound is unsatisfied for generic associated type defined with impl trait. #88595

Closed
LlewVallis opened this issue Sep 2, 2021 · 4 comments · Fixed by #90678
Labels
A-GATs Area: Generic associated types (GATs) 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-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` GATs-triaged Issues using the `generic_associated_types` feature that have been triaged 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

@LlewVallis
Copy link

LlewVallis commented Sep 2, 2021

When implementing generic associated type using impl Trait, the compiler panics if the trait lifetime bound is not satisfied by duplicating the where clause.

UPDATE: seems like the compiler also panics if an appropriate where clause is included in the implementation.

Reproducible in a new cargo project on the latest nightly.

Code

#![feature(generic_associated_types)]    
#![feature(type_alias_impl_trait)]    
    
fn main() {    
    println!("Hello, world!");    
}    
    
trait A<'a> {    
    type B<'b>: Clone    
    where    
        'a: 'b;    
                                         
    fn a(&'a self) -> Self::B<'a>;       
}    
    
struct C;    
    
impl<'a> A<'a> for C {    
    type B<'b> = impl Clone;               
        
    fn a(&'a self) -> Self::B<'a> {}       
}   

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (50171c310 2021-09-01)
binary: rustc
commit-hash: 50171c310cd15e1b2d3723766ce64e2e4d6696fc
commit-date: 2021-09-01
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 13.0.0

Error output

error[E0478]: lifetime bound not satisfied
  --> src/main.rs:19:5
   |
19 |     type B<'b> = impl Clone;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: lifetime parameter instantiated with the lifetime `'a` as defined on the impl at 18:6
  --> src/main.rs:18:6
   |
18 | impl<'a> A<'a> for C {
   |      ^^
note: but lifetime parameter must outlive the lifetime `'b` as defined on the associated item at 19:12
  --> src/main.rs:19:12
   |
19 |     type B<'b> = impl Clone;
   |            ^^

thread 'rustc' panicked at 'assertion failed: self.is_free_or_static(r_a) && self.is_free_or_static(r_b)', compiler/rustc_infer/src/infer/free_regions.rs:77:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.56.0-nightly (50171c310 2021-09-01) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [typeck] type-checking `<impl at src/main.rs:18:1: 22:2>::a`
#1 [type_of] computing type of `<impl at src/main.rs:18:1: 22:2>::B::{opaque#0}`
end of query stack
Backtrace

error[E0478]: lifetime bound not satisfied
  --> src/main.rs:19:5
   |
19 |     type B<'b> = impl Clone;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: lifetime parameter instantiated with the lifetime `'a` as defined on the impl at 18:6
  --> src/main.rs:18:6
   |
18 | impl<'a> A<'a> for C {
   |      ^^
note: but lifetime parameter must outlive the lifetime `'b` as defined on the associated item at 19:12
  --> src/main.rs:19:12
   |
19 |     type B<'b> = impl Clone;
   |            ^^

thread 'rustc' panicked at 'assertion failed: self.is_free_or_static(r_a) && self.is_free_or_static(r_b)', compiler/rustc_infer/src/infer/free_regions.rs:77:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/50171c310cd15e1b2d3723766ce64e2e4d6696fc/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/50171c310cd15e1b2d3723766ce64e2e4d6696fc/library/core/src/panicking.rs:101:14
   2: core::panicking::panic
             at /rustc/50171c310cd15e1b2d3723766ce64e2e4d6696fc/library/core/src/panicking.rs:50:5
   3: <rustc_infer::infer::free_regions::FreeRegionMap as rustc_infer::infer::free_regions::FreeRegionRelations>::sub_free_regions
   4: <rustc_infer::infer::InferCtxt as rustc_trait_selection::opaque_types::InferCtxtExt>::constrain_opaque_types
   5: rustc_typeck::check::regionck::RegionCtxt::visit_fn_body
   6: rustc_typeck::check::regionck::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::regionck_fn
   7: rustc_infer::infer::InferCtxtBuilder::enter
   8: rustc_typeck::check::typeck
   9: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  10: rustc_data_structures::stack::ensure_sufficient_stack
  11: rustc_query_system::query::plumbing::force_query_with_job
  12: rustc_query_system::query::plumbing::get_query_impl
  13: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  14: rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator::check
  15: <rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator as rustc_hir::intravisit::Visitor>::visit_impl_item
  16: rustc_hir::intravisit::Visitor::visit_nested_impl_item
  17: rustc_hir::intravisit::walk_impl_item_ref
  18: rustc_hir::intravisit::walk_item
  19: rustc_typeck::collect::type_of::type_of
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  21: rustc_data_structures::stack::ensure_sufficient_stack
  22: rustc_query_system::query::plumbing::force_query_with_job
  23: rustc_query_system::query::plumbing::get_query_impl
  24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_of
  25: rustc_typeck::check::check::check_item_type
  26: rustc_middle::hir::map::Map::visit_item_likes_in_module
  27: rustc_typeck::check::check::check_mod_item_types
  28: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  29: rustc_data_structures::stack::ensure_sufficient_stack
  30: rustc_query_system::query::plumbing::force_query_with_job
  31: rustc_query_system::query::plumbing::get_query_impl
  32: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  33: rustc_session::utils::<impl rustc_session::session::Session>::time
  34: rustc_typeck::check_crate
  35: rustc_interface::passes::analysis
  36: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  37: rustc_data_structures::stack::ensure_sufficient_stack
  38: rustc_query_system::query::plumbing::force_query_with_job
  39: rustc_query_system::query::plumbing::get_query_impl
  40: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  41: rustc_interface::passes::QueryContext::enter
  42: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  43: rustc_span::with_source_map
  44: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.56.0-nightly (50171c310 2021-09-01) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [typeck] type-checking `<impl at src/main.rs:18:1: 22:2>::a`
#1 [type_of] computing type of `<impl at src/main.rs:18:1: 22:2>::B::{opaque#0}`
#2 [check_mod_item_types] checking item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0478`.
error: could not compile `mre` due to previous error

@LlewVallis LlewVallis 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 Sep 2, 2021
@jackh726 jackh726 added F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Sep 2, 2021
matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Sep 5, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Sep 5, 2021
@Luro02
Copy link
Contributor

Luro02 commented Sep 20, 2021

I ran into this issue just now, reproducible code:

use core::iter;

pub trait ToIter<T> {
    type Iter<'b>: Iterator<Item = &'b T>
    where
        T: 'b;

    fn iter(&self) -> Self::Iter<'_>;
}

pub struct DrainRange<'a, T>(&'a T);

impl<'a, T> ToIter<T> for DrainRange<'a, T> {
    type Iter<'b>
    where
        T: 'b,
    = iter::FromFn<impl FnMut() -> Option<&'b T>>;

    fn iter(&self) -> Self::Iter<'_> {
        unimplemented!()
    }
}

fn main() {}

(note: this crashes on stable as well)

full backtrace
   Compiling playground v0.0.1 (/playground)
error[E0658]: generic associated types are unstable
 --> src/main.rs:4:5
  |
4 | /     type Iter<'b>: Iterator<Item = &'b T>
5 | |     where
6 | |         T: 'b;
  | |______________^
  |
  = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error[E0658]: where clauses on associated types are unstable
 --> src/main.rs:4:5
  |
4 | /     type Iter<'b>: Iterator<Item = &'b T>
5 | |     where
6 | |         T: 'b;
  | |______________^
  |
  = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error[E0658]: `impl Trait` in type aliases is unstable
  --> src/main.rs:17:20
   |
17 |     = iter::FromFn<impl FnMut() -> Option<&'b T>>;
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information

error[E0658]: generic associated types are unstable
  --> src/main.rs:14:5
   |
14 | /     type Iter<'b>
15 | |     where
16 | |         T: 'b,
17 | |     = iter::FromFn<impl FnMut() -> Option<&'b T>>;
   | |__________________________________________________^
   |
   = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error[E0658]: where clauses on associated types are unstable
  --> src/main.rs:14:5
   |
14 | /     type Iter<'b>
15 | |     where
16 | |         T: 'b,
17 | |     = iter::FromFn<impl FnMut() -> Option<&'b T>>;
   | |__________________________________________________^
   |
   = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

thread 'rustc' panicked at 'assertion failed: self.is_free_or_static(r_a) && self.is_free_or_static(r_b)', compiler/rustc_infer/src/infer/free_regions.rs:77:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:50:5
   3: <rustc_infer::infer::free_regions::FreeRegionMap as rustc_infer::infer::free_regions::FreeRegionRelations>::sub_free_regions
   4: <rustc_infer::infer::InferCtxt as rustc_trait_selection::opaque_types::InferCtxtExt>::constrain_opaque_types
   5: rustc_typeck::check::regionck::RegionCtxt::visit_fn_body
   6: rustc_typeck::check::regionck::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::regionck_fn
   7: rustc_infer::infer::InferCtxtBuilder::enter
   8: rustc_typeck::check::typeck
   9: rustc_query_system::query::plumbing::get_query_impl
  10: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  11: rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator::check
  12: <rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator as rustc_hir::intravisit::Visitor>::visit_impl_item
  13: rustc_hir::intravisit::Visitor::visit_nested_impl_item
  14: rustc_hir::intravisit::walk_impl_item_ref
  15: rustc_hir::intravisit::walk_item
  16: rustc_typeck::collect::type_of::type_of
  17: rustc_query_system::query::plumbing::get_query_impl
  18: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_of
  19: rustc_typeck::check::check::check_item_type
  20: rustc_middle::hir::map::Map::visit_item_likes_in_module
  21: rustc_typeck::check::check::check_mod_item_types
  22: rustc_query_system::query::plumbing::get_query_impl
  23: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  24: rustc_session::utils::<impl rustc_session::session::Session>::time
  25: rustc_typeck::check_crate
  26: rustc_interface::passes::analysis
  27: rustc_query_system::query::plumbing::get_query_impl
  28: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  29: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  30: rustc_span::with_source_map
  31: rustc_interface::interface::create_compiler_and_run
  32: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.55.0 (c8dfcfe04 2021-09-06) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [typeck] type-checking `<impl at src/main.rs:13:1: 22:2>::iter`
#1 [type_of] computing type of `<impl at src/main.rs:13:1: 22:2>::Iter::{opaque#0}`
#2 [check_mod_item_types] checking item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0658`.
error: could not compile `playground` due to 5 previous errors

@Luro02
Copy link
Contributor

Luro02 commented Sep 20, 2021

Regression in `nightly-2021-07-17`
searched toolchains nightly-2021-07-12 through nightly-2021-08-10


********************************************************************************
Regression in nightly-2021-07-17
********************************************************************************

fetching https://static.rust-lang.org/dist/2021-07-16/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2021-07-16: 40 B / 40 B [==========================================================================================================================] 100.00 % 1.18 MB/s converted 2021-07-16 to b1f8e27b74c541d3d555149c8efa4bfe9385cd56
fetching https://static.rust-lang.org/dist/2021-07-17/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2021-07-17: 40 B / 40 B [========================================================================================================================] 100.00 % 590.29 KB/s converted 2021-07-17 to 74ef0c3e404cc72c08b2d1e14506f90d9e877269
looking for regression commit between 2021-07-16 and 2021-07-17
refreshing repository at "rust.git"
opening existing repository at "rust.git"
fetching (via local git) commits from b1f8e27b74c541d3d555149c8efa4bfe9385cd56 to 74ef0c3e404cc72c08b2d1e14506f90d9e877269
refreshing repository at "rust.git"
opening existing repository at "rust.git"
looking up first commit
looking up second commit
checking that commits are by bors and thus have ci artifacts...
finding bors merge commits
found 8 bors merge commits in the specified range
  commit[0] 2021-07-15UTC: Auto merge of #83319 - tmiasko:packed-aligned, r=jackh726
  commit[1] 2021-07-16UTC: Auto merge of #86993 - jackh726:project-gat-binders, r=nikomatsakis
  commit[2] 2021-07-16UTC: Auto merge of #87177 - ehuss:update-cargo, r=ehuss
  commit[3] 2021-07-16UTC: Auto merge of #86662 - mockersf:fix-86620-link-unknown-location, r=jyn514
  commit[4] 2021-07-16UTC: Auto merge of #87182 - GuillaumeGomez:rollup-whwohua, r=GuillaumeGomez
  commit[5] 2021-07-16UTC: Auto merge of #87140 - camsteffen:pat-slice-refs, r=oli-obk
  commit[6] 2021-07-16UTC: Auto merge of #84623 - jackh726:gats-incomplete, r=nikomatsakis
  commit[7] 2021-07-16UTC: Auto merge of #87201 - GuillaumeGomez:rollup-4loi2q9, r=GuillaumeGomez
validated commits found, specifying toolchains

installing b1f8e27b74c541d3d555149c8efa4bfe9385cd56
cargo for x86_64-unknown-linux-gnu: 6.06 MB / 6.06 MB [===========================================================================================================] 100.00 % 656.74 KB/s testing...
RESULT: b1f8e27b74c541d3d555149c8efa4bfe9385cd56, ===> No
uninstalling b1f8e27b74c541d3d555149c8efa4bfe9385cd56

installing 74ef0c3e404cc72c08b2d1e14506f90d9e877269
cargo for x86_64-unknown-linux-gnu: 6.07 MB / 6.07 MB [===========================================================================================================] 100.00 % 674.10 KB/s testing...
RESULT: 74ef0c3e404cc72c08b2d1e14506f90d9e877269, ===> Yes
uninstalling 74ef0c3e404cc72c08b2d1e14506f90d9e877269

installing a6470c7fa8a511cfbcf9e9d3e1ab6779ac661edb
cargo for x86_64-unknown-linux-gnu: 6.07 MB / 6.07 MB [===========================================================================================================] 100.00 % 797.24 KB/s testing...
RESULT: a6470c7fa8a511cfbcf9e9d3e1ab6779ac661edb, ===> No
uninstalling a6470c7fa8a511cfbcf9e9d3e1ab6779ac661edb

installing 2119976c492894b72287f08865c71d63cff8d471
cargo for x86_64-unknown-linux-gnu: 6.07 MB / 6.07 MB [===========================================================================================================] 100.00 % 674.55 KB/s testing...
RESULT: 2119976c492894b72287f08865c71d63cff8d471, ===> No
uninstalling 2119976c492894b72287f08865c71d63cff8d471

installing c49895d9049f67e07e297ee487836a587f69690e
cargo for x86_64-unknown-linux-gnu: 6.07 MB / 6.07 MB [===========================================================================================================] 100.00 % 692.50 KB/s testing...
RESULT: c49895d9049f67e07e297ee487836a587f69690e, ===> No
uninstalling c49895d9049f67e07e297ee487836a587f69690e

searched toolchains b1f8e27b74c541d3d555149c8efa4bfe9385cd56 through 74ef0c3e404cc72c08b2d1e14506f90d9e877269
installing 74ef0c3e404cc72c08b2d1e14506f90d9e877269
cargo for x86_64-unknown-linux-gnu: 6.07 MB / 6.07 MB [==========================================================================================================] 100.00 % 1003.23 KB/s testing...
uninstalling 74ef0c3e404cc72c08b2d1e14506f90d9e877269

********************************************************************************
Regression in 74ef0c3e404cc72c08b2d1e14506f90d9e877269
********************************************************************************

==================================================================================
= Please file this regression report on the rust-lang/rust GitHub repository     =
=        New issue: https://github.com/rust-lang/rust/issues/new                 =
=     Known issues: https://github.com/rust-lang/rust/issues                     =
= Copy and paste the text below into the issue report thread.  Thanks!           =
==================================================================================

searched nightlies: from nightly-2021-07-12 to nightly-2021-08-10
regressed nightly: nightly-2021-07-17
searched commit range: https://github.com/rust-lang/rust/compare/b1f8e27b74c541d3d555149c8efa4bfe9385cd56...74ef0c3e404cc72c08b2d1e14506f90d9e877269
regressed commit: https://github.com/rust-lang/rust/commit/74ef0c3e404cc72c08b2d1e14506f90d9e877269

#87200

@Alexendoo
Copy link
Member

No longer ICEs since #89229

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 20, 2021
@jackh726
Copy link
Member

GATs issue triage: not blocking. Fixed; needs test.

@jackh726 jackh726 added the GATs-triaged Issues using the `generic_associated_types` feature that have been triaged label Oct 23, 2021
@bors bors closed this as completed in c2f095a Nov 9, 2021
@oli-obk oli-obk moved this from Todo to Done in type alias impl trait stabilization Sep 9, 2022
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) 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-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` GATs-triaged Issues using the `generic_associated_types` feature that have been triaged 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.
Development

Successfully merging a pull request may close this issue.

6 participants