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 "no index for a field" #104613

Closed
jruderman opened this issue Nov 19, 2022 · 1 comment · Fixed by #105267
Closed

ICE "no index for a field" #104613

jruderman opened this issue Nov 19, 2022 · 1 comment · Fixed by #105267
Assignees
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

@jruderman
Copy link
Contributor

Found with a modified fuzz-rustc

Code

struct S {
    a: u32,
}

fn main() {
    let s1 = S { a: 1 };

    let _ = || {
        let s2 = Oops { a: 2, ..s1 };
    };
}

Error output

error[E0422]: cannot find struct, variant or union type `Oops` in this scope
 --> src/main.rs:9:18
  |
9 |         let s2 = Oops { a: 2, ..s1 };
  |                  ^^^^ not found in this scope

thread '<unnamed>' panicked at 'no index for a field', compiler/rustc_middle/src/ty/mod.rs:2326:9
Backtrace

stack backtrace:
   0:        0x105fd1c52 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h65371da71ea634a1
   1:        0x1060306aa - core::fmt::write::h42d20afb3c5ee095
   2:        0x105fc3f0c - std::io::Write::write_fmt::h8d5b26d0e53ddd7f
   3:        0x105fd1a1a - std::sys_common::backtrace::print::hb5fe5178795d9f17
   4:        0x105fd4d46 - std::panicking::default_hook::{{closure}}::hff2fd60e97cc3869
   5:        0x105fd4a97 - std::panicking::default_hook::hc3f9a1de84e0ed9d
   6:        0x1148f4aed - rustc_driver[13343b5551cdacdb]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x105fd552d - std::panicking::rust_panic_with_hook::h1c5a191a8000993f
   8:        0x105fd52d3 - std::panicking::begin_panic_handler::{{closure}}::hd5b348ff58d0d76f
   9:        0x105fd20e8 - std::sys_common::backtrace::__rust_end_short_backtrace::h724f40d3ad4af19e
  10:        0x105fd4f9d - _rust_begin_unwind
  11:        0x10605d443 - core::panicking::panic_fmt::hc08710230bc1c166
  12:        0x10602d1db - core::panicking::panic_display::h484762008229854f
  13:        0x10602d18c - core::panicking::panic_str::h21235dd98dd92f90
  14:        0x10605d409 - core::option::expect_failed::hfda067ca1d1574cb
  15:        0x11910855a - <rustc_middle[fb39214eb358b7b2]::ty::context::TyCtxt>::field_index
  16:        0x117234dfc - <rustc_hir_typeck[280d4fd6d44492fc]::expr_use_visitor::ExprUseVisitor>::walk_expr
  17:        0x1172357f5 - <rustc_hir_typeck[280d4fd6d44492fc]::expr_use_visitor::ExprUseVisitor>::walk_local::<<rustc_hir_typeck[280d4fd6d44492fc]::expr_use_visitor::ExprUseVisitor>::walk_stmt::{closure#0}>
  18:        0x1172353e6 - <rustc_hir_typeck[280d4fd6d44492fc]::expr_use_visitor::ExprUseVisitor>::walk_expr
  19:        0x11723310c - <rustc_hir_typeck[280d4fd6d44492fc]::expr_use_visitor::ExprUseVisitor>::consume_expr
  20:        0x1172362d7 - <rustc_hir_typeck[280d4fd6d44492fc]::expr_use_visitor::ExprUseVisitor>::consume_body
  21:        0x117112ff6 - <rustc_hir_typeck[280d4fd6d44492fc]::fn_ctxt::FnCtxt>::analyze_closure
  22:        0x11721c968 - <rustc_hir_typeck[280d4fd6d44492fc]::upvar::InferBorrowKindVisitor as rustc_hir[30bdd25a7791883c]::intravisit::Visitor>::visit_expr
  23:        0x11714c7c8 - rustc_hir[30bdd25a7791883c]::intravisit::walk_local::<rustc_hir_typeck[280d4fd6d44492fc]::upvar::InferBorrowKindVisitor>
  24:        0x117154e4c - rustc_hir[30bdd25a7791883c]::intravisit::walk_expr::<rustc_hir_typeck[280d4fd6d44492fc]::upvar::InferBorrowKindVisitor>
  25:        0x1171e89ea - <rustc_hir_typeck[280d4fd6d44492fc]::inherited::InheritedBuilder>::enter::<rustc_hir_typeck[280d4fd6d44492fc]::typeck_with_fallback<rustc_hir_typeck[280d4fd6d44492fc]::typeck::{closure#0}>::{closure#0}::{closure#1}, &rustc_middle[fb39214eb358b7b2]::ty::context::TypeckResults>
  26:        0x11717ec4a - rustc_hir_typeck[280d4fd6d44492fc]::typeck
  27:        0x1180d3669 - rustc_query_system[1f9dfa1b3b6feb8f]::query::plumbing::try_execute_query::<rustc_query_impl[bea551e74a118b14]::plumbing::QueryCtxt, rustc_query_system[1f9dfa1b3b6feb8f]::query::caches::DefaultCache<rustc_span[3cd6c9c9c366901b]::def_id::LocalDefId, &rustc_middle[fb39214eb358b7b2]::ty::context::TypeckResults>>
  28:        0x1181cfb0c - rustc_query_system[1f9dfa1b3b6feb8f]::query::plumbing::get_query::<rustc_query_impl[bea551e74a118b14]::queries::typeck, rustc_query_impl[bea551e74a118b14]::plumbing::QueryCtxt>
  29:        0x11712ffcb - rustc_data_structures[65115343bf925642]::sync::par_for_each_in::<&[rustc_span[3cd6c9c9c366901b]::def_id::LocalDefId], <rustc_middle[fb39214eb358b7b2]::hir::map::Map>::par_body_owners<rustc_hir_typeck[280d4fd6d44492fc]::typeck_item_bodies::{closure#0}>::{closure#0}>
  30:        0x11717e3cd - rustc_hir_typeck[280d4fd6d44492fc]::typeck_item_bodies
  31:        0x118163e59 - rustc_query_system[1f9dfa1b3b6feb8f]::query::plumbing::try_execute_query::<rustc_query_impl[bea551e74a118b14]::plumbing::QueryCtxt, rustc_query_system[1f9dfa1b3b6feb8f]::query::caches::DefaultCache<(), ()>>
  32:        0x1181c43d9 - rustc_query_system[1f9dfa1b3b6feb8f]::query::plumbing::get_query::<rustc_query_impl[bea551e74a118b14]::queries::typeck_item_bodies, rustc_query_impl[bea551e74a118b14]::plumbing::QueryCtxt>
  33:        0x1173045ae - <rustc_session[d3dc83f7882946da]::session::Session>::time::<(), rustc_hir_analysis[65e5df12102afc97]::check_crate::{closure#7}>
  34:        0x11740de8f - rustc_hir_analysis[65e5df12102afc97]::check_crate
  35:        0x1149b155a - rustc_interface[bc80ce5eea40f24e]::passes::analysis
  36:        0x118155c1c - rustc_query_system[1f9dfa1b3b6feb8f]::query::plumbing::try_execute_query::<rustc_query_impl[bea551e74a118b14]::plumbing::QueryCtxt, rustc_query_system[1f9dfa1b3b6feb8f]::query::caches::DefaultCache<(), core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>>>
  37:        0x1181cfeb9 - rustc_query_system[1f9dfa1b3b6feb8f]::query::plumbing::get_query::<rustc_query_impl[bea551e74a118b14]::queries::analysis, rustc_query_impl[bea551e74a118b14]::plumbing::QueryCtxt>
  38:        0x1148b9a72 - <rustc_interface[bc80ce5eea40f24e]::passes::QueryContext>::enter::<rustc_driver[13343b5551cdacdb]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>>
  39:        0x1148cb94d - rustc_span[3cd6c9c9c366901b]::with_source_map::<core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>, rustc_interface[bc80ce5eea40f24e]::interface::run_compiler<core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>, rustc_driver[13343b5551cdacdb]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  40:        0x1148c222c - <scoped_tls[9f05bfe7696cff9b]::ScopedKey<rustc_span[3cd6c9c9c366901b]::SessionGlobals>>::set::<rustc_interface[bc80ce5eea40f24e]::interface::run_compiler<core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>, rustc_driver[13343b5551cdacdb]::run_compiler::{closure#1}>::{closure#0}, core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>>
  41:        0x11488a19a - std[b8dd7466c60cfdf8]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[bc80ce5eea40f24e]::util::run_in_thread_pool_with_globals<rustc_interface[bc80ce5eea40f24e]::interface::run_compiler<core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>, rustc_driver[13343b5551cdacdb]::run_compiler::{closure#1}>::{closure#0}, core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>>
  42:        0x11486c96b - <<std[b8dd7466c60cfdf8]::thread::Builder>::spawn_unchecked_<rustc_interface[bc80ce5eea40f24e]::util::run_in_thread_pool_with_globals<rustc_interface[bc80ce5eea40f24e]::interface::run_compiler<core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>, rustc_driver[13343b5551cdacdb]::run_compiler::{closure#1}>::{closure#0}, core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5f16df7105d54e]::result::Result<(), rustc_errors[56d5964ce0535c75]::ErrorGuaranteed>>::{closure#1} as core[5f16df7105d54e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:        0x105fde8e7 - std::sys::unix::thread::Thread::new::thread_start::h459496ec4dc9999f
  44:     0x7ff80d84d4e1 - __pthread_start

Regression

Regression in nightly-2022-11-06, somewhere in rollup commit 452cf4f

Version

rustc 1.67.0-nightly (b833ad56f 2022-11-18)
binary: rustc
commit-hash: b833ad56f46a0bbe0e8729512812a161e7dae28a
commit-date: 2022-11-18
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4
@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 19, 2022
@compiler-errors
Copy link
Member

This probably regressed in #103867, since we're no longer replacing block values with ty::Error which I think caused the ExprUseVisitor to bail early while walking HIR.

This probably can just be fixed by a more conservative check for field idx + a delayed bug, though someone who wants to claim this may find a more creative way of suppressing this error. Ideally, we'd check that the path Oops is actually resolved to a real ADT first, and skip this field check if so.

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

Successfully merging a pull request may close this issue.

2 participants