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: Foo was a subtype of &Foo but now is not? #117379

Closed
matthiaskrgr opened this issue Oct 30, 2023 · 2 comments · Fixed by #117403
Closed

ICE: Foo was a subtype of &Foo but now is not? #117379

matthiaskrgr opened this issue Oct 30, 2023 · 2 comments · Fixed by #117403
Assignees
Labels
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.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

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

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

original:

#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord,
         Debug, Default, Copy)]

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>();
    //~^ ERROR mismatched types
}

Version information

rustc 1.75.0-nightly (bcb5798dd 2023-10-30)
binary: rustc
commit-hash: bcb5798dd890a691644af9d371f3bd7fcc465584
commit-date: 2023-10-30
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0307]: invalid `self` parameter type: R
 --> /tmp/icemaker_global_tempdir.UiXGlnwFiTMm/rustc_testrunner_tmpdir_reporting.qpHEuYT5OkHH/mvce.rs:3:21
  |
3 |     fn get<R>(self: R) -> u32 {
  |                     ^
  |
  = note: type of `self` must be `Self` or a type that dereferences to it
  = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)

error[E0609]: no field `0` on type `R`
 --> /tmp/icemaker_global_tempdir.UiXGlnwFiTMm/rustc_testrunner_tmpdir_reporting.qpHEuYT5OkHH/mvce.rs:4:14
  |
3 |     fn get<R>(self: R) -> u32 {
  |            - type parameter 'R' declared here
4 |         self.0
  |              ^

error: internal compiler error: compiler/rustc_hir_typeck/src/method/confirm.rs:518:21: Foo was a subtype of &Foo but now is not?
  --> /tmp/icemaker_global_tempdir.UiXGlnwFiTMm/rustc_testrunner_tmpdir_reporting.qpHEuYT5OkHH/mvce.rs:10:9
   |
10 |     foo.get::<&Foo>();
   |         ^^^

thread 'rustc' panicked at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/compiler/rustc_errors/src/lib.rs:1000:33:
Box<dyn Any>
stack backtrace:
   0:     0x7fbd04169cfc - std::backtrace_rs::backtrace::libunwind::trace::h696e701df900a2b2
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fbd04169cfc - std::backtrace_rs::backtrace::trace_unsynchronized::h0a821b5067328428
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fbd04169cfc - std::sys_common::backtrace::_print_fmt::h561ba93d7dd378a2
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fbd04169cfc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hadaea2aacdfa4b18
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fbd041cbf50 - core::fmt::rt::Argument::fmt::haaf2e1dae680d0d4
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/core/src/fmt/rt.rs:142:9
   5:     0x7fbd041cbf50 - core::fmt::write::h92a090160f936a3a
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/core/src/fmt/mod.rs:1117:17
   6:     0x7fbd0415db8f - std::io::Write::write_fmt::h304b2c71e3a57237
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/io/mod.rs:1763:15
   7:     0x7fbd04169ae4 - std::sys_common::backtrace::_print::h805cb7447553b9fa
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fbd04169ae4 - std::sys_common::backtrace::print::h7be441b9aecf7507
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fbd0416c777 - std::panicking::default_hook::{{closure}}::hf0f1687c23b85f00
  10:     0x7fbd0416c4df - std::panicking::default_hook::h1aa7ed866efb6ff4
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/panicking.rs:292:9
  11:     0x7fbd06ce0b80 - std[52b4fac2c1cd6916]::panicking::update_hook::<alloc[b6c0ed09a4f055cf]::boxed::Box<rustc_driver_impl[f6d8c9ab4fbb7a4c]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fbd0416ceb8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::ha095ea6a5339338c
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/alloc/src/boxed.rs:2021:9
  13:     0x7fbd0416ceb8 - std::panicking::rust_panic_with_hook::h96c03960eff56a0b
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/panicking.rs:783:13
  14:     0x7fbd06e3ecb4 - std[52b4fac2c1cd6916]::panicking::begin_panic::<rustc_errors[56af66a7435c2564]::ExplicitBug>::{closure#0}
  15:     0x7fbd06e2b3a6 - std[52b4fac2c1cd6916]::sys_common::backtrace::__rust_end_short_backtrace::<std[52b4fac2c1cd6916]::panicking::begin_panic<rustc_errors[56af66a7435c2564]::ExplicitBug>::{closure#0}, !>
  16:     0x7fbd06e1e3e6 - std[52b4fac2c1cd6916]::panicking::begin_panic::<rustc_errors[56af66a7435c2564]::ExplicitBug>
  17:     0x7fbd06e11ffe - <rustc_errors[56af66a7435c2564]::HandlerInner>::span_bug::<rustc_span[219ab52d13232863]::span_encoding::Span, alloc[b6c0ed09a4f055cf]::string::String>
  18:     0x7fbd06e11d3b - <rustc_errors[56af66a7435c2564]::Handler>::span_bug::<rustc_span[219ab52d13232863]::span_encoding::Span, alloc[b6c0ed09a4f055cf]::string::String>
  19:     0x7fbd06e3eefb - rustc_middle[13e6374ce232bd81]::util::bug::opt_span_bug_fmt::<rustc_span[219ab52d13232863]::span_encoding::Span>::{closure#0}
  20:     0x7fbd06e41d0a - rustc_middle[13e6374ce232bd81]::ty::context::tls::with_opt::<rustc_middle[13e6374ce232bd81]::util::bug::opt_span_bug_fmt<rustc_span[219ab52d13232863]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7fbd06e32868 - rustc_middle[13e6374ce232bd81]::ty::context::tls::with_context_opt::<rustc_middle[13e6374ce232bd81]::ty::context::tls::with_opt<rustc_middle[13e6374ce232bd81]::util::bug::opt_span_bug_fmt<rustc_span[219ab52d13232863]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7fbd06056834 - rustc_middle[13e6374ce232bd81]::util::bug::span_bug_fmt::<rustc_span[219ab52d13232863]::span_encoding::Span>
  23:     0x7fbd08a3bd54 - <rustc_hir_typeck[8394991fd8d3c9ab]::method::confirm::ConfirmContext>::confirm
  24:     0x7fbd08a3140f - <rustc_hir_typeck[8394991fd8d3c9ab]::fn_ctxt::FnCtxt>::lookup_method
  25:     0x7fbd0884b3bc - <rustc_hir_typeck[8394991fd8d3c9ab]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7fbd083970d9 - <rustc_hir_typeck[8394991fd8d3c9ab]::fn_ctxt::FnCtxt>::check_block_with_expected
  27:     0x7fbd0884b2f0 - <rustc_hir_typeck[8394991fd8d3c9ab]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x7fbd086b3a3f - rustc_hir_typeck[8394991fd8d3c9ab]::check::check_fn
  29:     0x7fbd08134354 - rustc_hir_typeck[8394991fd8d3c9ab]::typeck
  30:     0x7fbd081337c7 - rustc_query_impl[d72368bb483549e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d72368bb483549e]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 8usize]>>
  31:     0x7fbd07f4aa2c - rustc_query_system[7f1cfd16d8bae603]::query::plumbing::try_execute_query::<rustc_query_impl[d72368bb483549e]::DynamicConfig<rustc_query_system[7f1cfd16d8bae603]::query::caches::VecCache<rustc_span[219ab52d13232863]::def_id::LocalDefId, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d72368bb483549e]::plumbing::QueryCtxt, false>
  32:     0x7fbd07f4a710 - rustc_query_impl[d72368bb483549e]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7fbd083226d9 - rustc_hir_analysis[1263226015b2b1b2]::check_crate
  34:     0x7fbd08612796 - rustc_interface[6394f483f79c51a]::passes::analysis
  35:     0x7fbd086121b5 - rustc_query_impl[d72368bb483549e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d72368bb483549e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 1usize]>>
  36:     0x7fbd089231e6 - rustc_query_system[7f1cfd16d8bae603]::query::plumbing::try_execute_query::<rustc_query_impl[d72368bb483549e]::DynamicConfig<rustc_query_system[7f1cfd16d8bae603]::query::caches::SingleCache<rustc_middle[13e6374ce232bd81]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d72368bb483549e]::plumbing::QueryCtxt, false>
  37:     0x7fbd08923015 - rustc_query_impl[d72368bb483549e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7fbd08b1aeb4 - std[52b4fac2c1cd6916]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6394f483f79c51a]::util::run_in_thread_with_globals<rustc_interface[6394f483f79c51a]::interface::run_compiler<core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>, rustc_driver_impl[f6d8c9ab4fbb7a4c]::run_compiler::{closure#1}>::{closure#0}, core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>>
  39:     0x7fbd08b1a173 - <<std[52b4fac2c1cd6916]::thread::Builder>::spawn_unchecked_<rustc_interface[6394f483f79c51a]::util::run_in_thread_with_globals<rustc_interface[6394f483f79c51a]::interface::run_compiler<core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>, rustc_driver_impl[f6d8c9ab4fbb7a4c]::run_compiler::{closure#1}>::{closure#0}, core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[68a6506991500897]::result::Result<(), rustc_span[219ab52d13232863]::ErrorGuaranteed>>::{closure#1} as core[68a6506991500897]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:     0x7fbd04177c85 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5c45b6a24e5f1474
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/alloc/src/boxed.rs:2007:9
  41:     0x7fbd04177c85 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h18b35e832435abd8
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/alloc/src/boxed.rs:2007:9
  42:     0x7fbd04177c85 - std::sys::unix::thread::Thread::new::thread_start::h4880d4dbe7e5215f
                               at /rustc/bcb5798dd890a691644af9d371f3bd7fcc465584/library/std/src/sys/unix/thread.rs:108:17
  43:     0x7fbd03f419eb - <unknown>
  44:     0x7fbd03fc57cc - <unknown>
  45:                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.75.0-nightly (bcb5798dd 2023-10-30) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

@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 Oct 30, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 30, 2023
@matthiaskrgr matthiaskrgr changed the title ICE: `Foo was a subtype of &Foo but now is not? ICE: Foo was a subtype of &Foo but now is not? Oct 30, 2023
@matthiaskrgr
Copy link
Member Author

hello #116849 my old friend... ping @oli-obk :D

@oli-obk
Copy link
Contributor

oli-obk commented Oct 30, 2023

😅 the gift that keeps giving

@oli-obk oli-obk self-assigned this Oct 30, 2023
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 30, 2023
@bors bors closed this as completed in 24c6b6c Oct 30, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 30, 2023
Rollup merge of rust-lang#117403 - oli-obk:the_gift_that_keeps_on_giving_116849, r=compiler-errors

Poison check_well_formed if method receivers are invalid to prevent typeck from running on it

fixes rust-lang#117379

Though if some code invokes typeck without having first invoked `check_well_formed` then we'll encounter this ICE again. This can happen in const and const fn bodies if they are evaluated due to other `check_well_formed` checks or similar
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants