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

rustc paniced: DefId::expect_local #92813

Closed
dvdsk opened this issue Jan 12, 2022 · 2 comments
Closed

rustc paniced: DefId::expect_local #92813

dvdsk opened this issue Jan 12, 2022 · 2 comments
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

@dvdsk
Copy link
Contributor

dvdsk commented Jan 12, 2022

I ran into a compiler panic while playing around with try streams and dyn.

I can only reproduce the example by keeping some code in a seperate libary. I have not removed a dependency on the futures (0.3.19) as that would mean moving alot of traits into the example. I set up a repo to easily replicate this example here.

Code

// client/src/main.rs
use futures::{Stream, stream};

pub fn main() {}

struct State (Option<Box<dyn Stream<Item = Result<lib::P, lib::E>>>>);

fn stream() {
    Box::pin(stream::unfold(State(None), move |state| async move {
        let stream = lib::unpack_stream().await.unwrap();
        let stream = Box::new(stream);
        state.0 = Some(stream);
        Some(((), state))
    }))
}

with as separate lib

// lib/src/lib.rs
use futures::{stream, StreamExt, TryStream, TryStreamExt};

#[derive(Debug)]
pub enum E {
    Empty,
}
pub struct P;

pub async fn unpack_stream() -> Result<impl TryStream<Ok = P, Error = E>, E> {
    let state = ();

    let stream = stream::try_unfold(state, state_machine);
    // this is needed as try_next needs Pin<TryStream> an TryStream is
    // not implemented for Pin<TryStream>
    Ok(stream.into_stream().boxed())
}

async fn state_machine(_: ()) -> Result<Option<(P, ())>, E> {
    Ok(None)
}

Meta

rustc --version --verbose:

rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'DefId::expect_local: `DefId(33:20 ~ lib[5f99]::unpack_stream::{opaque#0}::{opaque#0})`
 isn't local', /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/compiler/rustc_span/src/def_id.rs:234:43
Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
   2: rustc_middle::ty::error::<impl rustc_middle::ty::context::TyCtxt>::suggest_constraining_opaque_associated_ty
pe
   3: rustc_middle::ty::error::<impl rustc_middle::ty::context::TyCtxt>::note_and_explain_type_err
   4: rustc_infer::infer::error_reporting::<impl rustc_infer::infer::InferCtxt>::note_type_err
   5: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtPrivExt>::report_
projection_error
   6: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_fulf
illment_errors
   7: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
   8: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::confirm_builtin_call
   9: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  10: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  11: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  12: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  13: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  14: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  15: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  16: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  17: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  18: rustc_typeck::check::check::check_fn
  19: rustc_typeck::check::closure::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_closure
  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_and_args
  22: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  23: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::confirm_builtin_call
  24: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  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_and_args
  27: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  28: rustc_typeck::check::check::check_fn
  29: rustc_typeck::check::closure::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_closure
  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_and_args
  32: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  33: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::confirm_builtin_call
  34: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  35: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  36: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  37: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  38: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::confirm_builtin_call
  39: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  40: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  41: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  42: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  43: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  44: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  45: rustc_typeck::check::check::check_fn
  46: rustc_infer::infer::InferCtxtBuilder::enter
  47: rustc_typeck::check::typeck
  48: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  49: rustc_data_structures::stack::ensure_sufficient_stack
  50: rustc_query_system::query::plumbing::try_execute_query
  51: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  52: rustc_typeck::check::typeck
  53: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  54: rustc_data_structures::stack::ensure_sufficient_stack
  55: rustc_query_system::query::plumbing::try_execute_query
  56: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  57: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  58: rustc_data_structures::sync::par_for_each_in
  59: rustc_typeck::check::typeck_item_bodies
  60: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  61: rustc_data_structures::stack::ensure_sufficient_stack
  62: rustc_query_system::query::plumbing::try_execute_query
  63: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
  64: rustc_session::utils::<impl rustc_session::session::Session>::time
  65: rustc_typeck::check_crate
  66: rustc_interface::passes::analysis
  67: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  68: rustc_data_structures::stack::ensure_sufficient_stack
  69: rustc_query_system::query::plumbing::try_execute_query
  70: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  71: rustc_interface::passes::QueryContext::enter
  72: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  73: rustc_span::with_source_map
  74: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@dvdsk dvdsk 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 12, 2022
@compiler-errors
Copy link
Member

I believe this is fixed in #89946. @dvdsk, is it possible to try compiling this code with nightly?

@dvdsk
Copy link
Contributor Author

dvdsk commented Jan 13, 2022

The compiler no longer crashes using the current nightly. So this is fixed already :)
(I had tried nightly but now see I had forgotten to update the toolchain.)

@dvdsk dvdsk closed this as completed Jan 13, 2022
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

No branches or pull requests

2 participants