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.29k stars 1.52k forks source link

ICE: to get the signature of a closure, use ... #6256

Closed matthiaskrgr closed 3 years ago

matthiaskrgr commented 3 years ago

Code

code from ./src/test/ui/regions/issue-78262.rs

// revisions: nll default
// ignore-compare-mode-nll
//[nll]compile-flags: -Z borrowck=mir

trait TT {}

impl dyn TT {
    fn func(&self) {}
}

fn main() {
    let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
    //[nll]~^ ERROR: borrowed data escapes outside of closure
}

Meta

Error output

error: internal compiler error: compiler/rustc_typeck/src/collect.rs:1603:13: to get the signature of a closure, use `substs.as_closure().sig()` not `fn_sig()`

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:945: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.0.212 (ffa2e7a 2020-10-24)

query stack during panic:
#0 [fn_sig] computing function signature of `main::{closure#0}`
#1 [typeck] type-checking `main`
end of query stack
error: aborting due to previous error
Backtrace

``` error: internal compiler error: compiler/rustc_typeck/src/collect.rs:1603:13: to get the signature of a closure, use `substs.as_closure().sig()` not `fn_sig()` thread 'rustc' panicked at 'Box', compiler/rustc_errors/src/lib.rs:945:9 stack backtrace: 0: 0x7f93d4a1ea20 - std::backtrace_rs::backtrace::libunwind::trace::h303a626d53553a64 at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:100:5 1: 0x7f93d4a1ea20 - std::backtrace_rs::backtrace::trace_unsynchronized::h6abb882733c3f18c at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f93d4a1ea20 - std::sys_common::backtrace::_print_fmt::h57829321f1d9217a at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys_common/backtrace.rs:67:5 3: 0x7f93d4a1ea20 - ::fmt::h400b66a054640aac at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys_common/backtrace.rs:46:22 4: 0x7f93d4a8de9c - core::fmt::write::h1857a60b204f1b6a at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/fmt/mod.rs:1076:17 5: 0x7f93d4a10642 - std::io::Write::write_fmt::h6453b28c8b27c6ea at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/io/mod.rs:1516:15 6: 0x7f93d4a239d5 - std::sys_common::backtrace::_print::h15cc4b3923cc9bc0 at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys_common/backtrace.rs:49:5 7: 0x7f93d4a239d5 - std::sys_common::backtrace::print::h953c7be178c0674d at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys_common/backtrace.rs:36:9 8: 0x7f93d4a239d5 - std::panicking::default_hook::{{closure}}::h635d667f571198f0 at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:208:50 9: 0x7f93d4a23678 - std::panicking::default_hook::h3bc2efb48060abaa at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:227:9 10: 0x558de59fb491 - clippy_driver::report_clippy_ice::h76ee1ad508e689ae 11: 0x7f93d4a24216 - std::panicking::rust_panic_with_hook::h887eb0c89f46b8b2 at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:581:17 12: 0x7f93d8298a2d - std::panicking::begin_panic::{{closure}}::hc1d905d2374ce0cc 13: 0x7f93d8298936 - std::sys_common::backtrace::__rust_end_short_backtrace::ha1feaa73cb1e05ce 14: 0x7f93d829899f - std::panicking::begin_panic::h09616460625efa25 15: 0x7f93d82cf380 - rustc_errors::HandlerInner::bug::hbb6554bd4fbc8852 16: 0x7f93d82cde60 - rustc_errors::Handler::bug::h4feefeec7bb726ca 17: 0x7f93d7d3fbc4 - rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}::h22b92ed7b73b8340 18: 0x7f93d7d38e0b - rustc_middle::ty::context::tls::with_opt::{{closure}}::h32bfd9cf0b0a9393 19: 0x7f93d7d38db2 - rustc_middle::ty::context::tls::with_opt::h762464f893de2d96 20: 0x7f93d7d3fae9 - rustc_middle::util::bug::opt_span_bug_fmt::h05648c19bbf99518 21: 0x7f93d7d3fa5e - rustc_middle::util::bug::bug_fmt::h5d4f7ed12a8f1d0d 22: 0x7f93d5ec6f51 - rustc_typeck::collect::fn_sig::hb52a0a329f6964ef 23: 0x7f93d78b9952 - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::fn_sig>::compute::h13fc0633ba44b680 24: 0x7f93d79cd239 - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::h36d7997abc0c4bae 25: 0x7f93d79f6845 - rustc_data_structures::stack::ensure_sufficient_stack::h0be1b40c74cbc8c2 26: 0x7f93d7943ed1 - rustc_query_system::query::plumbing::get_query_impl::he841b945a79343ca 27: 0x7f93d78c65b9 - rustc_infer::infer::error_reporting::nice_region_error::util::::find_param_with_region::h66a45b4f57ed627b 28: 0x7f93d78c2c83 - rustc_infer::infer::error_reporting::nice_region_error::static_impl_trait::::try_report_static_impl_trait::h8105eabf38328f7b 29: 0x7f93d798ef0c - rustc_infer::infer::error_reporting::::report_region_errors::h3a44281bc2cff38b 30: 0x7f93d79a3b9b - rustc_infer::infer::InferCtxt::resolve_regions_and_report_errors::h2d24581248205346 31: 0x7f93d5d6abf2 - rustc_typeck::check::regionck::::regionck_fn::h297ea48485ddccf4 32: 0x7f93d5fb7bdd - rustc_infer::infer::InferCtxtBuilder::enter::h6881f9376e4471a9 33: 0x7f93d606e158 - rustc_typeck::check::typeck::h7936b5f86fffb913 34: 0x7f93d5f4f98e - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::typeck>::compute::hcea92138ac9e28bb 35: 0x7f93d5f19647 - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::h2605dda46e394e9a 36: 0x7f93d5e93a31 - rustc_data_structures::stack::ensure_sufficient_stack::hefd48e3d1b00a42f 37: 0x7f93d5d84329 - rustc_query_system::query::plumbing::get_query_impl::h3a9e7fcf130ad31d 38: 0x7f93d5df03fd - rustc_query_system::query::plumbing::ensure_query_impl::h7982f7a407c81650 39: 0x7f93d6072b36 - rustc_typeck::check::typeck_item_bodies::h64dc12efcaea9221 40: 0x7f93d5f0613e - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::typeck_item_bodies>::compute::h9834b15ef9ab2a9b 41: 0x7f93d5f25857 - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::ha57625619acaac80 42: 0x7f93d5e8f534 - rustc_data_structures::stack::ensure_sufficient_stack::h9c1970be50e3794d 43: 0x7f93d5d73f25 - rustc_query_system::query::plumbing::get_query_impl::h086a494db0b3fd1b 44: 0x7f93d5f6ee73 - rustc_typeck::check_crate::h19e2dfbdd8ea5557 45: 0x7f93d5531d95 - rustc_interface::passes::analysis::hf34e525a2b31f7c0 46: 0x7f93d526bd7b - rustc_middle::ty::query:: for rustc_middle::ty::query::queries::analysis>::compute::h23cb841af51f0584 47: 0x7f93d530a057 - rustc_query_system::dep_graph::graph::DepGraph::with_task_impl::h7178e9f1ddee6943 48: 0x7f93d53053df - rustc_middle::ty::query::plumbing::::start_query::{{closure}}::{{closure}}::{{closure}}::h4025824db8759ceb 49: 0x7f93d5296f10 - rustc_query_system::query::plumbing::get_query_impl::h29928f066778d4c4 50: 0x7f93d526e12b - rustc_interface::passes::QueryContext::enter::h0705343d8e4a95be 51: 0x7f93d53074a2 - rustc_interface::queries::::enter::h6eb07f11eba80bd6 52: 0x7f93d52ce2a2 - rustc_span::with_source_map::h3820d41b3a036910 53: 0x7f93d53089c2 - rustc_interface::interface::create_compiler_and_run::h08ad396f4e7721e0 54: 0x7f93d52f0d5a - scoped_tls::ScopedKey::set::hd425a36fbe06985e 55: 0x7f93d530d9b5 - std::sys_common::backtrace::__rust_begin_short_backtrace::h23925571219dbc63 56: 0x7f93d528b3ce - core::ops::function::FnOnce::call_once{{vtable.shim}}::h43b61b9af30b3669 57: 0x7f93d4a3321a - as core::ops::function::FnOnce>::call_once::h88864ee659ddb161 at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/alloc/src/boxed.rs:1042:9 58: 0x7f93d4a3321a - as core::ops::function::FnOnce>::call_once::h9f03cbdc7ab33431 at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/alloc/src/boxed.rs:1042:9 59: 0x7f93d4a3321a - std::sys::unix::thread::Thread::new::thread_start::h5979dd5560a11418 at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/sys/unix/thread.rs:89:17 60: 0x7f93d49183e9 - start_thread 61: 0x7f93d4700293 - __GI___clone 62: 0x0 - 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.0.212 (ffa2e7a 2020-10-24) query stack during panic: #0 [fn_sig] computing function signature of `main::{closure#0}` #1 [typeck] type-checking `main` #2 [typeck_item_bodies] type-checking all item bodies #3 [analysis] running analysis passes on this crate end of query stack error: aborting due to previous error ```

ebroto commented 3 years ago

It seems this one does not reproduce in current master nor in Clippy from ~2 days ago in the playground

ebroto commented 3 years ago

It breaks rustc though if you try to finish a build :) (stable, current nightly builds fine)