Skip to content

rustc_mir::borrow_check::region_infer::RegionInferenceContext::find_outlives_blame_span called Option::unwrap() on a None value #80772

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
kpreid opened this issue Jan 7, 2021 · 7 comments · Fixed by #90936
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kpreid
Copy link
Contributor

kpreid commented Jan 7, 2021

Code

trait SomeTrait {}

struct Exhibit {
    constant: usize,
    factory: fn(&usize) -> Box<dyn SomeTrait>,
}

const A_CONSTANT: &[Exhibit] = &[
    Exhibit {
        constant: 1,
        factory: |_| unimplemented!(),
    },
    Exhibit {
        constant: "Hello world".len(),
        factory: |_| unimplemented!(),
    },
];

On playground

Meta

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-apple-darwin
release: 1.49.0

Also happens on 1.48.0 and nightly.

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_mir/src/borrow_check/region_infer/mod.rs:2120:35

error: internal compiler error: unexpected panic

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.49.0 (e1884a8e3 2020-12-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_borrowck] borrow-checking `A_CONSTANT`
#1 [analysis] running analysis passes on this crate
end of query stack
Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panicking.rs:495:5
   1: core::panicking::panic_fmt
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/panicking.rs:50:5
   3: rustc_mir::borrow_check::region_infer::RegionInferenceContext::find_outlives_blame_span
   4: rustc_mir::borrow_check::do_mir_borrowck
   5: rustc_infer::infer::InferCtxtBuilder::enter
   6: rustc_mir::borrow_check::mir_borrowck
   7: core::ops::function::FnOnce::call_once
   8: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
   9: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  10: rustc_data_structures::stack::ensure_sufficient_stack
  11: rustc_query_system::query::plumbing::get_query_impl
  12: rustc_query_system::query::plumbing::ensure_query_impl
  13: rustc_session::utils::<impl rustc_session::session::Session>::time
  14: rustc_interface::passes::analysis
  15: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  16: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  17: rustc_data_structures::stack::ensure_sufficient_stack
  18: rustc_query_system::query::plumbing::get_query_impl
  19: rustc_interface::passes::QueryContext::enter
  20: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  21: rustc_span::with_source_map
  22: rustc_interface::interface::create_compiler_and_run
  23: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@kpreid kpreid 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 Jan 7, 2021
@jonas-schievink jonas-schievink added A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 7, 2021
@kpreid
Copy link
Contributor Author

kpreid commented Jan 7, 2021

On taking another look at the issues I found before filing this one, it looks like #74599 might be the same thing, as it has a similar stack trace. That code sample requires nightly, however, and this one does not.

From a superficial examination (I know nothing about the compiler internals), both issues involve:

  • multiple subexpressions (an array expression or a match) where the problem is sensitive to the number of them even if they're seemingly irrelevant
  • a closure in one or more of the subexpressions
  • calling a method on a literal in a constant context

@camelid
Copy link
Member

camelid commented Jan 7, 2021

This also reproduces the ICE:

trait SomeTrait {}

struct Exhibit {
    constant: bool,
    factory: fn(&usize) -> Box<dyn SomeTrait>,
}

const A_CONSTANT: &[Exhibit] = &[
    Exhibit {
        constant: "".is_empty(),
        factory: |_| unimplemented!(),
    },
    Exhibit {
        constant: "".is_empty(),
        factory: |_| unimplemented!(),
    },
];

@camelid
Copy link
Member

camelid commented Jan 8, 2021

searched toolchains nightly-2019-11-01 through nightly-2020-01-30


********************************************************************************
Regression in nightly-2019-11-29
********************************************************************************

Regression was too long ago to bisect to an individual commit, but the commit range is e87a205...bbb664a.

@apiraino apiraino added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 14, 2021
@apiraino
Copy link
Contributor

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

JohnTitor added a commit to JohnTitor/glacier that referenced this issue Jan 15, 2021
JohnTitor added a commit to JohnTitor/glacier that referenced this issue Jan 15, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jan 15, 2021
@isabelmu
Copy link
Contributor

It looks like the ICE was introduced with #66642 / bbb664a.

The unwrap that triggers the ICE is at the end of RegionInferenceContext::best_blame_constraint.

Issue #74599, mentioned above by @kpreid, is triggered by a None on the same unwrap but the error was already happening earlier in history. I observed it with the immediate parent commit f453d11.

@isabelmu
Copy link
Contributor

Actually it looks like f9ed219 is the first commit with this issue

@JohnTitor
Copy link
Member

This is no longer ICE with the latest nightly, I think #88698 is the fix. Marking as E-needs-test.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 15, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 16, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 16, 2021
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 16, 2021
Rollup of 8 pull requests

Successful merges:

 - rust-lang#86455 (check where-clause for explicit `Sized` before suggesting `?Sized`)
 - rust-lang#90801 (Normalize both arguments of `equate_normalized_input_or_output`)
 - rust-lang#90803 (Suggest `&str.chars()` on attempt to `&str.iter()`)
 - rust-lang#90819 (Fixes incorrect handling of TraitRefs when emitting suggestions.)
 - rust-lang#90910 (fix getting the discriminant of a zero-variant enum)
 - rust-lang#90925 (rustc_mir_build: reorder bindings)
 - rust-lang#90928 (Use a different server for checking clock drift)
 - rust-lang#90936 (Add a regression test for rust-lang#80772)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in c73b35e Nov 16, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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.

7 participants