Skip to content

ICE with add lang-item with generic param #104213

Closed

Description

@jruderman

Fuzzing found this by modifying src/test/ui/associated-types/associated-types-ICE-when-projecting-out-of-err.rs.

The key modification is adding a generic parameter to the add method of the add lang-item.

NB: It still ICEs even without no_core, after noting "duplicate lang item".

Code

#![crate_type = "lib"]
#![feature(lang_items)]
#![feature(no_core)]
#![no_core]

#[lang="sized"]
pub trait Sized {
    // Empty.
}

#[lang = "add"]
trait Add<RHS=Self> {
    type Output;

    fn add<Y>(self, _: RHS) -> Self::Output;
}

#[allow(unreachable_code)]
fn ice(a: usize) {
    let r = loop {};
    r = r + a;
}

Error output

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`', compiler/rustc_hir_typeck/src/method/mod.rs:446:9

The assertion is in construct_obligation_for_trait:

assert_eq!(generics.params.len(), 0);
Backtrace

stack backtrace:
   0:        0x101e6e7a2 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hde9930b8710af522
   1:        0x101ec65ea - core::fmt::write::hd25ec0bfc1849a2f
   2:        0x101e6087c - std::io::Write::write_fmt::hca36d7396c5dc18b
   3:        0x101e6e56a - std::sys_common::backtrace::print::hc155979e9e33e658
   4:        0x101e71946 - std::panicking::default_hook::{{closure}}::h03db778ae686f347
   5:        0x101e71697 - std::panicking::default_hook::h0d9e8bcb55be071f
   6:        0x10cf3b7dd - rustc_driver[77a613ab63d15aac]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x101e72145 - std::panicking::rust_panic_with_hook::h758520931cfdfde5
   8:        0x101e71ed3 - std::panicking::begin_panic_handler::{{closure}}::hbd614a4fa39cd06c
   9:        0x101e6ec38 - std::sys_common::backtrace::__rust_end_short_backtrace::h79fc17c09554573a
  10:        0x101e71b9d - _rust_begin_unwind
  11:        0x101ef30b3 - core::panicking::panic_fmt::he2b6cedac2bde968
  12:        0x101ec329a - core::panicking::assert_failed_inner::ha6a1dd7406f04693
  13:        0x111c3096e - core[cfd2f0869b685cd6]::panicking::assert_failed::<usize, usize>
  14:        0x10f80350f - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::construct_obligation_for_trait
  15:        0x10f808c7a - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::lookup_op_method
  16:        0x10f804633 - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_overloaded_binop
  17:        0x10f8042f3 - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_binop
  18:        0x10f81e133 - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_expr_kind
  19:        0x10f7c69c0 - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  20:        0x10f81f4ab - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_expr_kind
  21:        0x10f7c69c0 - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  22:        0x10f7dc435 - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_stmt
  23:        0x10f7dcb5f - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_block_with_expected
  24:        0x10f81d188 - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_expr_kind
  25:        0x10f7c69c0 - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:        0x10f7c79fa - <rustc_hir_typeck[716c980e434cc4b7]::fn_ctxt::FnCtxt>::check_return_expr
  27:        0x10f8d08cf - rustc_hir_typeck[716c980e434cc4b7]::check::check_fn
  28:        0x10f8fc894 - rustc_hir_typeck[716c980e434cc4b7]::typeck
  29:        0x1107a95a9 - rustc_query_system[69ea88315c8057f7]::query::plumbing::try_execute_query::<rustc_query_impl[44c1f9c305efea75]::plumbing::QueryCtxt, rustc_query_system[69ea88315c8057f7]::query::caches::DefaultCache<rustc_span[48482e0f8f724117]::def_id::LocalDefId, &rustc_middle[b315a0ebd84f913d]::ty::context::TypeckResults>>
  30:        0x1108a5b6c - rustc_query_system[69ea88315c8057f7]::query::plumbing::get_query::<rustc_query_impl[44c1f9c305efea75]::queries::typeck, rustc_query_impl[44c1f9c305efea75]::plumbing::QueryCtxt>
  31:        0x10f92592b - rustc_data_structures[d9a04b93d3448b55]::sync::par_for_each_in::<&[rustc_span[48482e0f8f724117]::def_id::LocalDefId], <rustc_middle[b315a0ebd84f913d]::hir::map::Map>::par_body_owners<rustc_hir_typeck[716c980e434cc4b7]::typeck_item_bodies::{closure#0}>::{closure#0}>
  32:        0x10f8f9ded - rustc_hir_typeck[716c980e434cc4b7]::typeck_item_bodies
  33:        0x110839d99 - rustc_query_system[69ea88315c8057f7]::query::plumbing::try_execute_query::<rustc_query_impl[44c1f9c305efea75]::plumbing::QueryCtxt, rustc_query_system[69ea88315c8057f7]::query::caches::DefaultCache<(), ()>>
  34:        0x11089a319 - rustc_query_system[69ea88315c8057f7]::query::plumbing::get_query::<rustc_query_impl[44c1f9c305efea75]::queries::typeck_item_bodies, rustc_query_impl[44c1f9c305efea75]::plumbing::QueryCtxt>
  35:        0x10fa29284 - <rustc_session[ae5bb785c2cd4c22]::session::Session>::time::<(), rustc_hir_analysis[ad14f4770cb1b48d]::check_crate::{closure#7}>
  36:        0x10f9d4caf - rustc_hir_analysis[ad14f4770cb1b48d]::check_crate
  37:        0x10d08284a - rustc_interface[a0d981abc9377f30]::passes::analysis
  38:        0x11082bb5c - rustc_query_system[69ea88315c8057f7]::query::plumbing::try_execute_query::<rustc_query_impl[44c1f9c305efea75]::plumbing::QueryCtxt, rustc_query_system[69ea88315c8057f7]::query::caches::DefaultCache<(), core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>>>
  39:        0x1108a5f19 - rustc_query_system[69ea88315c8057f7]::query::plumbing::get_query::<rustc_query_impl[44c1f9c305efea75]::queries::analysis, rustc_query_impl[44c1f9c305efea75]::plumbing::QueryCtxt>
  40:        0x10cf577e6 - <rustc_interface[a0d981abc9377f30]::passes::QueryContext>::enter::<rustc_driver[77a613ab63d15aac]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>>
  41:        0x10cf9bf5d - rustc_span[48482e0f8f724117]::with_source_map::<core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>, rustc_interface[a0d981abc9377f30]::interface::run_compiler<core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>, rustc_driver[77a613ab63d15aac]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  42:        0x10cf8ba7c - <scoped_tls[46b3c18c0a12f0bc]::ScopedKey<rustc_span[48482e0f8f724117]::SessionGlobals>>::set::<rustc_interface[a0d981abc9377f30]::interface::run_compiler<core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>, rustc_driver[77a613ab63d15aac]::run_compiler::{closure#1}>::{closure#0}, core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>>
  43:        0x10cf5b3ca - std[11391ffec397fd56]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a0d981abc9377f30]::util::run_in_thread_pool_with_globals<rustc_interface[a0d981abc9377f30]::interface::run_compiler<core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>, rustc_driver[77a613ab63d15aac]::run_compiler::{closure#1}>::{closure#0}, core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>>
  44:        0x10cf414cb - <<std[11391ffec397fd56]::thread::Builder>::spawn_unchecked_<rustc_interface[a0d981abc9377f30]::util::run_in_thread_pool_with_globals<rustc_interface[a0d981abc9377f30]::interface::run_compiler<core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>, rustc_driver[77a613ab63d15aac]::run_compiler::{closure#1}>::{closure#0}, core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[cfd2f0869b685cd6]::result::Result<(), rustc_errors[ec87cacb996b1da1]::ErrorGuaranteed>>::{closure#1} as core[cfd2f0869b685cd6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:        0x101e7b1f7 - std::sys::unix::thread::Thread::new::thread_start::ha121f0b94f5d418a
  46:     0x7ff814d514e1 - __pthread_start

Version

rustc 1.67.0-nightly (7eef946fc 2022-11-06)
binary: rustc
commit-hash: 7eef946fc0e0eff40e588eab77b09b287accbec3
commit-date: 2022-11-06
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 9, 2022
  2. Noratrieb commented on Nov 9, 2022

    @Noratrieb
    Member

    @rustbot claim

  3. added 2 commits that reference this issue on Nov 11, 2022
    298e270
    e83b476
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions