Skip to content

ICE: delegation: out of range when substituting #119919

Closed
@matthiaskrgr

Description

snippet:

trait Trait {
    fn static_method(&self, x: i32) -> i32 { x }
}

struct F;

struct S(F);
impl Trait for S {
    reuse Trait::bar { &self.0 }
    reuse <F as Trait>
    reuse Trait::baz { &self.0 }
}

impl S {
    reuse Trait::baz { &self.0 }
}


fn main() {
    reuse <S as Trait>::static_method;
    reuse <S as Trait>::static_method2 { (self) }
    #[inline]
    
    assert_eq!(42, static_method(42));
}

Version information

rustc 1.77.0-nightly (89110dafe 2024-01-13)
binary: rustc
commit-hash: 89110dafe79621fa07d6cd7c8493dd1d0a83cfaf
commit-date: 2024-01-13
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

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

Program output

error: expected `::`, found `reuse`
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:11:5
   |
8  | impl Trait for S {
   |                  - while parsing this item list starting here
9  |     reuse Trait::bar { &self.0 }
10 |     reuse <F as Trait>
   |                       - expected `::`
11 |     reuse Trait::baz { &self.0 }
   |     ^^^^^ unexpected token
12 | }
   | - the item list ends here

error[E0407]: method `bar` is not a member of trait `Trait`
 --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:9:5
  |
9 |     reuse Trait::bar { &self.0 }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Trait`

error[E0425]: cannot find function `bar` in trait `Trait`
 --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:9:18
  |
9 |     reuse Trait::bar { &self.0 }
  |                  ^^^ not found in `Trait`

error[E0425]: cannot find function `baz` in trait `Trait`
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:15:18
   |
15 |     reuse Trait::baz { &self.0 }
   |                  ^^^ not found in `Trait`

error[E0576]: cannot find method or associated constant `static_method2` in trait `Trait`
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:21:25
   |
2  |     fn static_method(&self, x: i32) -> i32 { x }
   |     -------------------------------------- similarly named associated function `static_method` defined here
...
21 |     reuse <S as Trait>::static_method2 { (self) }
   |                         ^^^^^^^^^^^^^^ help: an associated function with a similar name exists: `static_method`

error[E0658]: functions delegation is not yet fully implemented
 --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:9:5
  |
9 |     reuse Trait::bar { &self.0 }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information
  = help: add `#![feature(fn_delegation)]` to the crate attributes to enable

error[E0658]: functions delegation is not yet fully implemented
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:15:5
   |
15 |     reuse Trait::baz { &self.0 }
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information
   = help: add `#![feature(fn_delegation)]` to the crate attributes to enable

error[E0658]: functions delegation is not yet fully implemented
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:20:5
   |
20 |     reuse <S as Trait>::static_method;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information
   = help: add `#![feature(fn_delegation)]` to the crate attributes to enable

error[E0658]: functions delegation is not yet fully implemented
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:21:5
   |
21 |     reuse <S as Trait>::static_method2 { (self) }
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information
   = help: add `#![feature(fn_delegation)]` to the crate attributes to enable

warning: unused attribute `inline`
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:22:5
   |
22 |     #[inline]
   |     ^^^^^^^^^
   |
note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `assert_eq`
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:24:5
   |
24 |     assert_eq!(42, static_method(42));
   |     ^^^^^^^^^
   = note: `#[warn(unused_attributes)]` on by default

warning: unnecessary parentheses around block return value
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:21:42
   |
21 |     reuse <S as Trait>::static_method2 { (self) }
   |                                          ^    ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
21 -     reuse <S as Trait>::static_method2 { (self) }
21 +     reuse <S as Trait>::static_method2 { self }
   |

error: internal compiler error: compiler/rustc_middle/src/ty/generic_args.rs:898:9: type parameter `Self/#0` (Self/#0/0) out of range when substituting, args=[]

thread 'rustc' panicked at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/compiler/rustc_errors/src/lib.rs:939:30:
Box<dyn Any>
stack backtrace:
   0:     0x7fe11298c7e6 - std::backtrace_rs::backtrace::libunwind::trace::h4f92a9ab1e969130
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fe11298c7e6 - std::backtrace_rs::backtrace::trace_unsynchronized::hff5adbaff3a8cfb8
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fe11298c7e6 - std::sys_common::backtrace::_print_fmt::h9d3e0e63f6f89eaf
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fe11298c7e6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2d31e6c8aa8ef934
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fe1129deec0 - core::fmt::rt::Argument::fmt::hd4eaf83b012a42ab
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/core/src/fmt/rt.rs:142:9
   5:     0x7fe1129deec0 - core::fmt::write::hb507e806b3ae16c4
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fe11298014f - std::io::Write::write_fmt::h203bf95b6a67c7a0
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/io/mod.rs:1810:15
   7:     0x7fe11298c5c4 - std::sys_common::backtrace::_print::h2f732cf10966ea1c
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fe11298c5c4 - std::sys_common::backtrace::print::hef45416e244164df
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fe11298f357 - std::panicking::default_hook::{{closure}}::h1a73802a0a993acf
  10:     0x7fe11298f0b9 - std::panicking::default_hook::h34548737700c4b4d
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/panicking.rs:292:9
  11:     0x7fe11574e80c - std[d6f21989bfff4f42]::panicking::update_hook::<alloc[21b544e6cc75226b]::boxed::Box<rustc_driver_impl[bce72efeea91a1de]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fe11298faa6 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb0b823449909a650
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/alloc/src/boxed.rs:2030:9
  13:     0x7fe11298faa6 - std::panicking::rust_panic_with_hook::h60e4310ab2a16e4e
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/panicking.rs:785:13
  14:     0x7fe1157808c4 - std[d6f21989bfff4f42]::panicking::begin_panic::<rustc_errors[eaf17d4bd6ee3375]::ExplicitBug>::{closure#0}
  15:     0x7fe11577d1c6 - std[d6f21989bfff4f42]::sys_common::backtrace::__rust_end_short_backtrace::<std[d6f21989bfff4f42]::panicking::begin_panic<rustc_errors[eaf17d4bd6ee3375]::ExplicitBug>::{closure#0}, !>
  16:     0x7fe11577ce36 - std[d6f21989bfff4f42]::panicking::begin_panic::<rustc_errors[eaf17d4bd6ee3375]::ExplicitBug>
  17:     0x7fe11578b9d1 - <rustc_errors[eaf17d4bd6ee3375]::diagnostic_builder::BugAbort as rustc_errors[eaf17d4bd6ee3375]::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7fe115b50e8b - <rustc_errors[eaf17d4bd6ee3375]::DiagCtxt>::bug::<alloc[21b544e6cc75226b]::string::String>
  19:     0x7fe115be8c6b - rustc_middle[63813a132a817cd4]::util::bug::opt_span_bug_fmt::<rustc_span[6e44e330265df079]::span_encoding::Span>::{closure#0}
  20:     0x7fe115bd10da - rustc_middle[63813a132a817cd4]::ty::context::tls::with_opt::<rustc_middle[63813a132a817cd4]::util::bug::opt_span_bug_fmt<rustc_span[6e44e330265df079]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7fe115bd0f58 - rustc_middle[63813a132a817cd4]::ty::context::tls::with_context_opt::<rustc_middle[63813a132a817cd4]::ty::context::tls::with_opt<rustc_middle[63813a132a817cd4]::util::bug::opt_span_bug_fmt<rustc_span[6e44e330265df079]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7fe113b85a10 - rustc_middle[63813a132a817cd4]::util::bug::bug_fmt
  23:     0x7fe115bdecf6 - <rustc_middle[63813a132a817cd4]::ty::generic_args::ArgFolder>::type_param_out_of_range
  24:     0x7fe116a07563 - <rustc_middle[63813a132a817cd4]::ty::generic_args::ArgFolder as rustc_type_ir[a282ecd95494b706]::fold::TypeFolder<rustc_middle[63813a132a817cd4]::ty::context::TyCtxt>>::fold_ty
  25:     0x7fe116a02493 - <rustc_middle[63813a132a817cd4]::ty::generic_args::ArgFolder as rustc_type_ir[a282ecd95494b706]::fold::TypeFolder<rustc_middle[63813a132a817cd4]::ty::context::TyCtxt>>::fold_ty
  26:     0x7fe116af35aa - <rustc_middle[63813a132a817cd4]::ty::Ty>::fn_sig
  27:     0x7fe116ebbb1d - <rustc_hir_typeck[995280b49f849d23]::fn_ctxt::FnCtxt>::check_expr_path
  28:     0x7fe11740ef25 - <rustc_hir_typeck[995280b49f849d23]::fn_ctxt::FnCtxt>::check_call
  29:     0x7fe1174dbc39 - <rustc_hir_typeck[995280b49f849d23]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30:     0x7fe1174dc73f - <rustc_hir_typeck[995280b49f849d23]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  31:     0x7fe1174df710 - <rustc_hir_typeck[995280b49f849d23]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  32:     0x7fe1173f57df - <rustc_hir_typeck[995280b49f849d23]::fn_ctxt::FnCtxt>::check_match
  33:     0x7fe1174dcb09 - <rustc_hir_typeck[995280b49f849d23]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  34:     0x7fe1173f0fa3 - <rustc_hir_typeck[995280b49f849d23]::fn_ctxt::FnCtxt>::check_block_with_expected
  35:     0x7fe1174dc049 - <rustc_hir_typeck[995280b49f849d23]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  36:     0x7fe117055848 - rustc_hir_typeck[995280b49f849d23]::check::check_fn
  37:     0x7fe116cd3f02 - rustc_hir_typeck[995280b49f849d23]::typeck
  38:     0x7fe116cd3289 - rustc_query_impl[f8b584d7216df600]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f8b584d7216df600]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[63813a132a817cd4]::query::erase::Erased<[u8; 8usize]>>
  39:     0x7fe116abfdf9 - rustc_query_system[13649e0efc92577a]::query::plumbing::try_execute_query::<rustc_query_impl[f8b584d7216df600]::DynamicConfig<rustc_query_system[13649e0efc92577a]::query::caches::VecCache<rustc_span[6e44e330265df079]::def_id::LocalDefId, rustc_middle[63813a132a817cd4]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[f8b584d7216df600]::plumbing::QueryCtxt, false>
  40:     0x7fe116abfa90 - rustc_query_impl[f8b584d7216df600]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7fe116fe99cc - <rustc_middle[63813a132a817cd4]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[f88d56455d931b67]::check_crate::{closure#6}>::{closure#0}
  42:     0x7fe116fe82c4 - rustc_hir_analysis[f88d56455d931b67]::check_crate
  43:     0x7fe117494419 - rustc_interface[37b6cebe1bce16]::passes::analysis
  44:     0x7fe11749405f - rustc_query_impl[f8b584d7216df600]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f8b584d7216df600]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[63813a132a817cd4]::query::erase::Erased<[u8; 1usize]>>
  45:     0x7fe1179cd040 - rustc_query_system[13649e0efc92577a]::query::plumbing::try_execute_query::<rustc_query_impl[f8b584d7216df600]::DynamicConfig<rustc_query_system[13649e0efc92577a]::query::caches::SingleCache<rustc_middle[63813a132a817cd4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f8b584d7216df600]::plumbing::QueryCtxt, false>
  46:     0x7fe1179cce47 - rustc_query_impl[f8b584d7216df600]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  47:     0x7fe1177343ed - rustc_interface[37b6cebe1bce16]::interface::run_compiler::<core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>, rustc_driver_impl[bce72efeea91a1de]::run_compiler::{closure#0}>::{closure#0}
  48:     0x7fe1179f3546 - std[d6f21989bfff4f42]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[37b6cebe1bce16]::util::run_in_thread_with_globals<rustc_interface[37b6cebe1bce16]::util::run_in_thread_pool_with_globals<rustc_interface[37b6cebe1bce16]::interface::run_compiler<core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>, rustc_driver_impl[bce72efeea91a1de]::run_compiler::{closure#0}>::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>
  49:     0x7fe1179f3373 - <<std[d6f21989bfff4f42]::thread::Builder>::spawn_unchecked_<rustc_interface[37b6cebe1bce16]::util::run_in_thread_with_globals<rustc_interface[37b6cebe1bce16]::util::run_in_thread_pool_with_globals<rustc_interface[37b6cebe1bce16]::interface::run_compiler<core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>, rustc_driver_impl[bce72efeea91a1de]::run_compiler::{closure#0}>::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a757d3bbb7cc29b8]::result::Result<(), rustc_span[6e44e330265df079]::ErrorGuaranteed>>::{closure#1} as core[a757d3bbb7cc29b8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:     0x7fe1129999d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc62465ce3696edbb
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/alloc/src/boxed.rs:2016:9
  51:     0x7fe1129999d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2898b364df1453ed
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/alloc/src/boxed.rs:2016:9
  52:     0x7fe1129999d5 - std::sys::unix::thread::Thread::new::thread_start::hefe0ce868779f0f1
                               at /rustc/89110dafe79621fa07d6cd7c8493dd1d0a83cfaf/library/std/src/sys/unix/thread.rs:108:17
  53:     0x7fe1127859eb - <unknown>
  54:     0x7fe1128097cc - <unknown>
  55:                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.77.0-nightly (89110dafe 2024-01-13) 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[E0308]: mismatched types
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:20:25
   |
20 |     reuse <S as Trait>::static_method;
   |           --------------^^^^^^^^^^^^^
   |           |             |
   |           |             expected `&S`, found `&Self`
   |           arguments to this function are incorrect
   |
   = note: expected reference `&S`
              found reference `&Self`
note: method defined here
  --> /tmp/icemaker_global_tempdir.bHkheWGOf7Q4/rustc_testrunner_tmpdir_reporting.hSy8JnLxBMYR/mvce.rs:2:8
   |
2  |     fn static_method(&self, x: i32) -> i32 { x }
   |        ^^^^^^^^^^^^^ -----

error: aborting due to 11 previous errors; 2 warnings emitted

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-fn_delegation`#![feature(fn_delegation)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions