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

assert panics in unwrap lint #5579

Closed
wiomoc opened this issue May 8, 2020 · 1 comment · Fixed by #5590
Closed

assert panics in unwrap lint #5579

wiomoc opened this issue May 8, 2020 · 1 comment · Fixed by #5590
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@wiomoc
Copy link
Contributor

wiomoc commented May 8, 2020

Clippy panics during linting of this code:

trait IsErr {
    fn is_err(&self, err: &str) -> bool;
}

impl<T> IsErr for Option<T> {
    fn is_err(&self, _err: &str) -> bool {
        true
    }
}

fn main() {
    let t = Some(1);

    if t.is_err("") {
        t.unwrap();
    }
}

assert!(args.len() == 1);

Something like this should do the trick:

is_type_diagnostic_item(cx, ty, sym!(option_type))
        && ["is_some", "is_none"].contains(&&*name)
        || is_type_diagnostic_item(cx, ty, sym!(result_type))
            && ["is_ok", "is_err"].contains(&&*name)
@matthiaskrgr matthiaskrgr added the I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ label May 8, 2020
@matthiaskrgr
Copy link
Member

Backtrace:

thread 'rustc' panicked at 'assertion failed: args.len() == 1', src/tools/clippy/clippy_lints/src/unwrap.rs:107:17
stack backtrace:
   0:     0x7f37a12a89e4 - backtrace::backtrace::libunwind::trace::hfcd33194db0151d4
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1:     0x7f37a12a89e4 - backtrace::backtrace::trace_unsynchronized::hfd1904bbbd5335b5
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2:     0x7f37a12a89e4 - std::sys_common::backtrace::_print_fmt::h8476c57b177b254e
                               at src/libstd/sys_common/backtrace.rs:78
   3:     0x7f37a12a89e4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h73acbc5f6d4b1044
                               at src/libstd/sys_common/backtrace.rs:59
   4:     0x7f37a12e69dc - core::fmt::write::hdf236390fbd68d3d
                               at src/libcore/fmt/mod.rs:1069
   5:     0x7f37a129a3e3 - std::io::Write::write_fmt::h5722fa40bb2afafd
                               at src/libstd/io/mod.rs:1532
   6:     0x7f37a12ada05 - std::sys_common::backtrace::_print::ha468e873aada7c78
                               at src/libstd/sys_common/backtrace.rs:62
   7:     0x7f37a12ada05 - std::sys_common::backtrace::print::h149365a2f029de62
                               at src/libstd/sys_common/backtrace.rs:49
   8:     0x7f37a12ada05 - std::panicking::default_hook::{{closure}}::hb4a33f9e05934a52
                               at src/libstd/panicking.rs:198
   9:     0x7f37a12ad742 - std::panicking::default_hook::hc4535d7b0c743abd
                               at src/libstd/panicking.rs:218
  10:     0x55e625dbf881 - clippy_driver::report_clippy_ice::hedcde3cb12415fe4
  11:     0x7f37a12ae0bd - std::panicking::rust_panic_with_hook::haa34a96a6dbd5a2e
                               at src/libstd/panicking.rs:481
  12:     0x55e625eef9be - std::panicking::begin_panic::hf5950fe05dd10ed4
  13:     0x55e625e3abc2 - clippy_lints::unwrap::collect_unwrap_info::h316849687a130d62
  14:     0x55e625e3ac28 - clippy_lints::unwrap::UnwrappableVariablesVisitor::visit_branch::hb622d8882af7b05f
  15:     0x55e625e3b241 - <clippy_lints::unwrap::UnwrappableVariablesVisitor as rustc_hir::intravisit::Visitor>::visit_expr::h81cac39daa53a72a
  16:     0x55e625e3b6a3 - <clippy_lints::unwrap::UnwrappableVariablesVisitor as rustc_hir::intravisit::Visitor>::visit_expr::h81cac39daa53a72a
  17:     0x55e625f31776 - rustc_hir::intravisit::walk_fn::he136b21fd714fa62
  18:     0x55e625e3b806 - <clippy_lints::unwrap::Unwrap as rustc_lint::passes::LateLintPass>::check_fn::hc58848258ce8d661
  19:     0x7f37a37e44c2 - <rustc_lint::late::LateLintPassObjects as rustc_lint::passes::LateLintPass>::check_fn::ha9b477af3ee26aa4
  20:     0x7f37a1b980b6 - rustc_hir::intravisit::walk_item::hd7aca0a3280e0d01
  21:     0x7f37a1becd04 - rustc_hir::intravisit::Visitor::visit_nested_item::hef50697ada24f512
  22:     0x7f37a1b9156e - rustc_hir::intravisit::walk_crate::h87301c8e316eae69
  23:     0x7f37a1bc12c7 - rustc_lint::late::late_lint_pass_crate::h3987dcacf48988b9
  24:     0x7f37a1bc4490 - rustc_session::utils::<impl rustc_session::session::Session>::time::h0a01190aa57bb50d
  25:     0x7f37a1bc8c60 - rustc_session::utils::<impl rustc_session::session::Session>::time::hddabeeb6d45418e6
  26:     0x7f37a1b46595 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h57f965df9e864a4d
  27:     0x7f37a1bc4ca8 - rustc_session::utils::<impl rustc_session::session::Session>::time::h0c71c337234b0974
  28:     0x7f37a1c6fa4b - rustc_interface::passes::analysis::h6d809b9127d1df5d
  29:     0x7f37a18b71fb - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute::he31be01f92f630cb
  30:     0x7f37a1a02927 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::h8b90ad06db3eaeca
  31:     0x7f37a1885d58 - rustc_data_structures::stack::ensure_sufficient_stack::h7cb8d36df1565b9a
  32:     0x7f37a1a09e1c - rustc_query_system::query::plumbing::get_query_impl::h3655d22c01adc2a8
  33:     0x7f37a18b7407 - rustc_middle::ty::context::tls::enter_global::h172f152fc22b01e3
  34:     0x7f37a1883b49 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h24d68d75bb23a364
  35:     0x7f37a18c2f2d - scoped_tls::ScopedKey<T>::set::h017a7c9423dcc2fe
  36:     0x7f37a18bc872 - rustc_ast::attr::with_globals::hb07e6b9f2e998c0a
  37:     0x7f37a18cac05 - std::sys_common::backtrace::__rust_begin_short_backtrace::h1d61d8d2633208cc
  38:     0x7f37a1a112fe - core::ops::function::FnOnce::call_once{{vtable.shim}}::h8fafb950fdaeaae0
  39:     0x7f37a12be0ca - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::ha26a994a135d55de
                               at /rustc/a08c47310c7d49cbdc5d7afb38408ba519967ecd/src/liballoc/boxed.rs:1034
  40:     0x7f37a12be0ca - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h677072ad3ba2806b
                               at /rustc/a08c47310c7d49cbdc5d7afb38408ba519967ecd/src/liballoc/boxed.rs:1034
  41:     0x7f37a12be0ca - std::sys::unix::thread::Thread::new::thread_start::h7c46ce580f54dd0e
                               at src/libstd/sys/unix/thread.rs:87
  42:     0x7f37a11d246f - start_thread
  43:     0x7f37a10e83d3 - clone
  44:                0x0 - <unknown>

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-clippy/issues/new

note: Clippy version: clippy 0.0.212 (a08c473 2020-05-07)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants