rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.1k stars 12.55k forks source link

ICE: "type parameter out of range when substituting" if struct contains a field with a Box and unknown field is requested #81627

Closed matthiaskrgr closed 3 years ago

matthiaskrgr commented 3 years ago

Code

code from ./src/test/ui/parser/issue-35813-postfix-after-cast.rs

#![crate_type = "lib"]
#![feature(type_ascription)]
use std::future::Future;
use std::pin::Pin;

pub async fn cast_then_await() {
    Box::pin(noop()) as Pin<Box<dyn Future<Output = ()>>>.await;
    //~^ ERROR: casts cannot be followed by `.await`
}

Meta

The ICE was introduced in 941343e0871dd04ea774e8cee7755461b144ef29

Error output

error[E0670]: `async fn` is not permitted in Rust 2015
 --> ./src/test/ui/parser/issue-35813-postfix-after-cast.rs:7:5
  |
7 | pub async fn cast_then_await() {
  |     ^^^^^ to use `async fn`, switch to Rust 2018 or later
  |
  = help: set `edition = "2018"` in `Cargo.toml`
  = note: for more on editions, read https://doc.rust-lang.org/edition-guide

error: casts cannot be followed by a field access
 --> ./src/test/ui/parser/issue-35813-postfix-after-cast.rs:8:5
  |
8 |     Box::pin(noop()) as Pin<Box<dyn Future<Output = ()>>>.await;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
help: try surrounding the expression in parentheses
  |
8 |     (Box::pin(noop()) as Pin<Box<dyn Future<Output = ()>>>).await;
  |     ^                                                     ^

error[E0425]: cannot find function `noop` in this scope
 --> ./src/test/ui/parser/issue-35813-postfix-after-cast.rs:8:14
  |
8 |     Box::pin(noop()) as Pin<Box<dyn Future<Output = ()>>>.await;
  |              ^^^^ not found in this scope

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:529:17: type parameter `A/#1` (A/1) out of range when substituting, substs=[std::boxed::Box<dyn std::future::Future<Output = ()>>]

thread 'rustc' panicked at 'Box<Any>', /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/compiler/rustc_errors/src/lib.rs:904:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.51.0-nightly (e0d9f7939 2021-02-01) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `cast_then_await`
#1 [mir_built] building MIR for `cast_then_await`
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0425, E0670.
For more information about an error, try `rustc --explain E0425`.
Backtrace

``` error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:529:17: type parameter `A/#1` (A/1) out of range when substituting, substs=[std::boxed::Box>] thread 'rustc' panicked at 'Box', /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/compiler/rustc_errors/src/lib.rs:904:9 stack backtrace: 0: 0x7f9533c47f77 - std::backtrace_rs::backtrace::libunwind::trace::h8bc78f7bc1f75bdb at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5 1: 0x7f9533c47f77 - std::backtrace_rs::backtrace::trace_unsynchronized::ha4c961c9576f95ba at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f9533c47f77 - std::sys_common::backtrace::_print_fmt::hc20cfdc233d6eb02 at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/sys_common/backtrace.rs:67:5 3: 0x7f9533c47f77 - ::fmt::h04bea14549780a0f at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/sys_common/backtrace.rs:46:22 4: 0x7f9533cb8e6c - core::fmt::write::h3868db8542c90941 at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/core/src/fmt/mod.rs:1096:17 5: 0x7f9533c3a7a2 - std::io::Write::write_fmt::h55dd75636eef6a5c at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/io/mod.rs:1568:15 6: 0x7f9533c4bed5 - std::sys_common::backtrace::_print::h6439e8525077c7da at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/sys_common/backtrace.rs:49:5 7: 0x7f9533c4bed5 - std::sys_common::backtrace::print::h02b685f728ce3931 at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/sys_common/backtrace.rs:36:9 8: 0x7f9533c4bed5 - std::panicking::default_hook::{{closure}}::h7c29625065fafae1 at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/panicking.rs:208:50 9: 0x7f9533c4ba33 - std::panicking::default_hook::hba441710bb71f4d5 at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/panicking.rs:225:9 10: 0x7f95344a50fb - rustc_driver::report_ice::h6029ac9bafd12823 11: 0x7f9533c4c7d6 - std::panicking::rust_panic_with_hook::ha936eb00e51bc4d9 at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/panicking.rs:595:17 12: 0x7f9535847f0e - std::panicking::begin_panic::{{closure}}::hdae1e04dfcfc639b 13: 0x7f9535847da9 - std::sys_common::backtrace::__rust_end_short_backtrace::hd6dc708cb1fca797 14: 0x7f9535847e12 - std::panicking::begin_panic::h59fa958ece2a476b 15: 0x7f9535aaf5cc - rustc_errors::HandlerInner::span_bug::h0ec02a9dae95f144 16: 0x7f9535ab01b3 - rustc_errors::Handler::span_bug::h05fed40c7f0d45e6 17: 0x7f9535ae7731 - rustc_middle::ty::context::tls::with_opt::hc2a6a371078389e7 18: 0x7f95373dad80 - rustc_middle::util::bug::opt_span_bug_fmt::h7e8cf5e228b48603 19: 0x7f9535aedeac - rustc_middle::util::bug::span_bug_fmt::h61c63dec8ea28135 20: 0x7f9536749594 - ::fold_ty::hc0107cf03ba5d160 21: 0x7f95367dbbc3 - rustc_middle::ty::FieldDef::ty::h994a756965c6f648 22: 0x7f95349f1a62 - rustc_typeck::check::expr::::check_for_nested_field::hebcd688c86a9215f 23: 0x7f95349f1b1c - rustc_typeck::check::expr::::check_for_nested_field::hebcd688c86a9215f 24: 0x7f9535f20cda - rustc_typeck::check::expr::::check_expr_kind::hd81ec70dfc42c6e0 25: 0x7f9535f18825 - rustc_typeck::check::expr::::check_expr_with_expectation::h07813aaad007b57a 26: 0x7f9535f2f3c6 - rustc_typeck::check::fn_ctxt::checks::::check_stmt::hbf963b81ede9ede1 27: 0x7f9535f2fd3e - rustc_typeck::check::fn_ctxt::checks::::check_block_with_expected::h526b5bb73f609d40 28: 0x7f9535f18825 - rustc_typeck::check::expr::::check_expr_with_expectation::h07813aaad007b57a 29: 0x7f9535f18825 - rustc_typeck::check::expr::::check_expr_with_expectation::h07813aaad007b57a 30: 0x7f9535f2fd72 - rustc_typeck::check::fn_ctxt::checks::::check_block_with_expected::h526b5bb73f609d40 31: 0x7f9535f18825 - rustc_typeck::check::expr::::check_expr_with_expectation::h07813aaad007b57a 32: 0x7f9535f24f08 - rustc_typeck::check::expr::::check_return_expr::h4ff0e0dbebbfe070 33: 0x7f9535f536c7 - rustc_typeck::check::check::check_fn::h00c489a359a0389f 34: 0x7f9535f141ea - rustc_typeck::check::closure::::check_expr_closure::h6ebe25414ecfb7d1 35: 0x7f9535f1bf95 - rustc_typeck::check::expr::::check_expr_kind::hd81ec70dfc42c6e0 36: 0x7f9535f18825 - rustc_typeck::check::expr::::check_expr_with_expectation::h07813aaad007b57a 37: 0x7f9535f2d20b - rustc_typeck::check::fn_ctxt::checks::::check_argument_types::hf91eb4df9a1a17d0 38: 0x7f9535f12441 - rustc_typeck::check::callee::::confirm_builtin_call::h8486a4c735573b0c 39: 0x7f9535f10bb6 - rustc_typeck::check::callee::::check_call::h40de6b39d9bd3630 40: 0x7f9535f19233 - rustc_typeck::check::expr::::check_expr_kind::hd81ec70dfc42c6e0 41: 0x7f9535f18825 - rustc_typeck::check::expr::::check_expr_with_expectation::h07813aaad007b57a 42: 0x7f9535f24f08 - rustc_typeck::check::expr::::check_return_expr::h4ff0e0dbebbfe070 43: 0x7f9535f536c7 - rustc_typeck::check::check::check_fn::h00c489a359a0389f 44: 0x7f953601e125 - rustc_infer::infer::InferCtxtBuilder::enter::h3e7527764ffa9f0a 45: 0x7f9536031a02 - rustc_typeck::check::typeck::h113247b58c447d56 46: 0x7f95373ef293 - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::h27bb48bfa2deb7af 47: 0x7f95372aa5dc - rustc_middle::ty::query::plumbing::::start_query::{{closure}}::{{closure}}::{{closure}}::h9d95dbc61876508c 48: 0x7f95367a640f - rustc_query_system::query::plumbing::force_query_with_job::hf60085a2311782e6 49: 0x7f9536770d91 - rustc_query_system::query::plumbing::get_query_impl::h7fcccd7a01615de1 50: 0x7f95367d12cb - rustc_middle::ty::context::TyCtxt::typeck_opt_const_arg::hbae7650a277222f2 51: 0x7f95361d7802 - rustc_infer::infer::InferCtxtBuilder::enter::h306129bd89460654 52: 0x7f95361846af - rustc_mir_build::build::mir_built::ha7b1ee942555e765 53: 0x7f9536376575 - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::mir_built>::compute::h48904240fdb27966 54: 0x7f95362678eb - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::h72f394eff9f14175 55: 0x7f953629ecd9 - rustc_middle::ty::query::plumbing::::start_query::{{closure}}::{{closure}}::{{closure}}::h51de787e3e2f9a20 56: 0x7f953636d703 - rustc_query_system::query::plumbing::force_query_with_job::hf34e1ef95b731b82 57: 0x7f953635ff70 - rustc_query_system::query::plumbing::get_query_impl::ha20f54477ec1657a 58: 0x7f953638c1b5 - rustc_mir::transform::check_unsafety::unsafety_check_result::h1d95c842e338a43e 59: 0x7f953637c132 - core::ops::function::FnOnce::call_once::h7681b661fb0996b5 60: 0x7f95362c7fac - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::unsafety_check_result>::compute::h114bce804998c2b5 61: 0x7f95362692b3 - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::hd849e105cb9446f0 62: 0x7f953629ec17 - rustc_middle::ty::query::plumbing::::start_query::{{closure}}::{{closure}}::{{closure}}::h3189e2ef759c787a 63: 0x7f953636afb5 - rustc_query_system::query::plumbing::force_query_with_job::h55c14fdb18f9d21a 64: 0x7f95363664a7 - rustc_query_system::query::plumbing::get_query_impl::hd320c2b44dfe9e5c 65: 0x7f9536368ab1 - rustc_query_system::query::plumbing::ensure_query_impl::ha3094ecd18a36130 66: 0x7f95362e23d9 - rustc_mir::transform::mir_const::hb1c731185d52fb7c 67: 0x7f95362c7d65 - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::mir_const>::compute::h2f92598270bc84fa 68: 0x7f95362678eb - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::h72f394eff9f14175 69: 0x7f953629ecd9 - rustc_middle::ty::query::plumbing::::start_query::{{closure}}::{{closure}}::{{closure}}::h51de787e3e2f9a20 70: 0x7f953636d703 - rustc_query_system::query::plumbing::force_query_with_job::hf34e1ef95b731b82 71: 0x7f953635ff70 - rustc_query_system::query::plumbing::get_query_impl::ha20f54477ec1657a 72: 0x7f95362e2a7e - rustc_mir::transform::mir_promoted::hfd03776ab4ea681b 73: 0x7f9536390155 - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::mir_promoted>::compute::h6265ff7afd976145 74: 0x7f9536267f5d - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::h7d2a534fbe5e2b5d 75: 0x7f95362a3a3a - rustc_data_structures::stack::ensure_sufficient_stack::h11bea39979767815 76: 0x7f953636b903 - rustc_query_system::query::plumbing::force_query_with_job::h63d6d6b73f5ba35a 77: 0x7f9536351e95 - rustc_query_system::query::plumbing::get_query_impl::h47923df1dced4b9b 78: 0x7f95363a9a10 - rustc_mir::borrow_check::mir_borrowck::h20ccfe939d3a3a56 79: 0x7f95363905e2 - core::ops::function::FnOnce::call_once::h79d8e683c54ef83a 80: 0x7f9536c43abc - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::mir_borrowck>::compute::h58752fbb19297f0e 81: 0x7f9536b85a53 - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::h8acc93aecc8ed558 82: 0x7f9536bc7277 - rustc_middle::ty::query::plumbing::::start_query::{{closure}}::{{closure}}::{{closure}}::h29cb493336ddfe28 83: 0x7f9536c12618 - rustc_query_system::query::plumbing::force_query_with_job::h9d3c013bae4da5d6 84: 0x7f9536c00663 - rustc_query_system::query::plumbing::get_query_impl::hb26e3245160c76aa 85: 0x7f9536035530 - rustc_typeck::collect::type_of::type_of::ha4dcfab0f27f7038 86: 0x7f9536b8d560 - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::type_of>::compute::hfb1e7762b6aa76f0 87: 0x7f9535f4aea9 - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::he8ff1da88a1eccfd 88: 0x7f9535f834e0 - rustc_middle::ty::query::plumbing::::start_query::{{closure}}::{{closure}}::{{closure}}::h87b67c70bbe55b5f 89: 0x7f9535fea039 - rustc_query_system::query::plumbing::force_query_with_job::h95ec8f5b87f94ba9 90: 0x7f9535faf4f9 - rustc_query_system::query::plumbing::get_query_impl::h05c3a23c5103863d 91: 0x7f9535f56b7a - rustc_typeck::check::check::check_item_type::hafadd4e0d2dd7282 92: 0x7f9535f5efa2 - rustc_middle::hir::map::Map::visit_item_likes_in_module::hcabc11564900da0e 93: 0x7f9536b98c5c - rustc_typeck::check::check::check_mod_item_types::hd93010c12eac828e 94: 0x7f9536be4b9c - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::check_mod_item_types>::compute::hffe8f3ab44cdce5e 95: 0x7f9535f4a1c3 - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::hc50d188197926cdb 96: 0x7f9535f84775 - rustc_data_structures::stack::ensure_sufficient_stack::h76ec031ca3305d3e 97: 0x7f9535feb695 - rustc_query_system::query::plumbing::force_query_with_job::hc160624985ac14e9 98: 0x7f9535fe268f - rustc_query_system::query::plumbing::get_query_impl::hf100fe0884000017 99: 0x7f9535fe6007 - rustc_query_system::query::plumbing::ensure_query_impl::he59c10c66d1391ed 100: 0x7f9536bf0a21 - rustc_typeck::check_crate::h244544240d36d5a2 101: 0x7f9535e0bb8e - rustc_interface::passes::analysis::h464b015ec4fd1c4d 102: 0x7f953687e729 - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::analysis>::compute::h488ee7db58e17433 103: 0x7f953687d28e - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::h1ed17ff8c9334b72 104: 0x7f953687e807 - rustc_middle::ty::query::plumbing::::start_query::{{closure}}::{{closure}}::{{closure}}::hc07cb02ad54c9494 105: 0x7f9536863b99 - rustc_query_system::query::plumbing::force_query_with_job::h538a34873cd1fd46 106: 0x7f9536862f72 - rustc_query_system::query::plumbing::get_query_impl::h2b3ae432496b0c86 107: 0x7f953687e9ba - rustc_interface::passes::QueryContext::enter::h8fe0bfc836a76a84 108: 0x7f95368467d3 - rustc_interface::queries::::enter::h734423f4595e60ef 109: 0x7f953687e134 - rustc_span::with_source_map::h0b3994d7a2f67198 110: 0x7f95368477b7 - rustc_interface::interface::create_compiler_and_run::h4d7ef2129059135c 111: 0x7f953687edff - std::sys_common::backtrace::__rust_begin_short_backtrace::hcb0be55fe1a86377 112: 0x7f953686470a - core::ops::function::FnOnce::call_once{{vtable.shim}}::h0363f9b03bb4d9ca 113: 0x7f9533c5ccea - as core::ops::function::FnOnce>::call_once::h2895277a71fc2628 at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/alloc/src/boxed.rs:1521:9 114: 0x7f9533c5ccea - as core::ops::function::FnOnce>::call_once::h1b199c68a8d0f31e at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/alloc/src/boxed.rs:1521:9 115: 0x7f9533c5ccea - std::sys::unix::thread::Thread::new::thread_start::h565bef3956c58d58 at /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/library/std/src/sys/unix/thread.rs:71:17 116: 0x7f9533b4d3e9 - start_thread 117: 0x7f9533a6a293 - __GI___clone 118: 0x0 - 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.51.0-nightly (e0d9f7939 2021-02-01) running on x86_64-unknown-linux-gnu query stack during panic: #0 [typeck] type-checking `cast_then_await` #1 [mir_built] building MIR for `cast_then_await` #2 [unsafety_check_result] unsafety-checking `cast_then_await` #3 [mir_const] processing MIR for `cast_then_await` #4 [mir_promoted] processing `cast_then_await` #5 [mir_borrowck] borrow-checking `cast_then_await` #6 [type_of] computing type of `cast_then_await::{opaque#0}` #7 [check_mod_item_types] checking item types in top-level module #8 [analysis] running analysis passes on this crate end of query stack error: aborting due to 4 previous errors Some errors have detailed explanations: E0425, E0670. For more information about an error, try `rustc --explain E0425`. ```

matthiaskrgr commented 3 years ago

Another more simple example which causes a slightly different ICE:

pub struct Builder {
    stack: Box<i32>,
}

fn run(builder: &Builder) {
    if builder.notfound {}
}

pub fn main() {}
error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:529:17: type parameter `T/#0` (T/0) out of range when substituting, substs=[]

thread 'rustc' panicked at 'Box<Any>', /rustc/e0d9f793990d20f8f640097e28556886ba5362f0/compiler/rustc_errors/src/lib.rs:904:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.51.0-nightly (e0d9f7939 2021-02-01) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `run`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to previous error
matthiaskrgr commented 3 years ago

https://github.com/rust-lang/rust/pull/81480 (part of the rollup) looks suspicious