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

"DefId isn't local" ICE #81839

Closed
layderv opened this issue Feb 6, 2021 · 10 comments · Fixed by #81991
Closed

"DefId isn't local" ICE #81839

layderv opened this issue Feb 6, 2021 · 10 comments · Fixed by #81991
Assignees
Labels
C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@layderv
Copy link

layderv commented Feb 6, 2021

Code

The code is based on this example and the following git diff: https://github.com/teloxide/teloxide/tree/dev/examples/sqlite_remember_bot (commit fe6429c2790502ae09b04d2659f33e4495f6d314)

diff --git a/examples/sqlite_remember_bot/src/transitions.rs b/examples/sqlite_remember_bot/src/transitions.rs
index dcc78db..c8f1777 100644
--- a/examples/sqlite_remember_bot/src/transitions.rs
+++ b/examples/sqlite_remember_bot/src/transitions.rs
@@ -21,6 +21,15 @@ async fn have_number(
     ans: String,
 ) -> TransitionOut<Dialogue> {
     let num = state.number;
+    match ans {
+        "abc" => {
+            match num {
+                1 => { cx.answer_str("hi"); }
+                _ => cx.answer_str("hi")
+            }
+        }
+        _ => ()
+    };
 
     if ans.starts_with("/get") {
         cx.answer_str(format!("Here is your number: {}", num)).await?;

Meta

It fails on stable and nightly:

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.49.0 (e1884a8 2020-12-29)
binary: rustc
commit-hash: e1884a8
commit-date: 2020-12-29
host: x86_64-unknown-linux-gnu
release: 1.49.0

and

rustc 1.51.0-nightly (04caa63 2021-01-30)
binary: rustc
commit-hash: 04caa63
commit-date: 2021-01-30
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1

<version>

Error output

From stable, non verbose:

error[E0308]: mismatched types
  --> src/transitions.rs:25:9
   |
24 |     match ans {
   |           --- this expression has type `std::string::String`
25 |         "abc" => {
   |         ^^^^^ expected struct `std::string::String`, found `&str`

thread 'rustc' panicked at 'DefId::expect_local: `DefId(22:1034 ~ teloxide[eccd]::dispatching::update_with_cx::{impl#1}::answer_str::{opaque#0})` isn't local', /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/compiler/rustc_span/src/def_id.rs:175:43
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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 debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [typeck] type-checking `transitions::<impl teloxide::dispatching::dialogue::Subtransition for states::HaveNumberState>::react::have_number`
#1 [mir_built] building MIR for `transitions::<impl teloxide::dispatching::dialogue::Subtransition for states::HaveNumberState>::react::have_number`
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `sqlite_remember_bot`

Backtrace

error[E0308]: mismatched types
  --> src/transitions.rs:25:9
   |
24 |     match ans {
   |           --- this expression has type `std::string::String`
25 |         "abc" => {
   |         ^^^^^ expected struct `std::string::String`, found `&str`

thread 'rustc' panicked at 'DefId::expect_local: `DefId(22:1034 ~ teloxide[eccd]::dispatching::update_with_cx::{impl#1}::answer_str::{opaque#0})` isn't local', /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/compiler/rustc_span/src/def_id.rs:175:43
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panicking.rs:495:5
   1: std::panicking::begin_panic_fmt
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panicking.rs:437:5
   2: rustc_span::def_id::DefId::expect_local::{{closure}}
   3: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::could_remove_semicolon
   4: rustc_typeck::check::_match::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_match
   5: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
   6: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
   7: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
   8: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
   9: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  10: rustc_typeck::check::_match::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_match
  11: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  12: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  13: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  14: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  15: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  16: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  17: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  18: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  19: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  20: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  21: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  22: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  23: rustc_typeck::check::check::check_fn
  24: rustc_typeck::check::closure::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_closure
  25: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  26: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  27: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  28: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::confirm_builtin_call
  29: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  30: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  31: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  32: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  33: rustc_typeck::check::check::check_fn
  34: rustc_infer::infer::InferCtxtBuilder::enter
  35: rustc_typeck::check::typeck
  36: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  37: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  38: rustc_data_structures::stack::ensure_sufficient_stack
  39: rustc_query_system::query::plumbing::get_query_impl
  40: rustc_middle::ty::context::TyCtxt::typeck_opt_const_arg
  41: rustc_mir_build::thir::cx::Cx::new
  42: rustc_infer::infer::InferCtxtBuilder::enter
  43: rustc_mir_build::build::mir_built
  44: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_built>::compute
  45: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  46: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  47: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  48: rustc_query_system::query::plumbing::get_query_impl
  49: rustc_mir::transform::check_unsafety::unsafety_check_result
  50: core::ops::function::FnOnce::call_once
  51: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  52: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  53: rustc_data_structures::stack::ensure_sufficient_stack
  54: rustc_query_system::query::plumbing::force_query_impl
  55: rustc_middle::ty::query::force_from_dep_node
  56: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  57: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  58: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  59: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_green_and_read
  60: rustc_data_structures::stack::ensure_sufficient_stack
  61: rustc_query_system::query::plumbing::get_query_impl
  62: rustc_typeck::collect::type_of::type_of
  63: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::type_of>::compute
  64: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  65: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  66: rustc_data_structures::stack::ensure_sufficient_stack
  67: rustc_query_system::query::plumbing::get_query_impl
  68: rustc_typeck::check::check::check_item_type
  69: rustc_middle::hir::map::Map::visit_item_likes_in_module
  70: rustc_typeck::check::check::check_mod_item_types
  71: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_mod_item_types>::compute
  72: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  73: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  74: rustc_data_structures::stack::ensure_sufficient_stack
  75: rustc_query_system::query::plumbing::get_query_impl
  76: rustc_query_system::query::plumbing::ensure_query_impl
  77: rustc_session::utils::<impl rustc_session::session::Session>::time
  78: rustc_typeck::check_crate
  79: rustc_interface::passes::analysis
  80: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  81: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  82: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  83: rustc_data_structures::stack::ensure_sufficient_stack
  84: rustc_query_system::query::plumbing::get_query_impl
  85: rustc_interface::passes::QueryContext::enter
  86: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  87: rustc_span::with_source_map
  88: rustc_interface::interface::create_compiler_and_run
  89: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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 debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [typeck] type-checking `transitions::<impl teloxide::dispatching::dialogue::Subtransition for states::HaveNumberState>::react::have_number`
#1 [mir_built] building MIR for `transitions::<impl teloxide::dispatching::dialogue::Subtransition for states::HaveNumberState>::react::have_number`
#2 [unsafety_check_result] unsafety-checking `transitions::<impl teloxide::dispatching::dialogue::Subtransition for states::HaveNumberState>::react::have_number`
#3 [mir_borrowck] borrow-checking `transitions::<impl teloxide::dispatching::dialogue::Subtransition for states::HaveNumberState>::react::have_number`
#4 [type_of] computing type of `transitions::<impl teloxide::dispatching::dialogue::Subtransition for states::HaveNumberState>::react::have_number::{opaque#0}`
#5 [check_mod_item_types] checking item types in module `transitions`
#6 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `sqlite_remember_bot`

@layderv layderv 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 Feb 6, 2021
@jonas-schievink jonas-schievink changed the title Compiler error "DefId isn't local" ICE Feb 6, 2021
@jonas-schievink jonas-schievink added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 6, 2021
@LeSeulArtichaut
Copy link
Contributor

LeSeulArtichaut commented Feb 6, 2021

This looks like an incremental compilation ICE. Does it disappear after running cargo clean?

@LeSeulArtichaut
Copy link
Contributor

I can't reproduce the ICE, so it does look like an incremental bug

@LeSeulArtichaut LeSeulArtichaut added A-incr-comp Area: Incremental compilation E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Feb 6, 2021
@layderv
Copy link
Author

layderv commented Feb 6, 2021

This looks like an incremental compilation ICE. Does it disappear after running cargo clean?

It does. I have cloned that repo, modified the file as in the git diff above and run cargo build fresh too.

@layderv
Copy link
Author

layderv commented Feb 6, 2021

$ git clone https://github.com/teloxide/teloxide.git
Cloning into 'teloxide'...
remote: Enumerating objects: 114, done.
remote: Counting objects: 100% (114/114), done.
remote: Compressing objects: 100% (77/77), done.
remote: Total 14861 (delta 50), reused 66 (delta 37), pack-reused 14747
Receiving objects: 100% (14861/14861), done.
Resolving deltas: 100% (10379/10379), done.

$ cd teloxide/examples/sqlite_remember_bot/

# >>>> edit src/transitions.rs
# >>>> changing the file with the diff in the first comment above

$ cargo build
    Updating crates.io index
    Updating git repository `https://github.com/teloxide/teloxide-macros`
   Compiling proc-macro2 v1.0.24

...

   Compiling teloxide v0.3.4 (/tmp/teloxide)
   Compiling sqlite_remember_bot v0.1.0 (/tmp/teloxide/examples/sqlite_remember_bot)
error[E0308]: mismatched types
  --> src/transitions.rs:25:9
   |
24 |     match ans {
   |           --- this expression has type `std::string::String`
25 |         "abc" => {
   |         ^^^^^ expected struct `std::string::String`, found `&str`

thread 'rustc' panicked at 'DefId::expect_local: `DefId(22:1034 ~ teloxide[eccd]::dispatching::update_with_cx::{impl#1}::answer_str::{opaque#0})` isn't local', /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/compiler/rustc_span/src/def_id.rs:175:43
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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 debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [typeck] type-checking `transitions::<impl teloxide::dispatching::dialogue::Subtransition for states::HaveNumberState>::react::have_number`
#1 [mir_built] building MIR for `transitions::<impl teloxide::dispatching::dialogue::Subtransition for states::HaveNumberState>::react::have_number`
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `sqlite_remember_bot`

@layderv
Copy link
Author

layderv commented Feb 6, 2021

@LeSeulArtichaut

Sorry I had misread.

Does it disappear

No, it does not. Sorry for the confusion

@tmiasko
Copy link
Contributor

tmiasko commented Feb 6, 2021

Thanks for the report! I can reproduce with:

git clone https://github.com/teloxide/teloxide
cd teloxide/
git checkout fe6429c2790502ae09b04d2659f33e4495f6d314
cargo build --manifest-path examples/sqlite_remember_bot/Cargo.toml
git apply - <<EOF
diff --git a/examples/sqlite_remember_bot/src/transitions.rs b/examples/sqlite_remember_bot/src/transitions.rs
index dcc78db..c8f1777 100644
--- a/examples/sqlite_remember_bot/src/transitions.rs
+++ b/examples/sqlite_remember_bot/src/transitions.rs
@@ -21,6 +21,15 @@ async fn have_number(
     ans: String,
 ) -> TransitionOut<Dialogue> {
     let num = state.number;
+    match ans {
+        "abc" => {
+            match num {
+                1 => { cx.answer_str("hi"); }
+                _ => cx.answer_str("hi")
+            }
+        }
+        _ => ()
+    };
 
     if ans.starts_with("/get") {
         cx.answer_str(format!("Here is your number: {}", num)).await?;
EOF
cargo build --manifest-path examples/sqlite_remember_bot/Cargo.toml

@Aaron1011 Aaron1011 removed the A-incr-comp Area: Incremental compilation label Feb 7, 2021
@Aaron1011
Copy link
Member

This is caused by:

let last_hir_id = self.tcx.hir().local_def_id_to_hir_id(last_def_id.expect_local());
let exp_hir_id = self.tcx.hir().local_def_id_to_hir_id(exp_def_id.expect_local());

There is no guarantee that either last_def_id or exp_def_id is actually local.

@layderv
Copy link
Author

layderv commented Feb 7, 2021

I've never committed to this repository; if you want to guide me to fix this issue, I'm happy to do it. If it's better if you do it, no worries

@apiraino apiraino added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 11, 2021
@apiraino
Copy link
Contributor

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

@osa1
Copy link
Contributor

osa1 commented Feb 18, 2021

@rustbot claim

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 19, 2021
Fix panic in 'remove semicolon' when types are not local

It's not possible to check if removing a semicolon fixes the type error
when checking match arms and one or both of the last arm's and the
current arm's return types are imported "opaque" types. In these cases
we don't generate a "consider removing semicolon" suggestions.

Fixes rust-lang#81839

---

I'm not sure how to add a test for this. I think the test would need at least two crates. Do we have any existing tests that do this so that I can take a look?
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 20, 2021
Fix panic in 'remove semicolon' when types are not local

It's not possible to check if removing a semicolon fixes the type error
when checking match arms and one or both of the last arm's and the
current arm's return types are imported "opaque" types. In these cases
we don't generate a "consider removing semicolon" suggestions.

Fixes rust-lang#81839

---

I'm not sure how to add a test for this. I think the test would need at least two crates. Do we have any existing tests that do this so that I can take a look?
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 20, 2021
Fix panic in 'remove semicolon' when types are not local

It's not possible to check if removing a semicolon fixes the type error
when checking match arms and one or both of the last arm's and the
current arm's return types are imported "opaque" types. In these cases
we don't generate a "consider removing semicolon" suggestions.

Fixes rust-lang#81839

---

I'm not sure how to add a test for this. I think the test would need at least two crates. Do we have any existing tests that do this so that I can take a look?
@bors bors closed this as completed in 5fd1ebe Feb 21, 2021
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. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High 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