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

RPITIT ICE when impl's fn is missing a type parameter #104281

Closed
jruderman opened this issue Nov 11, 2022 · 0 comments · Fixed by #104295
Closed

RPITIT ICE when impl's fn is missing a type parameter #104281

jruderman opened this issue Nov 11, 2022 · 0 comments · Fixed by #104295
Assignees
Labels
C-bug Category: This is a bug. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` 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

Found with a modified fuzz-rustc

Code

#![feature(return_position_impl_trait_in_trait)]
#[allow(incomplete_features)]

struct S;

trait Foo {
    fn bar<T>() -> impl Sized;
}

impl Foo for S {
    fn bar() -> impl Sized {}
}

fn main() {
    S::bar();
}

Error output

error[E0049]: method `bar` has 0 type parameters but its trait declaration has 1 type parameter

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:726:9: type parameter `T/#1` (T/1) out of range when substituting, substs=[S]
Full output including backtrace

error[E0049]: method `bar` has 0 type parameters but its trait declaration has 1 type parameter
  --> ra.rs:11:11
   |
7  |     fn bar<T>() -> impl Sized;
   |            - expected 1 type parameter
...
11 |     fn bar() -> impl Sized {}
   |           ^ found 0 type parameters

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:726:9: type parameter `T/#1` (T/1) out of range when substituting, substs=[S]

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/e75aab045fc476f176a58c408f6b06f0e275c6e1/compiler/rustc_errors/src/lib.rs:1551:9
stack backtrace:
   0:        0x102887f12 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1b594e9bcc0c6898
   1:        0x1028e64ba - core::fmt::write::h7c6f83d024852aa9
   2:        0x102879fec - std::io::Write::write_fmt::h97d969d4aea1606d
   3:        0x102887cda - std::sys_common::backtrace::print::h562dadf6028256bf
   4:        0x10288b0b6 - std::panicking::default_hook::{{closure}}::hee367e24075678e4
   5:        0x10288ae07 - std::panicking::default_hook::hcce3553a0befadd1
   6:        0x111ee1f3d - rustc_driver[f93b8a3886cc8b65]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x10288b8b5 - std::panicking::rust_panic_with_hook::h4f6feaafc55c56a2
   8:        0x1165ff4d7 - std[38dd6138ba148cb2]::panicking::begin_panic::<rustc_errors[ef89fc2f19a46f90]::ExplicitBug>::{closure#0}
   9:        0x1165febe9 - std[38dd6138ba148cb2]::sys_common::backtrace::__rust_end_short_backtrace::<std[38dd6138ba148cb2]::panicking::begin_panic<rustc_errors[ef89fc2f19a46f90]::ExplicitBug>::{closure#0}, !>
  10:        0x116caaa39 - std[38dd6138ba148cb2]::panicking::begin_panic::<rustc_errors[ef89fc2f19a46f90]::ExplicitBug>
  11:        0x1165f92c9 - std[38dd6138ba148cb2]::panic::panic_any::<rustc_errors[ef89fc2f19a46f90]::ExplicitBug>
  12:        0x1165f753d - <rustc_errors[ef89fc2f19a46f90]::HandlerInner>::bug::<&alloc[dd1f1a43ef059f04]::string::String>
  13:        0x1165f7007 - <rustc_errors[ef89fc2f19a46f90]::Handler>::bug::<&alloc[dd1f1a43ef059f04]::string::String>
  14:        0x116753872 - rustc_middle[85091bb6846d2e9a]::ty::context::tls::with_context_opt::<rustc_middle[85091bb6846d2e9a]::ty::context::tls::with_opt<rustc_middle[85091bb6846d2e9a]::util::bug::opt_span_bug_fmt<rustc_span[50ad8565b2f1bbfb]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
  15:        0x1167547d1 - rustc_middle[85091bb6846d2e9a]::util::bug::opt_span_bug_fmt::<rustc_span[50ad8565b2f1bbfb]::span_encoding::Span>
  16:        0x116cac3ee - rustc_middle[85091bb6846d2e9a]::util::bug::bug_fmt
  17:        0x116cac198 - <rustc_middle[85091bb6846d2e9a]::ty::subst::SubstFolder>::type_param_out_of_range
  18:        0x116733709 - <rustc_middle[85091bb6846d2e9a]::ty::subst::SubstFolder as rustc_middle[85091bb6846d2e9a]::ty::fold::TypeFolder>::fold_ty
  19:        0x116751365 - <&rustc_middle[85091bb6846d2e9a]::ty::list::List<rustc_middle[85091bb6846d2e9a]::ty::subst::GenericArg> as rustc_middle[85091bb6846d2e9a]::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle[85091bb6846d2e9a]::ty::subst::SubstFolder>
  20:        0x116627227 - <rustc_middle[85091bb6846d2e9a]::ty::Ty as rustc_middle[85091bb6846d2e9a]::ty::fold::TypeSuperFoldable>::super_fold_with::<rustc_middle[85091bb6846d2e9a]::ty::subst::SubstFolder>
  21:        0x11490dd7b - rustc_middle[85091bb6846d2e9a]::ty::util::fold_list::<rustc_middle[85091bb6846d2e9a]::ty::subst::SubstFolder, rustc_middle[85091bb6846d2e9a]::ty::Ty, <&rustc_middle[85091bb6846d2e9a]::ty::list::List<rustc_middle[85091bb6846d2e9a]::ty::Ty> as rustc_middle[85091bb6846d2e9a]::ty::fold::TypeFoldable>::try_fold_with<rustc_middle[85091bb6846d2e9a]::ty::subst::SubstFolder>::{closure#0}>
  22:        0x1149437cf - <rustc_middle[85091bb6846d2e9a]::ty::sty::Binder<rustc_middle[85091bb6846d2e9a]::ty::sty::FnSig> as rustc_middle[85091bb6846d2e9a]::ty::fold::TypeSuperFoldable>::super_fold_with::<rustc_middle[85091bb6846d2e9a]::ty::subst::SubstFolder>
  23:        0x114a0810e - rustc_hir_analysis[e85e3b9a54dc24a9]::check::compare_method::collect_trait_impl_trait_tys
  24:        0x1156ee435 - rustc_query_system[38b064a260926677]::query::plumbing::try_execute_query::<rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt, rustc_query_system[38b064a260926677]::query::caches::DefaultCache<rustc_span[50ad8565b2f1bbfb]::def_id::DefId, core[322641b34a183a]::result::Result<&std[38dd6138ba148cb2]::collections::hash::map::HashMap<rustc_span[50ad8565b2f1bbfb]::def_id::DefId, rustc_middle[85091bb6846d2e9a]::ty::Ty, core[322641b34a183a]::hash::BuildHasherDefault<rustc_hash[4b31e884d1fde7da]::FxHasher>>, rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>>
  25:        0x1157d8534 - rustc_query_system[38b064a260926677]::query::plumbing::get_query::<rustc_query_impl[fcf86a589ba14889]::queries::collect_trait_impl_trait_tys, rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt>
  26:        0x1166f0d57 - <rustc_middle[85091bb6846d2e9a]::ty::context::TyCtxt>::bound_trait_impl_trait_tys
  27:        0x11639afd9 - rustc_trait_selection[fbfc9000665c881]::traits::project::project
  28:        0x1163975f1 - rustc_trait_selection[fbfc9000665c881]::traits::project::opt_normalize_projection_type
  29:        0x116391d9e - rustc_trait_selection[fbfc9000665c881]::traits::project::normalize_projection_type
  30:        0x116390794 - <rustc_trait_selection[fbfc9000665c881]::traits::project::AssocTypeNormalizer as rustc_middle[85091bb6846d2e9a]::ty::fold::TypeFolder>::fold_ty
  31:        0x11481503b - rustc_middle[85091bb6846d2e9a]::ty::util::fold_list::<rustc_trait_selection[fbfc9000665c881]::traits::project::AssocTypeNormalizer, rustc_middle[85091bb6846d2e9a]::ty::Ty, <&rustc_middle[85091bb6846d2e9a]::ty::list::List<rustc_middle[85091bb6846d2e9a]::ty::Ty> as rustc_middle[85091bb6846d2e9a]::ty::fold::TypeFoldable>::try_fold_with<rustc_trait_selection[fbfc9000665c881]::traits::project::AssocTypeNormalizer>::{closure#0}>
  32:        0x1147e4c61 - <rustc_trait_selection[fbfc9000665c881]::traits::project::AssocTypeNormalizer>::fold::<rustc_middle[85091bb6846d2e9a]::ty::sty::FnSig>
  33:        0x1147eb22a - rustc_trait_selection[fbfc9000665c881]::traits::project::normalize::<rustc_middle[85091bb6846d2e9a]::ty::sty::FnSig>
  34:        0x1148730bc - <rustc_infer[f3d18b0d0d8e0a5e]::infer::InferCtxt as rustc_trait_selection[fbfc9000665c881]::infer::InferCtxtExt>::partially_normalize_associated_types_in::<rustc_middle[85091bb6846d2e9a]::ty::sty::FnSig>
  35:        0x11482b100 - <rustc_hir_typeck[bdb15a1f3923c127]::inherited::Inherited>::normalize_associated_types_in::<rustc_middle[85091bb6846d2e9a]::ty::sty::FnSig>
  36:        0x1146da936 - <rustc_hir_typeck[bdb15a1f3923c127]::fn_ctxt::FnCtxt>::confirm_builtin_call
  37:        0x1146d7994 - <rustc_hir_typeck[bdb15a1f3923c127]::fn_ctxt::FnCtxt>::check_call
  38:        0x114741c82 - <rustc_hir_typeck[bdb15a1f3923c127]::fn_ctxt::FnCtxt>::check_expr_kind
  39:        0x1146eb680 - <rustc_hir_typeck[bdb15a1f3923c127]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  40:        0x1147010c5 - <rustc_hir_typeck[bdb15a1f3923c127]::fn_ctxt::FnCtxt>::check_stmt
  41:        0x1147017ef - <rustc_hir_typeck[bdb15a1f3923c127]::fn_ctxt::FnCtxt>::check_block_with_expected
  42:        0x114742068 - <rustc_hir_typeck[bdb15a1f3923c127]::fn_ctxt::FnCtxt>::check_expr_kind
  43:        0x1146eb680 - <rustc_hir_typeck[bdb15a1f3923c127]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  44:        0x1146ec6ba - <rustc_hir_typeck[bdb15a1f3923c127]::fn_ctxt::FnCtxt>::check_return_expr
  45:        0x11482c608 - rustc_hir_typeck[bdb15a1f3923c127]::check::check_fn
  46:        0x1148293cd - <rustc_hir_typeck[bdb15a1f3923c127]::inherited::InheritedBuilder>::enter::<rustc_hir_typeck[bdb15a1f3923c127]::typeck_with_fallback<rustc_hir_typeck[bdb15a1f3923c127]::typeck::{closure#0}>::{closure#0}::{closure#1}, &rustc_middle[85091bb6846d2e9a]::ty::context::TypeckResults>
  47:        0x1147c2ffa - rustc_hir_typeck[bdb15a1f3923c127]::typeck
  48:        0x1156d5159 - rustc_query_system[38b064a260926677]::query::plumbing::try_execute_query::<rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt, rustc_query_system[38b064a260926677]::query::caches::DefaultCache<rustc_span[50ad8565b2f1bbfb]::def_id::LocalDefId, &rustc_middle[85091bb6846d2e9a]::ty::context::TypeckResults>>
  49:        0x1157dab8c - rustc_query_system[38b064a260926677]::query::plumbing::get_query::<rustc_query_impl[fcf86a589ba14889]::queries::typeck, rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt>
  50:        0x11485276c - std[38dd6138ba148cb2]::panicking::try::<(), core[322641b34a183a]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[2eed7d44fa552923]::sync::par_for_each_in<&[rustc_span[50ad8565b2f1bbfb]::def_id::LocalDefId], <rustc_middle[85091bb6846d2e9a]::hir::map::Map>::par_body_owners<rustc_hir_typeck[bdb15a1f3923c127]::typeck_item_bodies::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>>
  51:        0x1148524a5 - rustc_data_structures[2eed7d44fa552923]::sync::par_for_each_in::<&[rustc_span[50ad8565b2f1bbfb]::def_id::LocalDefId], <rustc_middle[85091bb6846d2e9a]::hir::map::Map>::par_body_owners<rustc_hir_typeck[bdb15a1f3923c127]::typeck_item_bodies::{closure#0}>::{closure#0}>
  52:        0x1147c277d - rustc_hir_typeck[bdb15a1f3923c127]::typeck_item_bodies
  53:        0x11576edb9 - rustc_query_system[38b064a260926677]::query::plumbing::try_execute_query::<rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt, rustc_query_system[38b064a260926677]::query::caches::DefaultCache<(), ()>>
  54:        0x1157cf339 - rustc_query_system[38b064a260926677]::query::plumbing::get_query::<rustc_query_impl[fcf86a589ba14889]::queries::typeck_item_bodies, rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt>
  55:        0x11493b3f4 - <rustc_session[304ed9bc7c986c94]::session::Session>::time::<(), rustc_hir_analysis[e85e3b9a54dc24a9]::check_crate::{closure#7}>
  56:        0x114a5a5df - rustc_hir_analysis[e85e3b9a54dc24a9]::check_crate
  57:        0x111fa53ba - rustc_interface[bab52cec3fba6e57]::passes::analysis
  58:        0x115760b7c - rustc_query_system[38b064a260926677]::query::plumbing::try_execute_query::<rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt, rustc_query_system[38b064a260926677]::query::caches::DefaultCache<(), core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>>
  59:        0x1157daf39 - rustc_query_system[38b064a260926677]::query::plumbing::get_query::<rustc_query_impl[fcf86a589ba14889]::queries::analysis, rustc_query_impl[fcf86a589ba14889]::plumbing::QueryCtxt>
  60:        0x111e71416 - <rustc_interface[bab52cec3fba6e57]::passes::QueryContext>::enter::<rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>
  61:        0x111eb568d - rustc_span[50ad8565b2f1bbfb]::with_source_map::<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  62:        0x111ea55bc - <scoped_tls[5d80669e9829205e]::ScopedKey<rustc_span[50ad8565b2f1bbfb]::SessionGlobals>>::set::<rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>
  63:        0x111e7437a - std[38dd6138ba148cb2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[bab52cec3fba6e57]::util::run_in_thread_pool_with_globals<rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>
  64:        0x111e5ab4b - <<std[38dd6138ba148cb2]::thread::Builder>::spawn_unchecked_<rustc_interface[bab52cec3fba6e57]::util::run_in_thread_pool_with_globals<rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>::{closure#1} as core[322641b34a183a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  65:        0x102894967 - std::sys::unix::thread::Thread::new::thread_start::hae9a83a2ac729f3b
  66:     0x7ff80d84d4e1 - __pthread_start

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.67.0-nightly (e75aab045 2022-11-09) running on x86_64-apple-darwin

query stack during panic:
#0 [collect_trait_impl_trait_tys] comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process
#1 [typeck] type-checking `main`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

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

Not a regression

This ICEd in nightly-2022-09-10 when RPITIT was first introduced

Version

rustc 1.67.0-nightly (e75aab045 2022-11-09)
binary: rustc
commit-hash: e75aab045fc476f176a58c408f6b06f0e275c6e1
commit-date: 2022-11-09
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4

@rustbot label +F-return_position_impl_trait_in_trait

@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 Nov 11, 2022
@rustbot rustbot added the F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` label Nov 11, 2022
@compiler-errors compiler-errors self-assigned this Nov 11, 2022
@bors bors closed this as completed in 680ba90 Nov 22, 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. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` 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