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

ICE: explicit deref of non-derefable type #125058

Closed
Tracked by #123076
matthiaskrgr opened this issue May 13, 2024 · 4 comments · Fixed by #125084
Closed
Tracked by #123076

ICE: explicit deref of non-derefable type #125058

matthiaskrgr opened this issue May 13, 2024 · 4 comments · Fixed by #125084
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented May 13, 2024

Code

#![allow(incomplete_features)]
#![feature(ref_pat_everywhere)]

pub fn main() {
    if let Some(Some(&x)) = &Some(&Some(0)) {
        let _: u32 = x;
    }
}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (ba956ef4b 2024-05-13)
binary: rustc
commit-hash: ba956ef4b00c91579cff9b2220358ee3a46d982f
commit-date: 2024-05-13
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

Error output

<output>
Backtrace

error: internal compiler error: /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/compiler/rustc_hir_typeck/src/expr_use_visitor.rs:218:9: explicit deref of non-derefable type
 --> ref_pat_everywhere.rs:5:22
  |
5 |     if let Some(Some(&x)) = &Some(&Some(0)) {
  |                      ^^

thread 'rustc' panicked at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/compiler/rustc_hir_typeck/src/expr_use_visitor.rs:218:9:
Box<dyn Any>
stack backtrace:
   0:     0x759107658e55 - std::backtrace_rs::backtrace::libunwind::trace::he1c8af16e60d8ac3
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x759107658e55 - std::backtrace_rs::backtrace::trace_unsynchronized::h0ff4fb4d1fb1eafe
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x759107658e55 - std::sys_common::backtrace::_print_fmt::hda02bf9854ed434b
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x759107658e55 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2f1348356d4dd5a6
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7591076a816b - core::fmt::rt::Argument::fmt::hdfc187d135a92cff
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/core/src/fmt/rt.rs:165:63
   5:     0x7591076a816b - core::fmt::write::h2e66cd8a0d755998
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/core/src/fmt/mod.rs:1169:21
   6:     0x75910764dbef - std::io::Write::write_fmt::ha6594d6d0318bd63
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/std/src/io/mod.rs:1835:15
   7:     0x759107658c2e - std::sys_common::backtrace::_print::h7b339c0ab962de77
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x759107658c2e - std::sys_common::backtrace::print::hde9837078a8d5e94
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x75910765b649 - std::panicking::default_hook::{{closure}}::h0f2e3d59d4fc9781
  10:     0x75910765b38d - std::panicking::default_hook::h9944960cd621bbba
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/std/src/panicking.rs:298:9
  11:     0x759103eeb64f - std[2aee1e20eb236dda]::panicking::update_hook::<alloc[322764ce6b1abc47]::boxed::Box<rustc_driver_impl[b3f759d8272e082a]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x75910765bd7b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h63db09f1011a40db
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/alloc/src/boxed.rs:2036:9
  13:     0x75910765bd7b - std::panicking::rust_panic_with_hook::hd5c6a18d84f2558b
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/std/src/panicking.rs:799:13
  14:     0x759103f1b944 - std[2aee1e20eb236dda]::panicking::begin_panic::<rustc_errors[1fa39940d3d52013]::ExplicitBug>::{closure#0}
  15:     0x759103f182e6 - std[2aee1e20eb236dda]::sys_common::backtrace::__rust_end_short_backtrace::<std[2aee1e20eb236dda]::panicking::begin_panic<rustc_errors[1fa39940d3d52013]::ExplicitBug>::{closure#0}, !>
  16:     0x759103f13856 - std[2aee1e20eb236dda]::panicking::begin_panic::<rustc_errors[1fa39940d3d52013]::ExplicitBug>
  17:     0x759103f24be1 - <rustc_errors[1fa39940d3d52013]::diagnostic::BugAbort as rustc_errors[1fa39940d3d52013]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x5b1402a0a7c8 - <rustc_errors[1fa39940d3d52013]::DiagCtxt>::span_bug::<rustc_span[18b9f7b309fe5dcc]::span_encoding::Span, alloc[322764ce6b1abc47]::string::String>
  19:     0x5b1402b17ccb - rustc_middle[6763d32431b5f193]::util::bug::opt_span_bug_fmt::<rustc_span[18b9f7b309fe5dcc]::span_encoding::Span>::{closure#0}
  20:     0x5b1402b198aa - rustc_middle[6763d32431b5f193]::ty::context::tls::with_opt::<rustc_middle[6763d32431b5f193]::util::bug::opt_span_bug_fmt<rustc_span[18b9f7b309fe5dcc]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x5b1402acbb9b - rustc_middle[6763d32431b5f193]::ty::context::tls::with_context_opt::<rustc_middle[6763d32431b5f193]::ty::context::tls::with_opt<rustc_middle[6763d32431b5f193]::util::bug::opt_span_bug_fmt<rustc_span[18b9f7b309fe5dcc]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x5b1402ac923a - rustc_middle[6763d32431b5f193]::util::bug::span_bug_fmt::<rustc_span[18b9f7b309fe5dcc]::span_encoding::Span>
  23:     0x5b1402ae4c1e - <(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId) as rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::TypeInformationCtxt>::report_error::<&str>
  24:     0x5b1402b6bb68 - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::needless_pass_by_value::MovedVariablesCtxt>>::cat_deref
  25:     0x5b1402a100b4 - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::cat_pattern::<<rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::walk_pat::{closure#0}>
  26:     0x5b1402a106a2 - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::cat_pattern::<<rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::walk_pat::{closure#0}>
  27:     0x5b1402a106a2 - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::cat_pattern::<<rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::walk_pat::{closure#0}>
  28:     0x5b1402b5c46b - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::walk_irrefutable_pat
  29:     0x5b1402b5da61 - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::walk_expr
  30:     0x5b1402b5c21c - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::consume_expr
  31:     0x5b1402b5c803 - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::walk_expr
  32:     0x5b1402b5c21c - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::consume_expr
  33:     0x5b1402b5d58e - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::walk_expr
  34:     0x5b1402b5c21c - <rustc_hir_typeck[9965755b35d13bf6]::expr_use_visitor::ExprUseVisitor<(&rustc_lint[935797b976454209]::context::LateContext, rustc_span[18b9f7b309fe5dcc]::def_id::LocalDefId), &mut clippy_lints[7545ccafa66a19d7]::escape::EscapeDelegate>>::consume_expr
  35:     0x5b1402c182c8 - <clippy_lints[7545ccafa66a19d7]::escape::BoxedLocal as rustc_lint[935797b976454209]::passes::LateLintPass>::check_fn
  36:     0x7591042c2c75 - <rustc_lint[935797b976454209]::late::LateContextAndPass<rustc_lint[935797b976454209]::late::RuntimeCombinedLateLintPass> as rustc_hir[c63ce795a895b78]::intravisit::Visitor>::visit_fn
  37:     0x7591042b1ff5 - <rustc_lint[935797b976454209]::late::LateContextAndPass<rustc_lint[935797b976454209]::late::RuntimeCombinedLateLintPass> as rustc_hir[c63ce795a895b78]::intravisit::Visitor>::visit_nested_item
  38:     0x759105d7c12a - rustc_lint[935797b976454209]::late::check_crate::{closure#0}
  39:     0x759105d7c373 - rustc_lint[935797b976454209]::late::check_crate
  40:     0x759105d82b93 - rustc_interface[378bc30a20028389]::passes::analysis
  41:     0x759105d8209b - rustc_query_impl[829470001f3ffad1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[829470001f3ffad1]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6763d32431b5f193]::query::erase::Erased<[u8; 1usize]>>
  42:     0x759106002ca5 - rustc_query_system[f6e0b1d5265b4ecc]::query::plumbing::try_execute_query::<rustc_query_impl[829470001f3ffad1]::DynamicConfig<rustc_query_system[f6e0b1d5265b4ecc]::query::caches::SingleCache<rustc_middle[6763d32431b5f193]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[829470001f3ffad1]::plumbing::QueryCtxt, false>
  43:     0x759106002a09 - rustc_query_impl[829470001f3ffad1]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  44:     0x759105e3ee0e - rustc_interface[378bc30a20028389]::interface::run_compiler::<core[5a1853d728d4f28b]::result::Result<(), rustc_span[18b9f7b309fe5dcc]::ErrorGuaranteed>, rustc_driver_impl[b3f759d8272e082a]::run_compiler::{closure#0}>::{closure#1}
  45:     0x759105e04a89 - std[2aee1e20eb236dda]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[378bc30a20028389]::util::run_in_thread_with_globals<rustc_interface[378bc30a20028389]::util::run_in_thread_pool_with_globals<rustc_interface[378bc30a20028389]::interface::run_compiler<core[5a1853d728d4f28b]::result::Result<(), rustc_span[18b9f7b309fe5dcc]::ErrorGuaranteed>, rustc_driver_impl[b3f759d8272e082a]::run_compiler::{closure#0}>::{closure#1}, core[5a1853d728d4f28b]::result::Result<(), rustc_span[18b9f7b309fe5dcc]::ErrorGuaranteed>>::{closure#0}, core[5a1853d728d4f28b]::result::Result<(), rustc_span[18b9f7b309fe5dcc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5a1853d728d4f28b]::result::Result<(), rustc_span[18b9f7b309fe5dcc]::ErrorGuaranteed>>
  46:     0x759105e04836 - <<std[2aee1e20eb236dda]::thread::Builder>::spawn_unchecked_<rustc_interface[378bc30a20028389]::util::run_in_thread_with_globals<rustc_interface[378bc30a20028389]::util::run_in_thread_pool_with_globals<rustc_interface[378bc30a20028389]::interface::run_compiler<core[5a1853d728d4f28b]::result::Result<(), rustc_span[18b9f7b309fe5dcc]::ErrorGuaranteed>, rustc_driver_impl[b3f759d8272e082a]::run_compiler::{closure#0}>::{closure#1}, core[5a1853d728d4f28b]::result::Result<(), rustc_span[18b9f7b309fe5dcc]::ErrorGuaranteed>>::{closure#0}, core[5a1853d728d4f28b]::result::Result<(), rustc_span[18b9f7b309fe5dcc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5a1853d728d4f28b]::result::Result<(), rustc_span[18b9f7b309fe5dcc]::ErrorGuaranteed>>::{closure#2} as core[5a1853d728d4f28b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  47:     0x759107665c1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1118031ec204f534
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/alloc/src/boxed.rs:2022:9
  48:     0x759107665c1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h46a265d132dda3f6
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/alloc/src/boxed.rs:2022:9
  49:     0x759107665c1b - std::sys::pal::unix::thread::Thread::new::thread_start::hfd925ddaab3cb24c
                               at /rustc/ba956ef4b00c91579cff9b2220358ee3a46d982f/library/std/src/sys/pal/unix/thread.rs:108:17
  50:     0x759100ca955a - <unknown>
  51:     0x759100d26a3c - <unknown>
  52:                0x0 - <unknown>

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/tmp/im/rustc-ice-2024-05-13T04_56_49-1069123.txt` to your bug report

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
note: Clippy version: clippy 0.1.80 (ba956ef 2024-05-13)

error: aborting due to 1 previous error

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 13, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 13, 2024
@matthiaskrgr matthiaskrgr changed the title ICE: clippy: explicit deref of non-derefable type ICE: explicit deref of non-derefable type May 13, 2024
@matthiaskrgr
Copy link
Member Author

rustc repro:

#![feature(ref_pat_everywhere)]
struct Foo;

fn main() {
    || if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
        let _: u32 = x;
    };
}

@matthiaskrgr
Copy link
Member Author

This ^ bisects to #124902 cc @compiler-errors

@compiler-errors
Copy link
Member

compiler-errors commented May 13, 2024

This likely exposed a preexisting bug in ref_pat_everywhere cc @Jules-Bertholet

previously ExprUseVisitor was silently bailing when it couldn't deref a type it expected to be able to deref.

@Jules-Bertholet
Copy link
Contributor

ref_pat_everywhere is most likely going to be removed, but this also reproduces with edition 2024 and ref_pat_eat_one_layer_2024:

#![feature(ref_pat_eat_one_layer_2024)]
struct Foo;

fn main() {
    || if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
        let _: u32 = x;
    };
}

@rustbot claim

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 13, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this issue May 14, 2024
…ieril

`rustc_hir_typeck`: Account for `skipped_ref_pats` in `expr_use_visitor`

Fixes rust-lang#125058

r? `@Nadrieril`

cc rust-lang#123076

`@rustbot` label A-edition-2024 A-patterns
bors added a commit to rust-lang-ci/rust that referenced this issue May 15, 2024
`rustc_hir_typeck`: Account for `skipped_ref_pats` in `expr_use_visitor`

Fixes rust-lang#125058

r? `@Nadrieril`

cc rust-lang#123076

`@rustbot` label A-edition-2024 A-patterns
@bors bors closed this as completed in fe8f66e May 15, 2024
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) ❄️ 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.

5 participants