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 using return_position_impl_trait_in_trait with default implementation #102826

Closed
matheus-consoli opened this issue Oct 9, 2022 · 1 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.

Comments

@matheus-consoli
Copy link

Code

playground

rustc panics on:

#![feature(return_position_impl_trait_in_trait)]
trait FilterOddsIteratorExt: Iterator<Item=usize> + Sized {
    fn filter_odds(self) -> impl Iterator<Item=usize> {
        self.filter(|i| i % 2 != 0)
    }
}

impl<T> FilterOddsIteratorExt for T where T: Iterator<Item = usize> {}


fn main() {
   _ = (0..10).filter_odds();
}

but not on:

trait FilterOddsIteratorExt: Iterator<Item=usize> + Sized {
    fn filter_odds(self) -> impl Iterator<Item = usize>;
}

impl<T> FilterOddsIteratorExt for T where T: Iterator<Item=usize> {
    fn filter_odds(self) -> impl Iterator<Item=usize> {
        self.filter(|i| i % 2 != 0)
    }
}

fn main() {
    _ = (0..10).filter_odds();
}

note that when not using the implementation, the compiler doesn't panic, but gives a mismatch types error (try commenting main)

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (0ca356586 2022-10-06)
binary: rustc
commit-hash: 0ca356586fed56002b10920fd21ddf6fb12de797
commit-date: 2022-10-06
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2
Backtrace

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_hir_analysis/src/check/compare_method.rs:444:45
stack backtrace:
   0:     0x7f20db9a6450 - std::backtrace_rs::backtrace::libunwind::trace::hcf69096e68cbc96c
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f20db9a6450 - std::backtrace_rs::backtrace::trace_unsynchronized::hc388a2eb8060d628
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f20db9a6450 - std::sys_common::backtrace::_print_fmt::h4c04c7375802901c
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f20db9a6450 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0437a8b14d91b76c
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f20dba0121e - core::fmt::write::h3b1165d45b8cb3f7
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/core/src/fmt/mod.rs:1209:17
   5:     0x7f20db996fd5 - std::io::Write::write_fmt::h108967c06574ddc1
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/io/mod.rs:1679:15
   6:     0x7f20db9a91f3 - std::sys_common::backtrace::_print::haaa35276780afaf9
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f20db9a91f3 - std::sys_common::backtrace::print::hbb2439e50cf7a680
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f20db9a91f3 - std::panicking::default_hook::{{closure}}::h255e62e45345406e
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/panicking.rs:267:22
   9:     0x7f20db9a8eca - std::panicking::default_hook::h3a9c05016eae076b
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/panicking.rs:286:9
  10:     0x7f20de2cccd1 - <rustc_driver[f8d5eb37f9652177]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[341adad06997dc31]::ops::function::FnOnce<(&core[341adad06997dc31]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f20db9a9a2b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h96fcb5350a0ce4d2
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/alloc/src/boxed.rs:1952:9
  12:     0x7f20db9a9a2b - std::panicking::rust_panic_with_hook::h1e087acdfd3a88b4
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/panicking.rs:673:13
  13:     0x7f20db9a9841 - std::panicking::begin_panic_handler::{{closure}}::h36afbf5dab2db68d
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/panicking.rs:558:13
  14:     0x7f20db9a68fc - std::sys_common::backtrace::__rust_end_short_backtrace::h8b338cf63632c037
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/sys_common/backtrace.rs:138:18
  15:     0x7f20db9a95a2 - rust_begin_unwind
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/panicking.rs:556:5
  16:     0x7f20db9fddf3 - core::panicking::panic_fmt::hbaf70a28dc8c539a
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/core/src/panicking.rs:142:14
  17:     0x7f20db9fdc3d - core::panicking::panic::h82a6ad6819b2af85
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/core/src/panicking.rs:48:5
  18:     0x7f20de4fc804 - rustc_hir_analysis[23b58cca7863dc36]::check::compare_method::collect_trait_impl_trait_tys
  19:     0x7f20deb61c44 - <rustc_middle[8fec32cc1d722bdc]::dep_graph::dep_node::DepKind as rustc_query_system[8eac85d8325cc65c]::dep_graph::DepKind>::with_deps::<<rustc_query_system[8eac85d8325cc65c]::dep_graph::graph::DepGraph<rustc_middle[8fec32cc1d722bdc]::dep_graph::dep_node::DepKind>>::with_task_impl<rustc_middle[8fec32cc1d722bdc]::ty::context::TyCtxt, rustc_span[97dc9a00dee87296]::def_id::DefId, core[341adad06997dc31]::result::Result<&std[ec613a431564c17a]::collections::hash::map::HashMap<rustc_span[97dc9a00dee87296]::def_id::DefId, rustc_middle[8fec32cc1d722bdc]::ty::Ty, core[341adad06997dc31]::hash::BuildHasherDefault<rustc_hash[ad1c7c67e0991a18]::FxHasher>>, rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>::{closure#0}, core[341adad06997dc31]::result::Result<&std[ec613a431564c17a]::collections::hash::map::HashMap<rustc_span[97dc9a00dee87296]::def_id::DefId, rustc_middle[8fec32cc1d722bdc]::ty::Ty, core[341adad06997dc31]::hash::BuildHasherDefault<rustc_hash[ad1c7c67e0991a18]::FxHasher>>, rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>
  20:     0x7f20decbf555 - <rustc_query_system[8eac85d8325cc65c]::dep_graph::graph::DepGraph<rustc_middle[8fec32cc1d722bdc]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[8fec32cc1d722bdc]::ty::context::TyCtxt, rustc_span[97dc9a00dee87296]::def_id::DefId, core[341adad06997dc31]::result::Result<&std[ec613a431564c17a]::collections::hash::map::HashMap<rustc_span[97dc9a00dee87296]::def_id::DefId, rustc_middle[8fec32cc1d722bdc]::ty::Ty, core[341adad06997dc31]::hash::BuildHasherDefault<rustc_hash[ad1c7c67e0991a18]::FxHasher>>, rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>
  21:     0x7f20debc8792 - rustc_query_system[8eac85d8325cc65c]::query::plumbing::try_execute_query::<rustc_query_impl[8927692615c9b81a]::plumbing::QueryCtxt, rustc_query_system[8eac85d8325cc65c]::query::caches::DefaultCache<rustc_span[97dc9a00dee87296]::def_id::DefId, core[341adad06997dc31]::result::Result<&std[ec613a431564c17a]::collections::hash::map::HashMap<rustc_span[97dc9a00dee87296]::def_id::DefId, rustc_middle[8fec32cc1d722bdc]::ty::Ty, core[341adad06997dc31]::hash::BuildHasherDefault<rustc_hash[ad1c7c67e0991a18]::FxHasher>>, rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>>
  22:     0x7f20debf44ae - rustc_query_system[8eac85d8325cc65c]::query::plumbing::get_query::<rustc_query_impl[8927692615c9b81a]::queries::collect_trait_impl_trait_tys, rustc_query_impl[8927692615c9b81a]::plumbing::QueryCtxt>
  23:     0x7f20df2de512 - <rustc_middle[8fec32cc1d722bdc]::ty::context::TyCtxt>::bound_trait_impl_trait_tys
  24:     0x7f20dcc9ef3c - rustc_trait_selection[88fd394d1feda7a5]::traits::project::opt_normalize_projection_type
  25:     0x7f20dcc92413 - <rustc_trait_selection[88fd394d1feda7a5]::traits::project::AssocTypeNormalizer as rustc_middle[8fec32cc1d722bdc]::ty::fold::TypeFolder>::fold_ty
  26:     0x7f20dd5d4aa3 - <&rustc_middle[8fec32cc1d722bdc]::ty::list::List<rustc_middle[8fec32cc1d722bdc]::ty::Ty> as rustc_middle[8fec32cc1d722bdc]::ty::fold::TypeFoldable>::try_fold_with::<rustc_trait_selection[88fd394d1feda7a5]::traits::project::AssocTypeNormalizer>
  27:     0x7f20dd5d495e - <(rustc_middle[8fec32cc1d722bdc]::ty::sty::FnSig, rustc_middle[8fec32cc1d722bdc]::ty::InstantiatedPredicates) as rustc_middle[8fec32cc1d722bdc]::ty::fold::TypeFoldable>::fold_with::<rustc_trait_selection[88fd394d1feda7a5]::traits::project::AssocTypeNormalizer>
  28:     0x7f20dd5d4003 - rustc_trait_selection[88fd394d1feda7a5]::traits::project::normalize::<(rustc_middle[8fec32cc1d722bdc]::ty::sty::FnSig, rustc_middle[8fec32cc1d722bdc]::ty::InstantiatedPredicates)>
  29:     0x7f20dce604f2 - <rustc_hir_analysis[23b58cca7863dc36]::check::method::confirm::ConfirmContext>::confirm
  30:     0x7f20dce264ec - <rustc_hir_analysis[23b58cca7863dc36]::check::fn_ctxt::FnCtxt>::lookup_method
  31:     0x7f20dce082c4 - <rustc_hir_analysis[23b58cca7863dc36]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  32:     0x7f20dce46eef - <rustc_hir_analysis[23b58cca7863dc36]::check::fn_ctxt::FnCtxt>::check_decl
  33:     0x7f20dce4359e - <rustc_hir_analysis[23b58cca7863dc36]::check::fn_ctxt::FnCtxt>::check_block_with_expected
  34:     0x7f20dce0808b - <rustc_hir_analysis[23b58cca7863dc36]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  35:     0x7f20dce434b9 - <rustc_hir_analysis[23b58cca7863dc36]::check::fn_ctxt::FnCtxt>::check_block_with_expected
  36:     0x7f20dce0808b - <rustc_hir_analysis[23b58cca7863dc36]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  37:     0x7f20dd7f91a6 - <rustc_hir_analysis[23b58cca7863dc36]::check::fn_ctxt::FnCtxt>::check_return_expr
  38:     0x7f20dd7effa5 - rustc_hir_analysis[23b58cca7863dc36]::check::check::check_fn
  39:     0x7f20dd7e172b - <rustc_hir_analysis[23b58cca7863dc36]::check::inherited::InheritedBuilder>::enter::<rustc_hir_analysis[23b58cca7863dc36]::check::typeck_with_fallback<rustc_hir_analysis[23b58cca7863dc36]::check::typeck::{closure#0}>::{closure#1}, &rustc_middle[8fec32cc1d722bdc]::ty::context::TypeckResults>
  40:     0x7f20dd7df84f - rustc_hir_analysis[23b58cca7863dc36]::check::typeck
  41:     0x7f20dd8d4083 - <rustc_query_system[8eac85d8325cc65c]::dep_graph::graph::DepGraph<rustc_middle[8fec32cc1d722bdc]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[8fec32cc1d722bdc]::ty::context::TyCtxt, rustc_span[97dc9a00dee87296]::def_id::LocalDefId, &rustc_middle[8fec32cc1d722bdc]::ty::context::TypeckResults>
  42:     0x7f20dd8c2fb1 - rustc_query_system[8eac85d8325cc65c]::query::plumbing::try_execute_query::<rustc_query_impl[8927692615c9b81a]::plumbing::QueryCtxt, rustc_query_system[8eac85d8325cc65c]::query::caches::DefaultCache<rustc_span[97dc9a00dee87296]::def_id::LocalDefId, &rustc_middle[8fec32cc1d722bdc]::ty::context::TypeckResults>>
  43:     0x7f20de1cad4e - <rustc_query_impl[8927692615c9b81a]::Queries as rustc_middle[8fec32cc1d722bdc]::ty::query::QueryEngine>::typeck
  44:     0x7f20ddffd6a7 - rustc_data_structures[af88eac711b540fa]::sync::par_for_each_in::<&[rustc_span[97dc9a00dee87296]::def_id::LocalDefId], <rustc_middle[8fec32cc1d722bdc]::hir::map::Map>::par_body_owners<rustc_hir_analysis[23b58cca7863dc36]::check::typeck_item_bodies::{closure#0}>::{closure#0}>
  45:     0x7f20ddffd463 - rustc_hir_analysis[23b58cca7863dc36]::check::typeck_item_bodies
  46:     0x7f20ddf00c49 - <rustc_query_system[8eac85d8325cc65c]::dep_graph::graph::DepGraph<rustc_middle[8fec32cc1d722bdc]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[8fec32cc1d722bdc]::ty::context::TyCtxt, (), ()>
  47:     0x7f20ddeffc28 - rustc_query_system[8eac85d8325cc65c]::query::plumbing::try_execute_query::<rustc_query_impl[8927692615c9b81a]::plumbing::QueryCtxt, rustc_query_system[8eac85d8325cc65c]::query::caches::DefaultCache<(), ()>>
  48:     0x7f20ddeff637 - rustc_query_system[8eac85d8325cc65c]::query::plumbing::get_query::<rustc_query_impl[8927692615c9b81a]::queries::typeck_item_bodies, rustc_query_impl[8927692615c9b81a]::plumbing::QueryCtxt>
  49:     0x7f20dd607fcf - <rustc_session[5f8ba50a91a4fb10]::session::Session>::time::<(), rustc_hir_analysis[23b58cca7863dc36]::check_crate::{closure#7}>
  50:     0x7f20dd607a2f - rustc_hir_analysis[23b58cca7863dc36]::check_crate
  51:     0x7f20dd6076d7 - rustc_interface[ef326ff72e9f2695]::passes::analysis
  52:     0x7f20de03e526 - <rustc_query_system[8eac85d8325cc65c]::dep_graph::graph::DepGraph<rustc_middle[8fec32cc1d722bdc]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[8fec32cc1d722bdc]::ty::context::TyCtxt, (), core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>
  53:     0x7f20de03dc06 - rustc_query_system[8eac85d8325cc65c]::query::plumbing::try_execute_query::<rustc_query_impl[8927692615c9b81a]::plumbing::QueryCtxt, rustc_query_system[8eac85d8325cc65c]::query::caches::DefaultCache<(), core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>>
  54:     0x7f20de03d6e7 - rustc_query_system[8eac85d8325cc65c]::query::plumbing::get_query::<rustc_query_impl[8927692615c9b81a]::queries::analysis, rustc_query_impl[8927692615c9b81a]::plumbing::QueryCtxt>
  55:     0x7f20dcf9f484 - <rustc_interface[ef326ff72e9f2695]::passes::QueryContext>::enter::<rustc_driver[f8d5eb37f9652177]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>
  56:     0x7f20dcf9a019 - rustc_interface[ef326ff72e9f2695]::interface::create_compiler_and_run::<core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>, rustc_driver[f8d5eb37f9652177]::run_compiler::{closure#1}>
  57:     0x7f20dcf98922 - <scoped_tls[fa3665dae4c012d7]::ScopedKey<rustc_span[97dc9a00dee87296]::SessionGlobals>>::set::<rustc_interface[ef326ff72e9f2695]::interface::run_compiler<core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>, rustc_driver[f8d5eb37f9652177]::run_compiler::{closure#1}>::{closure#0}, core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>
  58:     0x7f20dcf9860f - std[ec613a431564c17a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ef326ff72e9f2695]::util::run_in_thread_pool_with_globals<rustc_interface[ef326ff72e9f2695]::interface::run_compiler<core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>, rustc_driver[f8d5eb37f9652177]::run_compiler::{closure#1}>::{closure#0}, core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>::{closure#0}, core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>
  59:     0x7f20de0e3530 - <<std[ec613a431564c17a]::thread::Builder>::spawn_unchecked_<rustc_interface[ef326ff72e9f2695]::util::run_in_thread_pool_with_globals<rustc_interface[ef326ff72e9f2695]::interface::run_compiler<core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>, rustc_driver[f8d5eb37f9652177]::run_compiler::{closure#1}>::{closure#0}, core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>::{closure#0}, core[341adad06997dc31]::result::Result<(), rustc_errors[827f592ed624eae5]::ErrorGuaranteed>>::{closure#1} as core[341adad06997dc31]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  60:     0x7f20db9b3503 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h716e33e5062fa80e
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/alloc/src/boxed.rs:1938:9
  61:     0x7f20db9b3503 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hda2b1d1f461e1c20
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/alloc/src/boxed.rs:1938:9
  62:     0x7f20db9b3503 - std::sys::unix::thread::Thread::new::thread_start::hcbf78f667b73439d
                               at /rustc/0ca356586fed56002b10920fd21ddf6fb12de797/library/std/src/sys/unix/thread.rs:108:17
  63:     0x7f20db72c8fd - <unknown>
  64:     0x7f20db7aea60 - <unknown>
  65:                0x0 - <unknown>

@matheus-consoli matheus-consoli 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 Oct 9, 2022
@compiler-errors
Copy link
Member

This is a duplicate of #101665, so it's fixed by #101679. Thanks for reporting.

@compiler-errors compiler-errors closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2022
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
Development

No branches or pull requests

2 participants