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 assertion failed: !ty.needs_infer() #110161

Closed
matthiaskrgr opened this issue Apr 10, 2023 · 7 comments · Fixed by #110272
Closed

ICE assertion failed: !ty.needs_infer() #110161

matthiaskrgr opened this issue Apr 10, 2023 · 7 comments · Fixed by #110272
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Apr 10, 2023

Code

trait Combine<'a> {
    type Ty;
}

impl<'a, T> Combine<'a> for Box<T> {}

struct WrapC<T>(T);
impl<'a, 'x: 'a, T> Combine<'a> for WrapC<T>
where
    T: Combine<'a, Ty = &'a &'x ()>,
{
    type Ty = &'a &'x ();
}

fn test_wrap<'a, 'b, 'c1, 'c2, A, B>(
    _: <WrapC<Box<&'main ()>> as Combine<'c2>>::Ty, 
) {}

Meta

rustc --version --verbose:

rustc 1.70.0-nightly (696aaad58 2023-04-09)
binary: rustc
commit-hash: 696aaad58c57a589f6fb2ecff5bae2eec581cb71
commit-date: 2023-04-09
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 16.0.2

Error output

<output>
Backtrace

error[E0261]: use of undeclared lifetime name `'main`
  --> treereduce.out:16:20
   |
15 | fn test_wrap<'a, 'b, 'c1, 'c2, A, B>(
   |              - help: consider introducing lifetime `'main` here: `'main,`
16 |     _: <WrapC<Box<&'main ()>> as Combine<'c2>>::Ty,
   |                    ^^^^^ undeclared lifetime

error[E0601]: `main` function not found in crate `treereduce`
  --> treereduce.out:17:5
   |
17 | ) {}
   |     ^ consider adding a `main` function to `treereduce.out`

thread 'rustc' panicked at 'assertion failed: !ty.needs_infer()', compiler/rustc_trait_selection/src/traits/outlives_bounds.rs:58:9
stack backtrace:
   0:     0x7f1f9f764f0a - std::backtrace_rs::backtrace::libunwind::trace::hd26deac9c5400510
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f1f9f764f0a - std::backtrace_rs::backtrace::trace_unsynchronized::h0d525c5df19c5fb3
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1f9f764f0a - std::sys_common::backtrace::_print_fmt::hfa46a4e5b1417412
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f1f9f764f0a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd35deac25c2a2361
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f1f9f7c8fcf - core::fmt::write::h57692caee39fe498
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/core/src/fmt/mod.rs:1254:17
   5:     0x7f1f9f757a45 - std::io::Write::write_fmt::h3cf8ad4e45a4d8c5
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/io/mod.rs:1698:15
   6:     0x7f1f9f764cd5 - std::sys_common::backtrace::_print::hdf25b99ab69d47c1
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f1f9f764cd5 - std::sys_common::backtrace::print::hf7d8e454ceffbfe6
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f1f9f76797e - std::panicking::default_hook::{{closure}}::hd867f5f971a369e7
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/panicking.rs:269:22
   9:     0x7f1f9f767725 - std::panicking::default_hook::habf6eee7b304b436
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/panicking.rs:288:9
  10:     0x7f1fa2a55665 - rustc_driver_impl[2d97b4318b2b8966]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f1f9f768174 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h0aac6d981c9df2cb
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/alloc/src/boxed.rs:1990:9
  12:     0x7f1f9f768174 - std::panicking::rust_panic_with_hook::h0ae6f6705c097c51
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/panicking.rs:694:13
  13:     0x7f1f9f767ea2 - std::panicking::begin_panic_handler::{{closure}}::hbe8782e7e80a84bd
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/panicking.rs:579:13
  14:     0x7f1f9f765376 - std::sys_common::backtrace::__rust_end_short_backtrace::hc6aeb922005c62a1
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/sys_common/backtrace.rs:150:18
  15:     0x7f1f9f767c42 - rust_begin_unwind
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/panicking.rs:577:5
  16:     0x7f1f9f7c52e3 - core::panicking::panic_fmt::h558c06d837516a28
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/core/src/panicking.rs:67:14
  17:     0x7f1f9f7c537d - core::panicking::panic::hee3e155c560a4e20
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/core/src/panicking.rs:117:5
  18:     0x7f1fa17e4eea - <rustc_infer[37e422eb914efaf5]::infer::outlives::env::OutlivesEnvironment>::with_bounds::<core[df85f84a2bdb4263]::iter::adapters::flatten::FlatMap<indexmap[e897b03f07ffded1]::set::IntoIter<rustc_middle[9ae9af9eb73fc3b1]::ty::Ty>, alloc[3819410e73c92c1b]::vec::Vec<rustc_middle[9ae9af9eb73fc3b1]::traits::query::OutlivesBound>, <rustc_infer[37e422eb914efaf5]::infer::InferCtxt as rustc_trait_selection[726c9a7f6e25929]::traits::outlives_bounds::InferCtxtExt>::implied_bounds_tys::{closure#0}>>
  19:     0x7f1fa17e02ef - rustc_hir_analysis[2fa568bcc53e911e]::check::wfcheck::check_item_fn
  20:     0x7f1fa17db199 - rustc_hir_analysis[2fa568bcc53e911e]::check::wfcheck::check_well_formed
  21:     0x7f1fa0f749ce - rustc_query_system[f15f440fadbc0dc2]::query::plumbing::try_execute_query::<rustc_query_impl[ed927665e84058ad]::queries::check_well_formed, rustc_query_impl[ed927665e84058ad]::plumbing::QueryCtxt>
  22:     0x7f1fa1c9fe57 - rustc_data_structures[6c5f262034998aae]::sync::par_for_each_in::<&[rustc_hir[1fa94aaa058a1f1a]::hir::ImplItemId], <rustc_middle[9ae9af9eb73fc3b1]::hir::ModuleItems>::par_impl_items<rustc_hir_analysis[2fa568bcc53e911e]::check::wfcheck::check_mod_type_wf::{closure#1}>::{closure#0}>
  23:     0x7f1fa1c9f914 - rustc_hir_analysis[2fa568bcc53e911e]::check::wfcheck::check_mod_type_wf
  24:     0x7f1fa207d231 - rustc_query_system[f15f440fadbc0dc2]::query::plumbing::try_execute_query::<rustc_query_impl[ed927665e84058ad]::queries::check_mod_type_wf, rustc_query_impl[ed927665e84058ad]::plumbing::QueryCtxt>
  25:     0x7f1fa207cdd9 - <rustc_query_impl[ed927665e84058ad]::Queries as rustc_middle[9ae9af9eb73fc3b1]::ty::query::QueryEngine>::check_mod_type_wf
  26:     0x7f1fa1f25c37 - rustc_data_structures[6c5f262034998aae]::sync::par_for_each_in::<&[rustc_hir[1fa94aaa058a1f1a]::hir_id::OwnerId], <rustc_middle[9ae9af9eb73fc3b1]::hir::map::Map>::par_for_each_module<rustc_hir_analysis[2fa568bcc53e911e]::check_crate::{closure#5}::{closure#0}::{closure#0}>::{closure#0}>
  27:     0x7f1fa1f259f0 - <rustc_session[ca8de67c023859ee]::session::Session>::track_errors::<rustc_hir_analysis[2fa568bcc53e911e]::check_crate::{closure#5}, ()>
  28:     0x7f1fa1f2301f - rustc_hir_analysis[2fa568bcc53e911e]::check_crate
  29:     0x7f1fa1f1d4a1 - rustc_interface[5859b4daf695f246]::passes::analysis
  30:     0x7f1fa21a50c2 - rustc_query_system[f15f440fadbc0dc2]::query::plumbing::try_execute_query::<rustc_query_impl[ed927665e84058ad]::queries::analysis, rustc_query_impl[ed927665e84058ad]::plumbing::QueryCtxt>
  31:     0x7f1fa21a4dd0 - <rustc_query_impl[ed927665e84058ad]::Queries as rustc_middle[9ae9af9eb73fc3b1]::ty::query::QueryEngine>::analysis
  32:     0x7f1fa20d6db6 - <std[3958f564ddc007dc]::thread::local::LocalKey<core[df85f84a2bdb4263]::cell::Cell<*const ()>>>::with::<rustc_middle[9ae9af9eb73fc3b1]::ty::context::tls::enter_context<<rustc_middle[9ae9af9eb73fc3b1]::ty::context::GlobalCtxt>::enter<rustc_driver_impl[2d97b4318b2b8966]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>>::{closure#0}, core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>>::{closure#0}, core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>>
  33:     0x7f1fa1ce27ef - <rustc_interface[5859b4daf695f246]::interface::Compiler>::enter::<rustc_driver_impl[2d97b4318b2b8966]::run_compiler::{closure#1}::{closure#2}, core[df85f84a2bdb4263]::result::Result<core[df85f84a2bdb4263]::option::Option<rustc_interface[5859b4daf695f246]::queries::Linker>, rustc_span[24111c70308d7d50]::ErrorGuaranteed>>
  34:     0x7f1fa1cdda41 - rustc_span[24111c70308d7d50]::set_source_map::<core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>, rustc_interface[5859b4daf695f246]::interface::run_compiler<core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>, rustc_driver_impl[2d97b4318b2b8966]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  35:     0x7f1fa1cdd586 - <scoped_tls[5f4f1a448a290364]::ScopedKey<rustc_span[24111c70308d7d50]::SessionGlobals>>::set::<rustc_interface[5859b4daf695f246]::interface::run_compiler<core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>, rustc_driver_impl[2d97b4318b2b8966]::run_compiler::{closure#1}>::{closure#0}, core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>>
  36:     0x7f1fa1cdcc5b - std[3958f564ddc007dc]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[5859b4daf695f246]::util::run_in_thread_pool_with_globals<rustc_interface[5859b4daf695f246]::interface::run_compiler<core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>, rustc_driver_impl[2d97b4318b2b8966]::run_compiler::{closure#1}>::{closure#0}, core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>>
  37:     0x7f1fa2320db1 - <<std[3958f564ddc007dc]::thread::Builder>::spawn_unchecked_<rustc_interface[5859b4daf695f246]::util::run_in_thread_pool_with_globals<rustc_interface[5859b4daf695f246]::interface::run_compiler<core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>, rustc_driver_impl[2d97b4318b2b8966]::run_compiler::{closure#1}>::{closure#0}, core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[df85f84a2bdb4263]::result::Result<(), rustc_span[24111c70308d7d50]::ErrorGuaranteed>>::{closure#1} as core[df85f84a2bdb4263]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x7f1f9f772255 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h40268ec1e3f75121
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/alloc/src/boxed.rs:1976:9
  39:     0x7f1f9f772255 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb4cdee1772a16528
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/alloc/src/boxed.rs:1976:9
  40:     0x7f1f9f772255 - std::sys::unix::thread::Thread::new::thread_start::h71a921bd46112f49
                               at /rustc/696aaad58c57a589f6fb2ecff5bae2eec581cb71/library/std/src/sys/unix/thread.rs:108:17
  41:     0x7f1f9f50cbb5 - <unknown>
  42:     0x7f1f9f58ed90 - <unknown>
  43:                0x0 - <unknown>

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: rustc 1.70.0-nightly (696aaad58 2023-04-09) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `test_wrap` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0261, E0601.
For more information about an error, try `rustc --explain E0261`

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Apr 10, 2023
@matthiaskrgr
Copy link
Member Author

See also #109204 , but while 109204 only reproduces with rustdoc, this one only repros with rustc and not rustdoc 🤔

@compiler-errors compiler-errors added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Apr 10, 2023
@Ezrashaw
Copy link
Contributor

searched nightlies: from nightly-2023-01-01 to nightly-2023-04-11
regressed nightly: nightly-2023-03-29
searched commit range: 2036fdd...478cbb4
regressed commit: 478cbb4

bisected with cargo-bisect-rustc v0.6.6

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --regress=ice --start 2023-01-01

@matthiaskrgr matthiaskrgr removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Apr 11, 2023
@Ezrashaw
Copy link
Contributor

@rustbot claim

I'll have a go at this, no idea if I'll be able to do it.

@aliemjay
Copy link
Member

This is an ICE on invalid code.
@rustbot label regression-from-stable-to-nightly

Minimized:

trait Trait {
    type Ty;
}

// erroneous `Ty` impl
impl Trait for () {
    // missing `Ty` impl
}

// `'lt` is not constrained by the erroneous `Ty`
impl<'lt, T> Trait for Box<T>
where
    T: Trait<Ty = &'lt ()>,
{
    type Ty = &'lt ();
}

// unconstrained lifetime appears in implied bounds
fn test(_: <Box<()> as Trait>::Ty) {}

@Ezrashaw this can be fixed by replacing the assertion with delay_span_bug and returning early to avoid processing unconstrained lifetime variables in implied bounds. It would be nice if we have a comment referring to this issue or to the ui test for why delaying a bug was necessary.

@rustbot rustbot added 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 Apr 13, 2023
@Noratrieb
Copy link
Member

searched nightlies: from nightly-2023-01-01 to nightly-2023-04-11 regressed nightly: nightly-2023-03-29 searched commit range: 2036fdd...478cbb4 regressed commit: 478cbb4

bisected with cargo-bisect-rustc v0.6.6

btw, you should update your cargo-bisect-rustc to make it bisect the contents of rollups as well.

@Ezrashaw
Copy link
Contributor

It is, unfortunately the regression is old enough that perf artifacts are gone :(

@Noratrieb
Copy link
Member

It's not old, but I remember now, this was my cursed rollup that didn't get unrolled perf builds. It also was a perf regression which made it pretty annoying :D

aliemjay added a commit to aliemjay/rust that referenced this issue Apr 15, 2023
…unds, r=aliemjay

fix: skip implied bounds if unconstrained lifetime exists

Fixes rust-lang#110161

r? `@aliemjay`
aliemjay added a commit to aliemjay/rust that referenced this issue Apr 15, 2023
…unds, r=aliemjay

fix: skip implied bounds if unconstrained lifetime exists

Fixes rust-lang#110161

r? ``@aliemjay``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 15, 2023
…unds, r=aliemjay

fix: skip implied bounds if unconstrained lifetime exists

Fixes rust-lang#110161

r? ```@aliemjay```
@bors bors closed this as completed in 52d23c9 Apr 16, 2023
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 19, 2023
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. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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.

7 participants