Skip to content

ICE calling generic method with explicitly provided self parameter #111838

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
BattyBoopers opened this issue May 22, 2023 · 1 comment · Fixed by #111860
Closed

ICE calling generic method with explicitly provided self parameter #111838

BattyBoopers opened this issue May 22, 2023 · 1 comment · Fixed by #111860
Assignees
Labels
C-bug Category: This is a bug. F-arbitrary_self_types `#![feature(arbitrary_self_types)]` 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

@BattyBoopers
Copy link

Code

#![feature(arbitrary_self_types)]
use std::ops::Deref;

struct Foo(u32);
impl Foo {
    fn get<R: Deref<Target=Self>>(self: R) -> u32 {
        self.0
    }
}

fn main() {
    let mut foo = Foo(1);
    foo.get::<&Foo>(); // ICE
}

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.71.0-nightly (9d871b061 2023-05-21)
binary: rustc
commit-hash: 9d871b0617a4b3d6610b7cee0ab5310dcb542c62
commit-date: 2023-05-21
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.4

Error output

$ cargo build
   Compiling ice v0.1.0 (/tmp/ice)
error: internal compiler error: compiler/rustc_hir_typeck/src/method/confirm.rs:486:17: Foo was a subtype of &Foo but now is not?
  --> src/main.rs:13:9
   |
13 |     foo.get::<&Foo>(); // ICE
   |         ^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/compiler/rustc_errors/src/lib.rs:994:33
stack backtrace:
   0:     0x7f7d94ef88d1 - std::backtrace_rs::backtrace::libunwind::trace::h1fcde0ea8f9a8cac
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f7d94ef88d1 - std::backtrace_rs::backtrace::trace_unsynchronized::h3bfe5daa881a502d
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f7d94ef88d1 - std::sys_common::backtrace::_print_fmt::h6c9a5949f87a0a7a
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f7d94ef88d1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h60e57e557d9992ea
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f7d94f58dff - core::fmt::rt::Argument::fmt::h32fe9cf7fd31466e
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/core/src/fmt/rt.rs:138:9
   5:     0x7f7d94f58dff - core::fmt::write::h456644d486ec276c
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f7d94eebb31 - std::io::Write::write_fmt::h2c3a3e95369085f2
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/std/src/io/mod.rs:1712:15
   7:     0x7f7d94ef86e5 - std::sys_common::backtrace::_print::h4a02a819355b63b1
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f7d94ef86e5 - std::sys_common::backtrace::print::h07577b83e8248693
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f7d94efb357 - std::panicking::default_hook::{{closure}}::hcb1bab104892ac31
  10:     0x7f7d94efb144 - std::panicking::default_hook::h0cc6f3347f4b8e64
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/std/src/panicking.rs:288:9
  11:     0x7f7d9808b3eb - <rustc_driver_impl[ad949ce21acad6aa]::install_ice_hook::{closure#0} as core[70e66fa3f6a59150]::ops::function::FnOnce<(&core[70e66fa3f6a59150]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7f7d94efba77 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h395b77e0b7687b27
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/alloc/src/boxed.rs:1999:9
  13:     0x7f7d94efba77 - std::panicking::rust_panic_with_hook::hfc3e471ec066cbc7
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/std/src/panicking.rs:695:13
  14:     0x7f7d982592f1 - std[c32680bc03d28d92]::panicking::begin_panic::<rustc_errors[235823ae0a7a21f8]::ExplicitBug>::{closure#0}
  15:     0x7f7d98257906 - std[c32680bc03d28d92]::sys_common::backtrace::__rust_end_short_backtrace::<std[c32680bc03d28d92]::panicking::begin_panic<rustc_errors[235823ae0a7a21f8]::ExplicitBug>::{closure#0}, !>
  16:     0x7f7d982b4746 - std[c32680bc03d28d92]::panicking::begin_panic::<rustc_errors[235823ae0a7a21f8]::ExplicitBug>
  17:     0x7f7d9827d5ee - <rustc_errors[235823ae0a7a21f8]::HandlerInner>::span_bug::<rustc_span[5a6c4eb39851ad60]::span_encoding::Span, alloc[758fbeec409bf174]::string::String>
  18:     0x7f7d9827d30d - <rustc_errors[235823ae0a7a21f8]::Handler>::span_bug::<rustc_span[5a6c4eb39851ad60]::span_encoding::Span, alloc[758fbeec409bf174]::string::String>
  19:     0x7f7d9826fc9d - rustc_middle[b7bed123b8e7ee66]::util::bug::opt_span_bug_fmt::<rustc_span[5a6c4eb39851ad60]::span_encoding::Span>::{closure#0}
  20:     0x7f7d9826fcca - rustc_middle[b7bed123b8e7ee66]::ty::context::tls::with_opt::<rustc_middle[b7bed123b8e7ee66]::util::bug::opt_span_bug_fmt<rustc_span[5a6c4eb39851ad60]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f7d9826c9da - rustc_middle[b7bed123b8e7ee66]::ty::context::tls::with_context_opt::<rustc_middle[b7bed123b8e7ee66]::ty::context::tls::with_opt<rustc_middle[b7bed123b8e7ee66]::util::bug::opt_span_bug_fmt<rustc_span[5a6c4eb39851ad60]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f7d966edc54 - rustc_middle[b7bed123b8e7ee66]::util::bug::span_bug_fmt::<rustc_span[5a6c4eb39851ad60]::span_encoding::Span>
  23:     0x7f7d9671a947 - <rustc_hir_typeck[5a077f7a366a5759]::method::confirm::ConfirmContext>::confirm
  24:     0x7f7d966cdecf - <rustc_hir_typeck[5a077f7a366a5759]::fn_ctxt::FnCtxt>::lookup_method
  25:     0x7f7d966bab19 - <rustc_hir_typeck[5a077f7a366a5759]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7f7d966fdaab - <rustc_hir_typeck[5a077f7a366a5759]::fn_ctxt::FnCtxt>::check_block_with_expected
  27:     0x7f7d966baa23 - <rustc_hir_typeck[5a077f7a366a5759]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x7f7d96bcee36 - <rustc_hir_typeck[5a077f7a366a5759]::fn_ctxt::FnCtxt>::check_return_expr
  29:     0x7f7d96bc696f - rustc_hir_typeck[5a077f7a366a5759]::check::check_fn
  30:     0x7f7d96bae63a - rustc_hir_typeck[5a077f7a366a5759]::typeck
  31:     0x7f7d9616a84e - rustc_query_impl[9a7ca49561e662fc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9a7ca49561e662fc]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b7bed123b8e7ee66]::query::erase::Erased<[u8; 8usize]>>
  32:     0x7f7d9616a81e - <rustc_query_impl[9a7ca49561e662fc]::query_impl::typeck::dynamic_query::{closure#2} as core[70e66fa3f6a59150]::ops::function::FnOnce<(rustc_middle[b7bed123b8e7ee66]::ty::context::TyCtxt, rustc_span[5a6c4eb39851ad60]::def_id::LocalDefId)>>::call_once
  33:     0x7f7d9691043d - rustc_query_system[6b3c15b25f26c51f]::query::plumbing::try_execute_query::<rustc_query_impl[9a7ca49561e662fc]::DynamicConfig<rustc_query_system[6b3c15b25f26c51f]::query::caches::VecCache<rustc_span[5a6c4eb39851ad60]::def_id::LocalDefId, rustc_middle[b7bed123b8e7ee66]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9a7ca49561e662fc]::plumbing::QueryCtxt, true>
  34:     0x7f7d97a799ea - rustc_query_impl[9a7ca49561e662fc]::query_impl::typeck::get_query_incr::__rust_end_short_backtrace
  35:     0x7f7d962c0f5d - rustc_query_impl[9a7ca49561e662fc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9a7ca49561e662fc]::query_impl::used_trait_imports::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b7bed123b8e7ee66]::query::erase::Erased<[u8; 8usize]>>
  36:     0x7f7d962c0ebe - <rustc_query_impl[9a7ca49561e662fc]::query_impl::used_trait_imports::dynamic_query::{closure#2} as core[70e66fa3f6a59150]::ops::function::FnOnce<(rustc_middle[b7bed123b8e7ee66]::ty::context::TyCtxt, rustc_span[5a6c4eb39851ad60]::def_id::LocalDefId)>>::call_once
  37:     0x7f7d9691043d - rustc_query_system[6b3c15b25f26c51f]::query::plumbing::try_execute_query::<rustc_query_impl[9a7ca49561e662fc]::DynamicConfig<rustc_query_system[6b3c15b25f26c51f]::query::caches::VecCache<rustc_span[5a6c4eb39851ad60]::def_id::LocalDefId, rustc_middle[b7bed123b8e7ee66]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9a7ca49561e662fc]::plumbing::QueryCtxt, true>
  38:     0x7f7d97a2e8ca - rustc_query_impl[9a7ca49561e662fc]::query_impl::used_trait_imports::get_query_incr::__rust_end_short_backtrace
  39:     0x7f7d97564e30 - rustc_hir_analysis[eb5c2b720aa6aa8]::check_crate
  40:     0x7f7d9755fa2d - rustc_interface[b4b865babd3476ac]::passes::analysis
  41:     0x7f7d975bfa9a - rustc_query_impl[9a7ca49561e662fc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9a7ca49561e662fc]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b7bed123b8e7ee66]::query::erase::Erased<[u8; 1usize]>>
  42:     0x7f7d975bfa89 - <rustc_query_impl[9a7ca49561e662fc]::query_impl::analysis::dynamic_query::{closure#2} as core[70e66fa3f6a59150]::ops::function::FnOnce<(rustc_middle[b7bed123b8e7ee66]::ty::context::TyCtxt, ())>>::call_once
  43:     0x7f7d978bbe65 - rustc_query_system[6b3c15b25f26c51f]::query::plumbing::try_execute_query::<rustc_query_impl[9a7ca49561e662fc]::DynamicConfig<rustc_query_system[6b3c15b25f26c51f]::query::caches::SingleCache<rustc_middle[b7bed123b8e7ee66]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9a7ca49561e662fc]::plumbing::QueryCtxt, true>
  44:     0x7f7d978bba54 - rustc_query_impl[9a7ca49561e662fc]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  45:     0x7f7d9775acdf - <rustc_middle[b7bed123b8e7ee66]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[ad949ce21acad6aa]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[70e66fa3f6a59150]::result::Result<(), rustc_span[5a6c4eb39851ad60]::ErrorGuaranteed>>
  46:     0x7f7d9732073f - <rustc_interface[b4b865babd3476ac]::interface::Compiler>::enter::<rustc_driver_impl[ad949ce21acad6aa]::run_compiler::{closure#1}::{closure#2}, core[70e66fa3f6a59150]::result::Result<core[70e66fa3f6a59150]::option::Option<rustc_interface[b4b865babd3476ac]::queries::Linker>, rustc_span[5a6c4eb39851ad60]::ErrorGuaranteed>>
  47:     0x7f7d9731e50d - <scoped_tls[471f6c29b29f8c7e]::ScopedKey<rustc_span[5a6c4eb39851ad60]::SessionGlobals>>::set::<rustc_interface[b4b865babd3476ac]::interface::run_compiler<core[70e66fa3f6a59150]::result::Result<(), rustc_span[5a6c4eb39851ad60]::ErrorGuaranteed>, rustc_driver_impl[ad949ce21acad6aa]::run_compiler::{closure#1}>::{closure#0}, core[70e66fa3f6a59150]::result::Result<(), rustc_span[5a6c4eb39851ad60]::ErrorGuaranteed>>
  48:     0x7f7d9731d966 - std[c32680bc03d28d92]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b4b865babd3476ac]::util::run_in_thread_pool_with_globals<rustc_interface[b4b865babd3476ac]::interface::run_compiler<core[70e66fa3f6a59150]::result::Result<(), rustc_span[5a6c4eb39851ad60]::ErrorGuaranteed>, rustc_driver_impl[ad949ce21acad6aa]::run_compiler::{closure#1}>::{closure#0}, core[70e66fa3f6a59150]::result::Result<(), rustc_span[5a6c4eb39851ad60]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[70e66fa3f6a59150]::result::Result<(), rustc_span[5a6c4eb39851ad60]::ErrorGuaranteed>>
  49:     0x7f7d97949195 - <<std[c32680bc03d28d92]::thread::Builder>::spawn_unchecked_<rustc_interface[b4b865babd3476ac]::util::run_in_thread_pool_with_globals<rustc_interface[b4b865babd3476ac]::interface::run_compiler<core[70e66fa3f6a59150]::result::Result<(), rustc_span[5a6c4eb39851ad60]::ErrorGuaranteed>, rustc_driver_impl[ad949ce21acad6aa]::run_compiler::{closure#1}>::{closure#0}, core[70e66fa3f6a59150]::result::Result<(), rustc_span[5a6c4eb39851ad60]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[70e66fa3f6a59150]::result::Result<(), rustc_span[5a6c4eb39851ad60]::ErrorGuaranteed>>::{closure#1} as core[70e66fa3f6a59150]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:     0x7f7d94f05f25 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf2094822989e0f14
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/alloc/src/boxed.rs:1985:9
  51:     0x7f7d94f05f25 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hda3729a280695d83
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/alloc/src/boxed.rs:1985:9
  52:     0x7f7d94f05f25 - std::sys::unix::thread::Thread::new::thread_start::h20e4fb469ede5e8c
                               at /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/library/std/src/sys/unix/thread.rs:108:17
  53:     0x7f7d94dc4ea7 - start_thread
  54:     0x7f7d94ce2a2f - clone
  55:                0x0 - <unknown>

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.71.0-nightly (9d871b061 2023-05-21) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [typeck] type-checking `main`
#1 [used_trait_imports] finding used_trait_imports `main`
#2 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `ice` (bin "ice")
Backtrace

RUST_BACKTRACE=1 cargo build
   Compiling ice v0.1.0 (/tmp/ice)
error: internal compiler error: compiler/rustc_hir_typeck/src/method/confirm.rs:486:17: Foo was a subtype of &Foo but now is not?
  --> src/main.rs:13:9
   |
13 |     foo.get::<&Foo>(); // ICE
   |         ^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/9d871b0617a4b3d6610b7cee0ab5310dcb542c62/compiler/rustc_errors/src/lib.rs:994:33
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::HandlerInner>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   2: <rustc_errors::Handler>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_hir_typeck::method::confirm::ConfirmContext>::confirm
   8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::lookup_method
   9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
  11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
  13: rustc_hir_typeck::check::check_fn
  14: rustc_hir_typeck::typeck
  15: rustc_hir_analysis::check_crate
  16: rustc_interface::passes::analysis
  17: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#4}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
  18: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
  19: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<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>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.71.0-nightly (9d871b061 2023-05-21) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [typeck] type-checking `main`
#1 [used_trait_imports] finding used_trait_imports `main`
#2 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `ice` (bin "ice")

@BattyBoopers BattyBoopers 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 May 22, 2023
@BattyBoopers BattyBoopers changed the title ICE calling generic method with explicitly constrained self parameter ICE calling generic method with explicitly provided self parameter May 22, 2023
@BattyBoopers
Copy link
Author

@rustbot label +F-arbitrary_self_types

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-arbitrary_self_types `#![feature(arbitrary_self_types)]` 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.

3 participants