Skip to content

panic in unnecessary_literal_unwrap.rs #11229

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

Closed
camshaft opened this issue Jul 25, 2023 · 1 comment
Closed

panic in unnecessary_literal_unwrap.rs #11229

camshaft opened this issue Jul 25, 2023 · 1 comment

Comments

@camshaft
Copy link

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9d3464cdccdec08621e0df1a7df8fae5

pub fn test() -> u32 {
    let value = None;
    value.unwrap_or(123)
}

Results in the following:

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', src/tools/clippy/clippy_lints/src/methods/unnecessary_literal_unwrap.rs:103:36
stack backtrace:
   0:     0x7f43e9468fc1 - std::backtrace_rs::backtrace::libunwind::trace::hdbeb239dad3fe05b
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f43e9468fc1 - std::backtrace_rs::backtrace::trace_unsynchronized::h0d5832c176f29d68
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f43e9468fc1 - std::sys_common::backtrace::_print_fmt::h693b93625fae6594
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f43e9468fc1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8be7805a245ed733
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f43e94cf49c - core::fmt::rt::Argument::fmt::ha09465f0c1b6fb28
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/core/src/fmt/rt.rs:138:9
   5:     0x7f43e94cf49c - core::fmt::write::h419380ed19a66504
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f43e945b5ce - std::io::Write::write_fmt::h697a91a7bc6c66fd
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/io/mod.rs:1714:15
   7:     0x7f43e9468dd5 - std::sys_common::backtrace::_print::hcc84e4906b2cfc50
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f43e9468dd5 - std::sys_common::backtrace::print::hc97c64af7e7979ca
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f43e946be2a - std::panicking::panic_hook_with_disk_dump::{{closure}}::h45993653bb29d743
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/panicking.rs:278:22
  10:     0x7f43e946bac3 - std::panicking::panic_hook_with_disk_dump::h6a3f474df42ecdbe
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/panicking.rs:312:9
  11:     0x7f43ec687649 - <rustc_driver_impl[4cc18990ea388c2c]::install_ice_hook::{closure#0} as core[fc70c29feb60d78b]::ops::function::FnOnce<(&core[fc70c29feb60d78b]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7f43e946c6d0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h165fe1e6dec08dab
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/alloc/src/boxed.rs:2021:9
  13:     0x7f43e946c6d0 - std::panicking::rust_panic_with_hook::h2d67ee3cc819491a
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/panicking.rs:733:13
  14:     0x7f43e946c457 - std::panicking::begin_panic_handler::{{closure}}::hb96e40d184f5738d
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/panicking.rs:621:13
  15:     0x7f43e9469426 - std::sys_common::backtrace::__rust_end_short_backtrace::h7b396c253251f100
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/sys_common/backtrace.rs:151:18
  16:     0x7f43e946c1a2 - rust_begin_unwind
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/panicking.rs:617:5
  17:     0x7f43e94cb853 - core::panicking::panic_fmt::h004846269750dc83
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/core/src/panicking.rs:67:14
  18:     0x7f43e94cb9b2 - core::panicking::panic_bounds_check::h8eba5d222766995e
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/core/src/panicking.rs:162:5
  19:     0x55a93f1c5624 - <clippy_utils[21eaa80f3d856778]::diagnostics::span_lint_and_then<rustc_lint[1f33ef38fc576923]::context::LateContext, rustc_span[276188d0befe557d]::span_encoding::Span, clippy_lints[328390dc73fb7bc9]::methods::unnecessary_literal_unwrap::check::{closure#1}>::{closure#0} as core[fc70c29feb60d78b]::ops::function::FnOnce<(&mut rustc_errors[ec2707f3c482dcf4]::diagnostic_builder::DiagnosticBuilder<()>,)>>::call_once::{shim:vtable#0}
  20:     0x55a93f1b3534 - rustc_middle[be7299d8622494ca]::lint::struct_lint_level::struct_lint_level_impl::<alloc[60930d8c9a7bb729]::string::String>
  21:     0x55a93f1ac5b9 - rustc_middle[be7299d8622494ca]::lint::struct_lint_level::<alloc[60930d8c9a7bb729]::string::String, clippy_utils[21eaa80f3d856778]::diagnostics::span_lint_and_then<rustc_lint[1f33ef38fc576923]::context::LateContext, rustc_span[276188d0befe557d]::span_encoding::Span, clippy_lints[328390dc73fb7bc9]::methods::unnecessary_literal_unwrap::check::{closure#1}>::{closure#0}>
  22:     0x55a93f1f0067 - <rustc_middle[be7299d8622494ca]::ty::context::TyCtxt>::struct_span_lint_hir::<rustc_span[276188d0befe557d]::span_encoding::Span, alloc[60930d8c9a7bb729]::string::String, clippy_utils[21eaa80f3d856778]::diagnostics::span_lint_and_then<rustc_lint[1f33ef38fc576923]::context::LateContext, rustc_span[276188d0befe557d]::span_encoding::Span, clippy_lints[328390dc73fb7bc9]::methods::unnecessary_literal_unwrap::check::{closure#1}>::{closure#0}>
  23:     0x55a93f1a5560 - clippy_utils[21eaa80f3d856778]::diagnostics::span_lint_and_then::<rustc_lint[1f33ef38fc576923]::context::LateContext, rustc_span[276188d0befe557d]::span_encoding::Span, clippy_lints[328390dc73fb7bc9]::methods::unnecessary_literal_unwrap::check::{closure#1}>
  24:     0x55a93f0a7526 - clippy_lints[328390dc73fb7bc9]::methods::unnecessary_literal_unwrap::check
  25:     0x55a93f27a922 - <clippy_lints[328390dc73fb7bc9]::methods::Methods>::check_methods
  26:     0x55a93f2769ac - <clippy_lints[328390dc73fb7bc9]::methods::Methods as rustc_lint[1f33ef38fc576923]::passes::LateLintPass>::check_expr
  27:     0x7f43ecab2f06 - <rustc_lint[1f33ef38fc576923]::early::RuntimeCombinedEarlyLintPass as rustc_lint[1f33ef38fc576923]::passes::EarlyLintPass>::check_generic_arg
  28:     0x7f43eca4cb67 - <rustc_lint[1f33ef38fc576923]::late::LateContextAndPass<rustc_lint[1f33ef38fc576923]::late::RuntimeCombinedLateLintPass> as rustc_hir[3793f6a056a90597]::intravisit::Visitor>::visit_expr
  29:     0x7f43eca4cd19 - <rustc_lint[1f33ef38fc576923]::late::LateContextAndPass<rustc_lint[1f33ef38fc576923]::late::RuntimeCombinedLateLintPass> as rustc_hir[3793f6a056a90597]::intravisit::Visitor>::visit_block
  30:     0x7f43eca4cb72 - <rustc_lint[1f33ef38fc576923]::late::LateContextAndPass<rustc_lint[1f33ef38fc576923]::late::RuntimeCombinedLateLintPass> as rustc_hir[3793f6a056a90597]::intravisit::Visitor>::visit_expr
  31:     0x7f43eca4d05a - <rustc_lint[1f33ef38fc576923]::late::LateContextAndPass<rustc_lint[1f33ef38fc576923]::late::RuntimeCombinedLateLintPass> as rustc_hir[3793f6a056a90597]::intravisit::Visitor>::visit_nested_body
  32:     0x7f43eca4d1f0 - <rustc_lint[1f33ef38fc576923]::late::LateContextAndPass<rustc_lint[1f33ef38fc576923]::late::RuntimeCombinedLateLintPass> as rustc_hir[3793f6a056a90597]::intravisit::Visitor>::visit_fn
  33:     0x7f43eca50293 - rustc_hir[3793f6a056a90597]::intravisit::walk_item::<rustc_lint[1f33ef38fc576923]::late::LateContextAndPass<rustc_lint[1f33ef38fc576923]::late::RuntimeCombinedLateLintPass>>
  34:     0x7f43eca4da8f - <rustc_lint[1f33ef38fc576923]::late::LateContextAndPass<rustc_lint[1f33ef38fc576923]::late::RuntimeCombinedLateLintPass> as rustc_hir[3793f6a056a90597]::intravisit::Visitor>::visit_nested_item
  35:     0x7f43eca4fb08 - rustc_hir[3793f6a056a90597]::intravisit::walk_mod::<rustc_lint[1f33ef38fc576923]::late::LateContextAndPass<rustc_lint[1f33ef38fc576923]::late::RuntimeCombinedLateLintPass>>
  36:     0x7f43ebb5640c - rustc_lint[1f33ef38fc576923]::late::late_lint_crate::<rustc_lint[1f33ef38fc576923]::BuiltinCombinedLateLintPass>
  37:     0x7f43ebb536a3 - <rustc_session[27ffd0f91dc1f7f3]::session::Session>::time::<(), rustc_interface[4590c8f94634ac8b]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}>
  38:     0x7f43ebb5314b - <core[fc70c29feb60d78b]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[4590c8f94634ac8b]::passes::analysis::{closure#5}::{closure#1}> as core[fc70c29feb60d78b]::ops::function::FnOnce<()>>::call_once
  39:     0x7f43ebb52b68 - <rustc_session[27ffd0f91dc1f7f3]::session::Session>::time::<(), rustc_interface[4590c8f94634ac8b]::passes::analysis::{closure#5}>
  40:     0x7f43ebb518e7 - rustc_interface[4590c8f94634ac8b]::passes::analysis
  41:     0x7f43ebb8094a - rustc_query_impl[874dfe5be29ea4b6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[874dfe5be29ea4b6]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[be7299d8622494ca]::query::erase::Erased<[u8; 1usize]>>
  42:     0x7f43ebb80939 - <rustc_query_impl[874dfe5be29ea4b6]::query_impl::analysis::dynamic_query::{closure#2} as core[fc70c29feb60d78b]::ops::function::FnOnce<(rustc_middle[be7299d8622494ca]::ty::context::TyCtxt, ())>>::call_once
  43:     0x7f43ebd37c48 - rustc_query_system[564890d86981df37]::query::plumbing::try_execute_query::<rustc_query_impl[874dfe5be29ea4b6]::DynamicConfig<rustc_query_system[564890d86981df37]::query::caches::SingleCache<rustc_middle[be7299d8622494ca]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[874dfe5be29ea4b6]::plumbing::QueryCtxt, false>
  44:     0x7f43ebd379d7 - rustc_query_impl[874dfe5be29ea4b6]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7f43eb9059b5 - <rustc_middle[be7299d8622494ca]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[4cc18990ea388c2c]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[fc70c29feb60d78b]::result::Result<(), rustc_span[276188d0befe557d]::ErrorGuaranteed>>
  46:     0x7f43eb904fe2 - <rustc_interface[4590c8f94634ac8b]::interface::Compiler>::enter::<rustc_driver_impl[4cc18990ea388c2c]::run_compiler::{closure#1}::{closure#2}, core[fc70c29feb60d78b]::result::Result<core[fc70c29feb60d78b]::option::Option<rustc_interface[4590c8f94634ac8b]::queries::Linker>, rustc_span[276188d0befe557d]::ErrorGuaranteed>>
  47:     0x7f43eb9021e4 - std[6c6be89d5af8698b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[4590c8f94634ac8b]::util::run_in_thread_pool_with_globals<rustc_interface[4590c8f94634ac8b]::interface::run_compiler<core[fc70c29feb60d78b]::result::Result<(), rustc_span[276188d0befe557d]::ErrorGuaranteed>, rustc_driver_impl[4cc18990ea388c2c]::run_compiler::{closure#1}>::{closure#0}, core[fc70c29feb60d78b]::result::Result<(), rustc_span[276188d0befe557d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[fc70c29feb60d78b]::result::Result<(), rustc_span[276188d0befe557d]::ErrorGuaranteed>>
  48:     0x7f43ebf01b0e - <<std[6c6be89d5af8698b]::thread::Builder>::spawn_unchecked_<rustc_interface[4590c8f94634ac8b]::util::run_in_thread_pool_with_globals<rustc_interface[4590c8f94634ac8b]::interface::run_compiler<core[fc70c29feb60d78b]::result::Result<(), rustc_span[276188d0befe557d]::ErrorGuaranteed>, rustc_driver_impl[4cc18990ea388c2c]::run_compiler::{closure#1}>::{closure#0}, core[fc70c29feb60d78b]::result::Result<(), rustc_span[276188d0befe557d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[fc70c29feb60d78b]::result::Result<(), rustc_span[276188d0befe557d]::ErrorGuaranteed>>::{closure#1} as core[fc70c29feb60d78b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:     0x7f43e9476dc5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha7a812df2522755c
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/alloc/src/boxed.rs:2007:9
  50:     0x7f43e9476dc5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb9951559ba9cd9f6
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/alloc/src/boxed.rs:2007:9
  51:     0x7f43e9476dc5 - std::sys::unix::thread::Thread::new::thread_start::h0ca6842f2b5c5e07
                               at /rustc/31395ec38250b60b380fd3c27e94756aba3557de/library/std/src/sys/unix/thread.rs:108:17
  52:     0x7f43e9331609 - start_thread
  53:     0x7f43e9105133 - clone
  54:                0x0 - <unknown>
@camshaft
Copy link
Author

Sorry, I should have looked at the closed issues before opening. I just noticed this is a duplicate of #11099 and was already resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant