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 calling method on auto trait #105732

Closed
jruderman opened this issue Dec 15, 2022 · 2 comments · Fixed by #105747
Closed

ICE calling method on auto trait #105732

jruderman opened this issue Dec 15, 2022 · 2 comments · Fixed by #105747
Assignees
Labels
C-bug Category: This is a bug. F-auto_traits `#![feature(auto_traits)]` 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

@jruderman
Copy link
Contributor

jruderman commented Dec 15, 2022

Found with a modified fuzz-rustc

Code

#![feature(auto_traits)]

auto trait Foo {
    fn g(&self);
}

trait Bar {
    fn f(&self) {
        self.g();
    }
}

fn main() {}

Error output

error[E0380]: auto traits cannot have associated items

thread 'rustc' panicked at 'internal error: entered unreachable code', compiler/rustc_hir_typeck/src/method/suggest.rs:691

Full output including backtrace
error[E0380]: auto traits cannot have associated items
 --> f2db.rs:4:8
  |
3 | auto trait Foo {
  |            --- auto trait cannot have associated items
4 |     fn g(&self);
  |     ---^-------- help: remove these associated items

thread 'rustc' panicked at 'internal error: entered unreachable code', compiler/rustc_hir_typeck/src/method/suggest.rs:691:40
stack backtrace:
   0:        0x1060ad731 - ___fixunssfsi
   1:        0x106138b08 - core::fmt::write::hed31846cddb4e13c
   2:        0x106084b28 - std::io::Write::write_fmt::hf6e0f2914bebea98
   3:        0x1060ad522 - std::sys_common::backtrace::print::h905a3d11750ea1e9
   4:        0x1060bdd35 - std::panicking::default_hook::{{closure}}::he83c590da184b003
   5:        0x1060bdb1e - std::panicking::default_hook::hd8c8acc029e0c8cd
   6:        0x112ca3ae8 - rustc_driver[75b940a0d44b1efd]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x1060be526 - std::panicking::rust_panic_with_hook::h0cf82b3605a8081f
   8:        0x1060aca52 - std::panicking::begin_panic_handler::{{closure}}::h7d24d0bcbcd0c8c3
   9:        0x1060ac9c8 - std::sys_common::backtrace::__rust_end_short_backtrace::h584365ffa1be1317
  10:        0x1060bde08 - _rust_begin_unwind
  11:        0x10615d483 - core::panicking::panic_fmt::h7ec57a9a63e6db71
  12:        0x10615d557 - core::panicking::panic::h604eaa4391462ac9
  13:        0x115694776 - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::report_method_error
  14:        0x1156bcb23 - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::check_expr_kind
  15:        0x115663617 - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  16:        0x1156babd4 - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  17:        0x11567ea8c - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::check_stmt
  18:        0x1155b6a96 - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::with_breakable_ctxt::<<rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::check_block_with_expected::{closure#0}, ()>
  19:        0x11567ed4d - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::check_block_with_expected
  20:        0x1156bbf9f - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::check_expr_kind
  21:        0x115663617 - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  22:        0x1156babd4 - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  23:        0x1156652df - <rustc_hir_typeck[b7aa618f0b708977]::fn_ctxt::FnCtxt>::check_return_expr
  24:        0x1156425c2 - rustc_hir_typeck[b7aa618f0b708977]::check::check_fn
  25:        0x115567200 - <rustc_hir_typeck[b7aa618f0b708977]::inherited::InheritedBuilder>::enter::<rustc_hir_typeck[b7aa618f0b708977]::typeck_with_fallback<rustc_hir_typeck[b7aa618f0b708977]::typeck::{closure#0}>::{closure#0}::{closure#1}, &rustc_middle[2716ddfd79b0a8a6]::ty::context::TypeckResults>
  26:        0x11561aef5 - rustc_hir_typeck[b7aa618f0b708977]::typeck_with_fallback::<rustc_hir_typeck[b7aa618f0b708977]::typeck::{closure#0}>
  27:        0x11564c46f - rustc_hir_typeck[b7aa618f0b708977]::typeck
  28:        0x116d59d6b - rustc_query_system[47b5c57ee62d79cf]::query::plumbing::try_execute_query::<rustc_query_impl[6353a2785d754f42]::plumbing::QueryCtxt, rustc_query_system[47b5c57ee62d79cf]::query::caches::VecCache<rustc_span[c887fc7c2a0a81b]::def_id::LocalDefId, &rustc_middle[2716ddfd79b0a8a6]::ty::context::TypeckResults>>
  29:        0x116e5862e - rustc_query_system[47b5c57ee62d79cf]::query::plumbing::get_query::<rustc_query_impl[6353a2785d754f42]::queries::typeck, rustc_query_impl[6353a2785d754f42]::plumbing::QueryCtxt>
  30:        0x116ade03f - <rustc_query_impl[6353a2785d754f42]::Queries as rustc_middle[2716ddfd79b0a8a6]::ty::query::QueryEngine>::typeck
  31:        0x115626b13 - <core[95bb6d661b676f4d]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[49afb3d772895c69]::sync::par_for_each_in<&[rustc_span[c887fc7c2a0a81b]::def_id::LocalDefId], <rustc_middle[2716ddfd79b0a8a6]::hir::map::Map>::par_body_owners<rustc_hir_typeck[b7aa618f0b708977]::typeck_item_bodies::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}> as core[95bb6d661b676f4d]::ops::function::FnOnce<()>>::call_once
  32:        0x11564aad0 - std[150eb488e385df0f]::panicking::try::<(), core[95bb6d661b676f4d]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[49afb3d772895c69]::sync::par_for_each_in<&[rustc_span[c887fc7c2a0a81b]::def_id::LocalDefId], <rustc_middle[2716ddfd79b0a8a6]::hir::map::Map>::par_body_owners<rustc_hir_typeck[b7aa618f0b708977]::typeck_item_bodies::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>>
  33:        0x115722153 - rustc_data_structures[49afb3d772895c69]::sync::par_for_each_in::<&[rustc_span[c887fc7c2a0a81b]::def_id::LocalDefId], <rustc_middle[2716ddfd79b0a8a6]::hir::map::Map>::par_body_owners<rustc_hir_typeck[b7aa618f0b708977]::typeck_item_bodies::{closure#0}>::{closure#0}>
  34:        0x11564c22a - rustc_hir_typeck[b7aa618f0b708977]::typeck_item_bodies
  35:        0x116d38427 - rustc_query_system[47b5c57ee62d79cf]::query::plumbing::try_execute_query::<rustc_query_impl[6353a2785d754f42]::plumbing::QueryCtxt, rustc_query_system[47b5c57ee62d79cf]::query::caches::DefaultCache<(), ()>>
  36:        0x116e1145d - rustc_query_system[47b5c57ee62d79cf]::query::plumbing::get_query::<rustc_query_impl[6353a2785d754f42]::queries::typeck_item_bodies, rustc_query_impl[6353a2785d754f42]::plumbing::QueryCtxt>
  37:        0x116add9d7 - <rustc_query_impl[6353a2785d754f42]::Queries as rustc_middle[2716ddfd79b0a8a6]::ty::query::QueryEngine>::typeck_item_bodies
  38:        0x1158c9245 - <rustc_session[9e89c47467305ea5]::session::Session>::time::<(), rustc_hir_analysis[39115411e53478da]::check_crate::{closure#7}>
  39:        0x1158a97ee - rustc_hir_analysis[39115411e53478da]::check_crate
  40:        0x112e423ea - rustc_interface[3c94b850180ed4ea]::passes::analysis
  41:        0x116d28658 - rustc_query_system[47b5c57ee62d79cf]::query::plumbing::try_execute_query::<rustc_query_impl[6353a2785d754f42]::plumbing::QueryCtxt, rustc_query_system[47b5c57ee62d79cf]::query::caches::DefaultCache<(), core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>>>
  42:        0x116e589dd - rustc_query_system[47b5c57ee62d79cf]::query::plumbing::get_query::<rustc_query_impl[6353a2785d754f42]::queries::analysis, rustc_query_impl[6353a2785d754f42]::plumbing::QueryCtxt>
  43:        0x116aba127 - <rustc_query_impl[6353a2785d754f42]::Queries as rustc_middle[2716ddfd79b0a8a6]::ty::query::QueryEngine>::analysis
  44:        0x112cb2ff4 - <rustc_interface[3c94b850180ed4ea]::passes::QueryContext>::enter::<rustc_driver[75b940a0d44b1efd]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>>
  45:        0x112c93b3d - <rustc_interface[3c94b850180ed4ea]::interface::Compiler>::enter::<rustc_driver[75b940a0d44b1efd]::run_compiler::{closure#1}::{closure#2}, core[95bb6d661b676f4d]::result::Result<core[95bb6d661b676f4d]::option::Option<rustc_interface[3c94b850180ed4ea]::queries::Linker>, rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>>
  46:        0x112c91241 - rustc_span[c887fc7c2a0a81b]::with_source_map::<core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>, rustc_interface[3c94b850180ed4ea]::interface::run_compiler<core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>, rustc_driver[75b940a0d44b1efd]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  47:        0x112cdef0a - <scoped_tls[c451c38e2ed76225]::ScopedKey<rustc_span[c887fc7c2a0a81b]::SessionGlobals>>::set::<rustc_interface[3c94b850180ed4ea]::interface::run_compiler<core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>, rustc_driver[75b940a0d44b1efd]::run_compiler::{closure#1}>::{closure#0}, core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>>
  48:        0x112cae0a0 - std[150eb488e385df0f]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[3c94b850180ed4ea]::util::run_in_thread_pool_with_globals<rustc_interface[3c94b850180ed4ea]::interface::run_compiler<core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>, rustc_driver[75b940a0d44b1efd]::run_compiler::{closure#1}>::{closure#0}, core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>>
  49:        0x112cd1810 - std[150eb488e385df0f]::panicking::try::<core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>, core[95bb6d661b676f4d]::panic::unwind_safe::AssertUnwindSafe<<std[150eb488e385df0f]::thread::Builder>::spawn_unchecked_<rustc_interface[3c94b850180ed4ea]::util::run_in_thread_pool_with_globals<rustc_interface[3c94b850180ed4ea]::interface::run_compiler<core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>, rustc_driver[75b940a0d44b1efd]::run_compiler::{closure#1}>::{closure#0}, core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
  50:        0x112cce071 - <<std[150eb488e385df0f]::thread::Builder>::spawn_unchecked_<rustc_interface[3c94b850180ed4ea]::util::run_in_thread_pool_with_globals<rustc_interface[3c94b850180ed4ea]::interface::run_compiler<core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>, rustc_driver[75b940a0d44b1efd]::run_compiler::{closure#1}>::{closure#0}, core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[95bb6d661b676f4d]::result::Result<(), rustc_errors[dcd2348bee1b0385]::ErrorGuaranteed>>::{closure#1} as core[95bb6d661b676f4d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:        0x10608107b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h363a7f79aa0064c8
  52:        0x1060b889f - std::sys::unix::thread::Thread::new::thread_start::hee5a1e4745806fcc
  53:     0x7ff80c3874e1 - __pthread_start

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.68.0-dev running on x86_64-apple-darwin

query stack during panic:
#0 [typeck] type-checking `Bar::f`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0380`.

Regression

Regression in nightly-2022-11-05, somewhere in rollup 0950848, likely #103937 (CC @BoxyUwU)

Version

2022-12-14 fbf8b93

@rustbot label +F-auto_traits

@jruderman jruderman 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 Dec 15, 2022
@rustbot rustbot added the F-auto_traits `#![feature(auto_traits)]` label Dec 15, 2022
@chenyukang
Copy link
Member

@rustbot claim

@chenyukang
Copy link
Member

Fixed the ICE, the error message now is:

cat@LAPTOP-V6U0QKD4:~/code/rust$ j dev         src/test/ui/methods/issues/issue-105732.rs
rustc +dev src/test/ui/methods/issues/issue-105732.rs
error[E0380]: auto traits cannot have associated items
 --> src/test/ui/methods/issues/issue-105732.rs:4:8
  |
3 | auto trait Foo {
  |            --- auto trait cannot have associated items
4 |     fn g(&self); //~ ERROR auto traits cannot have associated items
  |     ---^-------- help: remove these associated items

error[E0599]: the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
 --> src/test/ui/methods/issues/issue-105732.rs:9:14
  |
9 |         self.g();
  |              ^
  |
  = note: the following trait bounds were not satisfied:
          `Self: Foo`
          which is required by `&Self: Foo`
          `&Self: Foo`
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `g`, perhaps you need to add a supertrait for it:
  |
7 | trait Bar: Foo {
  |          +++++

error: aborting due to 2 previous errors

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

I think the second error message should not come out, considering the Foo is an auto trait.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 16, 2022
…trait, r=compiler-errors

Fix ICE calling method on auto trait

Fixes rust-lang#105732
r? `@compiler-errors`
@bors bors closed this as completed in 605f77b Dec 16, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 3, 2023
…ror, r=compiler-errors

Refactoring report_method_error

While working on rust-lang#105732, I found it's hard to follow this long function,
so I tried to make it shorter.

It's not easy for code reviewing, since so many lines of code changes,
but only the positions are changed.

Generally, I extract two sub-methods from `report_method_error`:

https://github.com/rust-lang/rust/blob/397b66e77b279de5006facf87979f9ecff5c7f87/compiler/rustc_hir_typeck/src/method/suggest.rs#L117
to `note_candidates_on_method_error`

And this long block:
https://github.com/rust-lang/rust/blob/397b66e77b279de5006facf87979f9ecff5c7f87/compiler/rustc_hir_typeck/src/method/suggest.rs#L263

to `report_no_match_method_error`.

r? `@compiler-errors`
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-auto_traits `#![feature(auto_traits)]` 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