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' panicked at 'called Option::unwrap() on a None value', src/librustc_typeck/check/method/suggest.rs:550:46 #69725

Closed
sunny-g opened this issue Mar 5, 2020 · 4 comments · Fixed by #69727
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sunny-g
Copy link

sunny-g commented Mar 5, 2020

I tried code very similar to this:

use serde::de::*;

pub trait IpldVisitorExt<'de>: Visitor<'de> {
    fn visit_link<E>(self, _cid: Cid) -> Result<<Self as Visitor<'de>>::Value, E>
    where
        E: Error;
}

struct JsonVisitor<V>(V);

impl<'de, V: IpldVisitorExt<'de>> Visitor<'de> for JsonVisitor<V> {
    type Value = V::Value;

    #[inline]
    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
        formatter.write_str("a JSON map, link object or byte object")
    }

    #[inline]
    fn visit_map<A>(self, map: A) -> Result<Self::Value, A::Error>
    where
        A: MapAccess<'de>,
    {
        let deserializer = value::MapAccessDeserializer::<A>::new(map);
        
        // uncommenting the following line triggers the error
        // let temp: value::MapAccessDeserializer<A> = deserializer.clone();

        Err(Error::custom(""))
    }
}

and it produces some type of type checking error when uncommenting the line beginning with let temp.

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/librustc_typeck/check/method/suggest.rs:550:46
...
query stack during panic:
#0 [typeck_tables_of] type-checking `<codec::dag_json::JsonVisitor<V> as serde::de::Visitor<'de>>::visit_map`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack

Meta

rustc --version --verbose:

rustc 1.43.0-nightly (4ad624882 2020-03-03)
binary: rustc
commit-hash: 4ad62488258972bdb0e2df225d100f99ef58dbad
commit-date: 2020-03-03
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0

Backtrace:

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/librustc_typeck/check/method/suggest.rs:550:46
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1053
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1428
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: rustc_driver::report_ice
  11: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at /rustc/4ad62488258972bdb0e2df225d100f99ef58dbad/src/liballoc/boxed.rs:1031
  12: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}::{{closure}}
             at /rustc/4ad62488258972bdb0e2df225d100f99ef58dbad/src/libproc_macro/bridge/client.rs:305
  13: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
  14: rust_begin_unwind
             at src/libstd/panicking.rs:378
  15: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  16: core::panicking::panic
             at src/libcore/panicking.rs:52
  17: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  18: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  19: rustc_typeck::check::method::suggest::<impl rustc_typeck::check::FnCtxt>::report_method_error
  20: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  21: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  22: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_coercable_to_type
  23: rustc_typeck::check::FnCtxt::check_decl_local
  24: rustc_typeck::check::FnCtxt::check_stmt
  25: rustc_typeck::check::FnCtxt::check_block_with_expected
  26: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  27: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  28: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  29: rustc_typeck::check::check_fn
  30: rustc::ty::context::GlobalCtxt::enter_local
  31: rustc_typeck::check::typeck_tables_of
  32: rustc::ty::query::__query_compute::typeck_tables_of
  33: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  34: rustc::dep_graph::graph::DepGraph::with_task_impl
  35: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  36: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  37: rustc_typeck::check::typeck_item_bodies
  38: rustc::ty::query::__query_compute::typeck_item_bodies
  39: rustc::dep_graph::graph::DepGraph::with_task_impl
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  41: rustc_typeck::check_crate
  42: rustc_interface::passes::analysis
  43: rustc::ty::query::__query_compute::analysis
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  46: rustc::ty::context::tls::enter_global
  47: rustc_interface::interface::run_compiler_in_existing_thread_pool
  48: rustc_ast::attr::with_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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.43.0-nightly (4ad624882 2020-03-03) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

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

query stack during panic:
#0 [typeck_tables_of] type-checking `<codec::dag_json::JsonVisitor<V> as serde::de::Visitor<'de>>::visit_map`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack

@sunny-g
Copy link
Author

sunny-g commented Mar 5, 2020

The error is likely due to the fact that the trait bounds on visit_map don't include Clone for A: MapAccess<'de>, though the compiler/type checker crashing is still likely a bug.

@JohnTitor JohnTitor added 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) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 5, 2020
@JohnTitor
Copy link
Member

That code was introduced in #69255, cc @estebank. Submitted #69727 as a quick fix.

Centril added a commit to Centril/rust that referenced this issue Mar 6, 2020
Avoid using `unwrap()` in suggestions

Addresses rust-lang#69725, still need a regression test.

r? @estebank
Centril added a commit to Centril/rust that referenced this issue Mar 6, 2020
Avoid using `unwrap()` in suggestions

Addresses rust-lang#69725, still need a regression test.

r? @estebank
@hellow554
Copy link
Contributor

hellow554 commented Mar 6, 2020

I can't get it to work in the same crate, just with two crates, where the first one depends on the other:

src/main.rs

use other_crate::Struct;

fn crash<A>() {
    let _ = Struct::<A>::new().clone();
}

fn main() {}

other_crate/src/lib.rs

#[derive(Clone)]
pub struct Struct<A>(A);

impl<A> Struct<A> {
    pub fn new() -> Self {
        todo!()
    }
}

@rustbot modify labels: -E-needs-mcve

@rustbot rustbot removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Mar 6, 2020
@JohnTitor
Copy link
Member

Thanks @hellow554! I included a test in the PR.

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) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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.

4 participants