Skip to content

ICE: failed to resolve instance for <Self as EnvFuture>::g #134336

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
matthiaskrgr opened this issue Dec 15, 2024 · 4 comments · Fixed by #135973
Closed

ICE: failed to resolve instance for <Self as EnvFuture>::g #134336

matthiaskrgr opened this issue Dec 15, 2024 · 4 comments · Fixed by #135973
Assignees
Labels
C-bug Category: This is a bug. F-explicit_tail_calls `#![feature(explicit_tail_calls)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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):

pub trait EnvFuture {
    type Item;

    fn g(a: String, b: &str) -> String {
        become a + b;
    }
}

original:

// Make sure that the mono-item collector does not crash when trying to
// instantiate a default impl of a method with lifetime parameters.
// See https://github.com/rust-lang/rust/issues/47309

//@ compile-flags:-Clink-dead-code
//@ build-pass

#![crate_type="rlib"]

pub trait EnvFuture {
    type Item;

    fn g(a: String, b: &str) -> String {
    become a + b; //~ error: `become` does not support operators
}
}

struct Foo;

impl<'a> EnvFuture for &'a Foo {
    type Item = ();
}

Version information

rustc 1.85.0-nightly (4790a435c 2024-12-15)
binary: rustc
commit-hash: 4790a435cbcb55c94ccdef51bf7a9b2e55824528
commit-date: 2024-12-15
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5

Possibly related line of code:

shrunk,
was_written,
path,
type_length,
});
} else {
span_bug!(
span_or_local_def_span(),
"failed to resolve instance for {}",
tcx.def_path_str_with_args(def_id, args)
)
}
}

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

Program output

error[E0658]: `become` expression is experimental
 --> /tmp/icemaker_global_tempdir.EkIxS0yajpO5/rustc_testrunner_tmpdir_reporting.lSa2HFI9vuXC/mvce.rs:5:9
  |
5 |         become a + b;
  |         ^^^^^^^^^^^^
  |
  = note: see issue #112788 <https://github.com/rust-lang/rust/issues/112788> for more information
  = help: add `#![feature(explicit_tail_calls)]` to the crate attributes to enable
  = note: this compiler was built on 2024-12-15; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.EkIxS0yajpO5/rustc_testrunner_tmpdir_reporting.lSa2HFI9vuXC/mvce.rs:7:2
  |
7 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.EkIxS0yajpO5/rustc_testrunner_tmpdir_reporting.lSa2HFI9vuXC/mvce.rs`

error: `become` does not support operators
 --> /tmp/icemaker_global_tempdir.EkIxS0yajpO5/rustc_testrunner_tmpdir_reporting.lSa2HFI9vuXC/mvce.rs:5:16
  |
5 |         become a + b;
  |                ^^^^^
  |
help: try using the method directly
  |
5 |         become (a).add(b);
  |                + ~~~~~~ +

error: internal compiler error: compiler/rustc_middle/src/ty/instance.rs:585:21: failed to resolve instance for <Self as EnvFuture>::g
 --> /tmp/icemaker_global_tempdir.EkIxS0yajpO5/rustc_testrunner_tmpdir_reporting.lSa2HFI9vuXC/mvce.rs:4:5
  |
4 |     fn g(a: String, b: &str) -> String {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_middle/src/ty/instance.rs:585:21:
Box<dyn Any>
stack backtrace:
   0:     0x7fa93f3a4c5a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::heb202b000efba683
   1:     0x7fa93fc13d66 - core::fmt::write::h4529572b8b32da24
   2:     0x7fa940c1db51 - std::io::Write::write_fmt::h1a906436cb206037
   3:     0x7fa93f3a4ab2 - std::sys::backtrace::BacktraceLock::print::h934abc86fa2dd260
   4:     0x7fa93f3a6faa - std::panicking::default_hook::{{closure}}::hfd4bbe50128406cd
   5:     0x7fa93f3a6df3 - std::panicking::default_hook::h25fd19fcd22c2e04
   6:     0x7fa93e4f9a68 - std[70002648da4681c1]::panicking::update_hook::<alloc[334d4c3039138aa]::boxed::Box<rustc_driver_impl[2cc745b14baadf]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7fa93f3a7768 - std::panicking::rust_panic_with_hook::h3f6d3ded85336e6b
   8:     0x7fa93e52f911 - std[70002648da4681c1]::panicking::begin_panic::<rustc_errors[196465616da871a4]::ExplicitBug>::{closure#0}
   9:     0x7fa93e524ab6 - std[70002648da4681c1]::sys::backtrace::__rust_end_short_backtrace::<std[70002648da4681c1]::panicking::begin_panic<rustc_errors[196465616da871a4]::ExplicitBug>::{closure#0}, !>
  10:     0x7fa93e52486f - std[70002648da4681c1]::panicking::begin_panic::<rustc_errors[196465616da871a4]::ExplicitBug>
  11:     0x7fa93e5398d1 - <rustc_errors[196465616da871a4]::diagnostic::BugAbort as rustc_errors[196465616da871a4]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7fa93ea9971c - <rustc_errors[196465616da871a4]::DiagCtxtHandle>::span_bug::<rustc_span[5501a71f8d28de35]::span_encoding::Span, alloc[334d4c3039138aa]::string::String>
  13:     0x7fa93eb30657 - rustc_middle[4552a92c16cacd81]::util::bug::opt_span_bug_fmt::<rustc_span[5501a71f8d28de35]::span_encoding::Span>::{closure#0}
  14:     0x7fa93eb1600a - rustc_middle[4552a92c16cacd81]::ty::context::tls::with_opt::<rustc_middle[4552a92c16cacd81]::util::bug::opt_span_bug_fmt<rustc_span[5501a71f8d28de35]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x7fa93eb15e9b - rustc_middle[4552a92c16cacd81]::ty::context::tls::with_context_opt::<rustc_middle[4552a92c16cacd81]::ty::context::tls::with_opt<rustc_middle[4552a92c16cacd81]::util::bug::opt_span_bug_fmt<rustc_span[5501a71f8d28de35]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x7fa93cfa5f07 - rustc_middle[4552a92c16cacd81]::util::bug::span_bug_fmt::<rustc_span[5501a71f8d28de35]::span_encoding::Span>
  17:     0x7fa9402d2284 - <rustc_middle[4552a92c16cacd81]::ty::instance::Instance>::expect_resolve
  18:     0x7fa93eb97fe8 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor>::needs_location
  19:     0x7fa94058cd42 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_expr
  20:     0x7fa94058af95 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_expr
  21:     0x7fa94058ae91 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_block
  22:     0x7fa94058b0df - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_expr
  23:     0x7fa94058af95 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_expr
  24:     0x7fa94058af95 - <rustc_mir_build[377f342b43331edb]::check_tail_calls::TailCallCkVisitor as rustc_middle[4552a92c16cacd81]::thir::visit::Visitor>::visit_expr
  25:     0x7fa94058a3f6 - rustc_mir_build[377f342b43331edb]::check_tail_calls::check_tail_calls
  26:     0x7fa94058a0af - rustc_query_impl[98026ab69133ca5a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[98026ab69133ca5a]::query_impl::check_tail_calls::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 1usize]>>
  27:     0x7fa94059b5c7 - rustc_query_system[c5a9321c1b201b0d]::query::plumbing::try_execute_query::<rustc_query_impl[98026ab69133ca5a]::DynamicConfig<rustc_data_structures[41b15b2b138651fb]::vec_cache::VecCache<rustc_span[5501a71f8d28de35]::def_id::LocalDefId, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[c5a9321c1b201b0d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[98026ab69133ca5a]::plumbing::QueryCtxt, false>
  28:     0x7fa94059b1c1 - rustc_query_impl[98026ab69133ca5a]::query_impl::check_tail_calls::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7fa94059fd39 - rustc_mir_build[377f342b43331edb]::build::mir_build
  30:     0x7fa93fc077d4 - rustc_mir_transform[f55849332dfb7241]::mir_built
  31:     0x7fa93fc07797 - rustc_query_impl[98026ab69133ca5a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[98026ab69133ca5a]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 8usize]>>
  32:     0x7fa93fe75711 - rustc_query_system[c5a9321c1b201b0d]::query::plumbing::try_execute_query::<rustc_query_impl[98026ab69133ca5a]::DynamicConfig<rustc_data_structures[41b15b2b138651fb]::vec_cache::VecCache<rustc_span[5501a71f8d28de35]::def_id::LocalDefId, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[c5a9321c1b201b0d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[98026ab69133ca5a]::plumbing::QueryCtxt, false>
  33:     0x7fa93fe752cd - rustc_query_impl[98026ab69133ca5a]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7fa93cc1e8e5 - rustc_mir_build[377f342b43331edb]::check_unsafety::check_unsafety
  35:     0x7fa9404f50e7 - rustc_query_impl[98026ab69133ca5a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[98026ab69133ca5a]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 0usize]>>
  36:     0x7fa9404f53a9 - rustc_query_system[c5a9321c1b201b0d]::query::plumbing::try_execute_query::<rustc_query_impl[98026ab69133ca5a]::DynamicConfig<rustc_data_structures[41b15b2b138651fb]::vec_cache::VecCache<rustc_span[5501a71f8d28de35]::def_id::LocalDefId, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 0usize]>, rustc_query_system[c5a9321c1b201b0d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[98026ab69133ca5a]::plumbing::QueryCtxt, false>
  37:     0x7fa9404f5011 - rustc_query_impl[98026ab69133ca5a]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7fa940053bb2 - rustc_interface[cf66c2394d3c8572]::passes::run_required_analyses
  39:     0x7fa940c0c91e - rustc_interface[cf66c2394d3c8572]::passes::analysis
  40:     0x7fa940c0c8ef - rustc_query_impl[98026ab69133ca5a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[98026ab69133ca5a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 0usize]>>
  41:     0x7fa940c41015 - rustc_query_system[c5a9321c1b201b0d]::query::plumbing::try_execute_query::<rustc_query_impl[98026ab69133ca5a]::DynamicConfig<rustc_query_system[c5a9321c1b201b0d]::query::caches::SingleCache<rustc_middle[4552a92c16cacd81]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[98026ab69133ca5a]::plumbing::QueryCtxt, false>
  42:     0x7fa940c40d4e - rustc_query_impl[98026ab69133ca5a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  43:     0x7fa940cb61b4 - rustc_interface[cf66c2394d3c8572]::interface::run_compiler::<(), rustc_driver_impl[2cc745b14baadf]::run_compiler::{closure#0}>::{closure#1}
  44:     0x7fa940b685db - std[70002648da4681c1]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_with_globals<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_pool_with_globals<rustc_interface[cf66c2394d3c8572]::interface::run_compiler<(), rustc_driver_impl[2cc745b14baadf]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  45:     0x7fa940b68a90 - <<std[70002648da4681c1]::thread::Builder>::spawn_unchecked_<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_with_globals<rustc_interface[cf66c2394d3c8572]::util::run_in_thread_pool_with_globals<rustc_interface[cf66c2394d3c8572]::interface::run_compiler<(), rustc_driver_impl[2cc745b14baadf]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[3b8d2fc2756ea0bb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  46:     0x7fa940b6a06f - std::sys::pal::unix::thread::Thread::new::thread_start::hdeaa41b2ac9b4ad7
  47:     0x7fa93aca339d - <unknown>
  48:     0x7fa93ad2849c - <unknown>
  49:                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: please make sure that you have updated to the latest nightly

note: rustc 1.85.0-nightly (4790a435c 2024-12-15) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_tail_calls] tail-call-checking `EnvFuture::g`
#1 [mir_built] building MIR for `EnvFuture::g`
end of query stack
error: aborting due to 4 previous errors

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

@matthiaskrgr matthiaskrgr 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, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 15, 2024
@compiler-errors
Copy link
Member

cc @WaffleLapkin: This is due to the become compatibility checks.

I must've missed it during reviews, but in general it's not possible to call Instance::expect_resolve on still generic code, like this code is, since we only guarantee that Instance::expect_resolve succeeds post-mono otherwise it still may be too generic or still ambiguous due to things like specialization.

It seems important to guarantee that we enforce #[track_caller] compatibility for become <T as Trait>::foo(), though, so I'm not totally sure how we are going to check that for generic code... since we definitely can't look into all the impls of a trait, for example 🤔

@WaffleLapkin WaffleLapkin added the F-explicit_tail_calls `#![feature(explicit_tail_calls)]` label Dec 16, 2024
@WaffleLapkin
Copy link
Member

@compiler-errors hm. the only option that comes to mind is to check in codegen. which is sad, but maybe the only way? the check must be after mono...

another option could be to say that the caller can't be #[track_caller] (this is a local check) and callee is always un-track-called (i.e. the same what happens for as fn()). but this doesn't feel any better tbh...

@WaffleLapkin WaffleLapkin added requires-nightly This issue requires a nightly compiler in some way. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 16, 2024
@WaffleLapkin
Copy link
Member

For future reference, this is the MCVE:

#![expect(incomplete_features)]
#![feature(explicit_tail_calls)]

trait Tr {
    fn f();
}

fn g<T: Tr>() {
    become T::f();
}

@WaffleLapkin WaffleLapkin added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Dec 16, 2024
@compiler-errors
Copy link
Member

another option could be to say that the caller can't be #[track_caller] (this is a local check) and callee is always un-track-called (i.e. the same what happens for as fn()). but this doesn't feel any better tbh...

I actually think it would be reasonable to do this. Seems a lot better than introducing a new kind of post-mono error.

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jan 5, 2025
@WaffleLapkin WaffleLapkin self-assigned this Jan 24, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 6, 2025
…, r=compiler-errors

fix tail call checks wrt `#[track_caller]`

Only check the caller + disallow caller having the attribute.

fixes rust-lang#134336

r? `@compiler-errors`

<sub>apparently there were no tests for `#[track_caller]` before... ooops</sub>
@bors bors closed this as completed in 1c794b9 Feb 7, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 7, 2025
Rollup merge of rust-lang#135973 - WaffleLapkin:tail-track-caller-fix, r=compiler-errors

fix tail call checks wrt `#[track_caller]`

Only check the caller + disallow caller having the attribute.

fixes rust-lang#134336

r? `@compiler-errors`

<sub>apparently there were no tests for `#[track_caller]` before... ooops</sub>
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-explicit_tail_calls `#![feature(explicit_tail_calls)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

4 participants