rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.26k stars 1.52k forks source link

note: the compiler unexpectedly panicked. this is a bug. #9508

Closed morenol closed 1 year ago

morenol commented 1 year ago
error: internal compiler error: compiler/rustc_middle/src/ty/sty.rs:1916:18: Ty::fn_sig() called on non-fn type: B

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/compiler/rustc_errors/src/lib.rs:1391:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new

note: Clippy version: clippy 0.1.63 (4b91a6ea 2022-08-08)

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack

Minimal reproduction:

Cargo.toml

[package]
name = "fluvio-ws-wasm"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
discard = "1.0.4"
pin-project = "1.0.10"
wasm-bindgen-futures = "0.4.33"
futures-signals = "0.3.31"
futures = "0.3.21"

src/lib.rs

use discard::DiscardOnDrop;
use futures_signals::signal_vec::{MutableSignalVec, MutableVec, SignalVec, VecDiff};
use futures_signals::{cancelable_future, CancelableFutureHandle};
use pin_project::pin_project;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use wasm_bindgen_futures::spawn_local;

use futures::{Stream, StreamExt};

#[pin_project]
struct CancelableSignalVec<S> {
    // This will automatically cancel the Future when the CancelableSignalVec struct is dropped
    _handle: DiscardOnDrop<CancelableFutureHandle>,
    #[pin]
    signal: S,
}

impl<A> CancelableSignalVec<MutableSignalVec<A>>
where
    A: Clone + 'static,
{
    async fn with_future_stream<E, F, S, B>(future: F, stream: S, mut eq: B) -> Result<Self, E>
    where
        F: Future<Output = Result<Vec<A>, E>>,
        S: Stream<Item = (Vec<A>, Vec<A>)> + Unpin + 'static,
        B: FnMut(&A, &A) -> bool + 'static,
    {
        let items = future.await?;

        // Skip first because it gets current state
        let skip = if items.is_empty() { 0 } else { 1 };

        let output = MutableVec::new_with_values(items);

        let signal = output.signal_vec_cloned();

        let (handle, future) = cancelable_future(
            async move {
                let mut changes = stream.skip(skip);

                // Get updates
                while let Some((added, deleted)) = changes.next().await {
                    let mut lock = output.lock_mut();

                    lock.retain(|old| deleted.iter().find(|new| eq(old, new)).is_none());

                    for new in added {
                        match lock.iter().position(|old| eq(old, &new)) {
                            Some(index) => {
                                lock.set_cloned(index, new);
                            }
                            None => {
                                lock.push_cloned(new);
                            }
                        }
                    }
                }
            },
            || (),
        );

        spawn_local(future);

        Ok(Self {
            _handle: handle,
            signal,
        })
    }
}

impl<S> SignalVec for CancelableSignalVec<S>
where
    S: SignalVec,
{
    type Item = S::Item;

    fn poll_vec_change(
        self: Pin<&mut Self>,
        cx: &mut Context,
    ) -> Poll<Option<VecDiff<Self::Item>>> {
        self.project().signal.poll_vec_change(cx)
    }
}
lukaslueg commented 1 year ago

Full stack trace:

warning: associated function `with_future_stream` is never used
  --> src/lib.rs:24:14
   |
24 |     async fn with_future_stream<E, F, S, B>(future: F, stream: S, mut eq: B) -> Result<Self, E>
   |              ^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

error: internal compiler error: compiler/rustc_middle/src/ty/sty.rs:1916:18: Ty::fn_sig() called on non-fn type: B

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/compiler/rustc_errors/src/lib.rs:1391:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug::<&alloc::string::String>
   3: <rustc_errors::Handler>::bug::<&alloc::string::String>
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_middle::ty::Ty>::fn_sig
   8: <clippy_utils::sugg::DerefDelegate as rustc_typeck::expr_use_visitor::Delegate>::borrow
   9: <rustc_typeck::expr_use_visitor::ExprUseVisitor>::walk_expr
  10: <rustc_typeck::expr_use_visitor::ExprUseVisitor>::consume_expr
  11: <rustc_typeck::expr_use_visitor::ExprUseVisitor>::walk_expr
  12: <rustc_typeck::expr_use_visitor::ExprUseVisitor>::consume_expr
  13: <rustc_typeck::expr_use_visitor::ExprUseVisitor>::consume_body
  14: <rustc_infer::infer::InferCtxtBuilder>::enter::<(), clippy_utils::sugg::deref_closure_args::{closure#0}>
  15: clippy_utils::sugg::deref_closure_args
  16: clippy_lints::methods::search_is_some::check
  17: clippy_lints::methods::check_is_some_is_none
  18: <clippy_lints::methods::Methods as rustc_lint::passes::LateLintPass>::check_expr
  19: <rustc_lint::late::LateLintPassObjects as rustc_lint::passes::LateLintPass>::check_expr
  20: rustc_hir::intravisit::walk_body::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  21: <rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects> as rustc_hir::intravisit::Visitor>::visit_nested_body
  22: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  23: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  24: rustc_hir::intravisit::walk_stmt::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  25: rustc_hir::intravisit::walk_block::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  26: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  27: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  28: rustc_hir::intravisit::walk_block::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  29: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  30: rustc_hir::intravisit::walk_block::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  31: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  32: rustc_hir::intravisit::walk_body::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  33: <rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects> as rustc_hir::intravisit::Visitor>::visit_nested_body
  34: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  35: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  36: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  37: rustc_hir::intravisit::walk_local::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  38: rustc_hir::intravisit::walk_stmt::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  39: rustc_hir::intravisit::walk_block::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  40: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  41: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  42: rustc_hir::intravisit::walk_block::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  43: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  44: rustc_hir::intravisit::walk_body::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  45: <rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects> as rustc_hir::intravisit::Visitor>::visit_nested_body
  46: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  47: rustc_hir::intravisit::walk_expr::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  48: rustc_hir::intravisit::walk_body::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  49: <rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects> as rustc_hir::intravisit::Visitor>::visit_nested_body
  50: rustc_hir::intravisit::walk_impl_item::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  51: <rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects> as rustc_hir::intravisit::Visitor>::visit_nested_impl_item
  52: rustc_hir::intravisit::walk_item::<rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects>>
  53: <rustc_lint::late::LateContextAndPass<rustc_lint::late::LateLintPassObjects> as rustc_hir::intravisit::Visitor>::visit_nested_item
  54: rustc_lint::late::late_lint_pass_crate::<rustc_lint::late::LateLintPassObjects>
  55: rustc_lint::late::late_lint_crate::<rustc_lint::BuiltinCombinedLateLintPass>
  56: <rustc_session::session::Session>::time::<(), rustc_lint::late::check_crate<rustc_lint::BuiltinCombinedLateLintPass, rustc_interface::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#0}::{closure#0}>
  57: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}>
  58: <core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::passes::analysis::{closure#5}::{closure#1}> as core::ops::function::FnOnce<()>>::call_once
  59: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#5}>
  60: rustc_interface::passes::analysis
  61: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  62: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorGuaranteed>>>
  63: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  64: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  65: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  66: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  67: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new

note: Clippy version: clippy 0.1.63 (4b91a6ea 2022-08-08)

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
warning: `issue9508` (lib) generated 1 warning
error: could not compile `issue9508`; 1 warning emitted
morenol commented 1 year ago

It looks like it was solved in stable release: 1.64.0