Repository: rust
Issue: ICE: `assertion failed: self.let_source != LetSource::None`
Labels: I-ICE,T-compiler,C-bug,F-coerce_unsized,S-has-mcve,S-bug-has-test

<!--
[31mICE[0m: Rustc ./a.rs '' 'thread 'rustc' panicked at compiler/rustc_mir_build/src/thir/pattern/check_match.rs:437:9: 'assertion failed: self.let_source != LetSource::None'', 'thread 'rustc' panicked at compiler/rustc_mir_build/src/thir/pattern/check_match.rs:437:9: 'assertion failed: self.let_source != LetSource::None''
File: /tmp/im/2/a.rs
-->

auto-reduced (treereduce-rust):
````rust
impl<A> std::ops::CoerceUnsized<A> for A {}

fn main() {
    match true {
        _ if let true = true
            && true => {}

        _ => {}
    }
}

````

original:
````rust
impl<A> std::ops::CoerceUnsized<A> for A {}

fn main() {
    match true {
        _ if let true = true && true => {}
        //~^ ERROR `if let` guards are
        //~| ERROR `let` expressions in this
        _ => {}
    }
}

````

Version information
````
rustc 1.85.0-nightly (8e37e1518 2024-12-12)
binary: rustc
commit-hash: 8e37e151835d96d6a7415e93e6876561485a3354
commit-date: 2024-12-12
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5

````

Possibly related line of code:
https://github.com/rust-lang/rust/blob/8e37e151835d96d6a7415e93e6876561485a3354/compiler/rustc_mir_build/src/thir/pattern/check_match.rs#L431-L443

Command:
`/home/matthias/.rustup/toolchains/master/bin/rustc `

<details><summary><strong>Program output</strong></summary>
<p>

```
error[E0658]: `if let` guards are experimental
 --> /tmp/icemaker_global_tempdir.LCpqT8xE8i8B/rustc_testrunner_tmpdir_reporting.HaAO0ramSh9i/mvce.rs:5:11
  |
5 |           _ if let true = true
  |  ___________^
6 | |             && true => {}
  | |___________________^
  |
  = note: see issue #51114 <https://github.com/rust-lang/rust/issues/51114> for more information
  = help: add `#![feature(if_let_guard)]` to the crate attributes to enable
  = note: this compiler was built on 2024-12-12; consider upgrading it if it is out of date
  = help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`

error[E0658]: `let` expressions in this position are unstable
 --> /tmp/icemaker_global_tempdir.LCpqT8xE8i8B/rustc_testrunner_tmpdir_reporting.HaAO0ramSh9i/mvce.rs:5:14
  |
5 |         _ if let true = true
  |              ^^^^^^^^^^^^^^^
  |
  = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
  = help: add `#![feature(let_chains)]` to the crate attributes to enable
  = note: this compiler was built on 2024-12-12; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `coerce_unsized`
 --> /tmp/icemaker_global_tempdir.LCpqT8xE8i8B/rustc_testrunner_tmpdir_reporting.HaAO0ramSh9i/mvce.rs:1:9
  |
1 | impl<A> std::ops::CoerceUnsized<A> for A {}
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #18598 <https://github.com/rust-lang/rust/issues/18598> for more information
  = help: add `#![feature(coerce_unsized)]` to the crate attributes to enable
  = note: this compiler was built on 2024-12-12; consider upgrading it if it is out of date

error[E0210]: type parameter `A` must be used as the type parameter for some local type (e.g., `MyStruct<A>`)
 --> /tmp/icemaker_global_tempdir.LCpqT8xE8i8B/rustc_testrunner_tmpdir_reporting.HaAO0ramSh9i/mvce.rs:1:6
  |
1 | impl<A> std::ops::CoerceUnsized<A> for A {}
  |      ^ type parameter `A` must be used as the type parameter for some local type
  |
  = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
  = note: only traits defined in the current crate can be implemented for a type parameter

error[E0376]: the trait `CoerceUnsized` may only be implemented for a coercion between structures
 --> /tmp/icemaker_global_tempdir.LCpqT8xE8i8B/rustc_testrunner_tmpdir_reporting.HaAO0ramSh9i/mvce.rs:1:1
  |
1 | impl<A> std::ops::CoerceUnsized<A> for A {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_mir_build/src/thir/pattern/check_match.rs:437:9:
assertion failed: self.let_source != LetSource::None
stack backtrace:
   0:     0x7d588315e3aa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hdcffbc1065d74d75
   1:     0x7d5883813c66 - core::fmt::write::h55baa0ecd0176531
   2:     0x7d58847da091 - std::io::Write::write_fmt::h49f3dcbd2134b25a
   3:     0x7d588315e202 - std::sys::backtrace::BacktraceLock::print::h19877f04c7770d81
   4:     0x7d588316071a - std::panicking::default_hook::{{closure}}::h812458b2e3e6cae6
   5:     0x7d5883160563 - std::panicking::default_hook::hc806cb2847473728
   6:     0x7d58822c4e08 - std[f11eb203934acfd6]::panicking::update_hook::<alloc[a23c71bf91e329cf]::boxed::Box<rustc_driver_impl[b5a68f650dfe829f]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7d5883160f18 - std::panicking::rust_panic_with_hook::ha79d4bc654fea354
   8:     0x7d5883160bd6 - std::panicking::begin_panic_handler::{{closure}}::h54a022eda853152d
   9:     0x7d588315e859 - std::sys::backtrace::__rust_end_short_backtrace::hd4a582557f71a384
  10:     0x7d58831608cd - rust_begin_unwind
  11:     0x7d587fdb9560 - core::panicking::panic_fmt::he1c36effa16de984
  12:     0x7d588093558c - core::panicking::panic::h70de7f5a871adbc2
  13:     0x7d5884200e94 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_expr
  14:     0x7d58841ffed4 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_expr
  15:     0x7d5884ada95c - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor>::visit_land_rhs
  16:     0x7d5884ada88f - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor>::visit_land
  17:     0x7d5884ada873 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor>::visit_land
  18:     0x7d5884ada7a1 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor>::visit_land
  19:     0x7d58841ff29e - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_expr
  20:     0x7d58841feb83 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_expr
  21:     0x7d58841feaf3 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor>::with_let_source::<<rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_arm::{closure#0}::{closure#0}>
  22:     0x7d5884200746 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_expr
  23:     0x7d58841ffed4 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_expr
  24:     0x7d58841feb83 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_expr
  25:     0x7d58841ffed4 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_expr
  26:     0x7d58841ffed4 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_expr
  27:     0x7d58841feb83 - <rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::MatchVisitor as rustc_middle[ec650cf5d749f3c]::thir::visit::Visitor>::visit_expr
  28:     0x7d5884201f27 - rustc_mir_build[2e387cfc83cb721c]::thir::pattern::check_match::check_match
  29:     0x7d5884201b33 - rustc_query_impl[37a5c04746b38b2a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[37a5c04746b38b2a]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ec650cf5d749f3c]::query::erase::Erased<[u8; 1usize]>>
  30:     0x7d5884217347 - rustc_query_system[292d97488c9a101d]::query::plumbing::try_execute_query::<rustc_query_impl[37a5c04746b38b2a]::DynamicConfig<rustc_data_structures[35c611aae2a30678]::vec_cache::VecCache<rustc_span[89c59f74d8e61a10]::def_id::LocalDefId, rustc_middle[ec650cf5d749f3c]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[292d97488c9a101d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[37a5c04746b38b2a]::plumbing::QueryCtxt, false>
  31:     0x7d5884216fdd - rustc_query_impl[37a5c04746b38b2a]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7d588421ba85 - rustc_mir_build[2e387cfc83cb721c]::build::mir_build
  33:     0x7d5883809c44 - rustc_mir_transform[ef0b54958ae2c620]::mir_built
  34:     0x7d5883809c07 - rustc_query_impl[37a5c04746b38b2a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[37a5c04746b38b2a]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ec650cf5d749f3c]::query::erase::Erased<[u8; 8usize]>>
  35:     0x7d5883acfdd1 - rustc_query_system[292d97488c9a101d]::query::plumbing::try_execute_query::<rustc_query_impl[37a5c04746b38b2a]::DynamicConfig<rustc_data_structures[35c611aae2a30678]::vec_cache::VecCache<rustc_span[89c59f74d8e61a10]::def_id::LocalDefId, rustc_middle[ec650cf5d749f3c]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[292d97488c9a101d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[37a5c04746b38b2a]::plumbing::QueryCtxt, false>
  36:     0x7d5883acf98d - rustc_query_impl[37a5c04746b38b2a]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7d5880a13015 - rustc_mir_build[2e387cfc83cb721c]::check_unsafety::check_unsafety
  38:     0x7d588418a6fd - rustc_query_impl[37a5c04746b38b2a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[37a5c04746b38b2a]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ec650cf5d749f3c]::query::erase::Erased<[u8; 0usize]>>
  39:     0x7d588418a99a - rustc_query_system[292d97488c9a101d]::query::plumbing::try_execute_query::<rustc_query_impl[37a5c04746b38b2a]::DynamicConfig<rustc_data_structures[35c611aae2a30678]::vec_cache::VecCache<rustc_span[89c59f74d8e61a10]::def_id::LocalDefId, rustc_middle[ec650cf5d749f3c]::query::erase::Erased<[u8; 0usize]>, rustc_query_system[292d97488c9a101d]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[37a5c04746b38b2a]::plumbing::QueryCtxt, false>
  40:     0x7d588418a641 - rustc_query_impl[37a5c04746b38b2a]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7d5883c5efec - rustc_interface[2b9613d0d03e32ba]::passes::run_required_analyses
  42:     0x7d58847c569e - rustc_interface[2b9613d0d03e32ba]::passes::analysis
  43:     0x7d58847c566f - rustc_query_impl[37a5c04746b38b2a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[37a5c04746b38b2a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ec650cf5d749f3c]::query::erase::Erased<[u8; 0usize]>>
  44:     0x7d588483fbd5 - rustc_query_system[292d97488c9a101d]::query::plumbing::try_execute_query::<rustc_query_impl[37a5c04746b38b2a]::DynamicConfig<rustc_query_system[292d97488c9a101d]::query::caches::SingleCache<rustc_middle[ec650cf5d749f3c]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[37a5c04746b38b2a]::plumbing::QueryCtxt, false>
  45:     0x7d588483f90e - rustc_query_impl[37a5c04746b38b2a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:     0x7d5884883a3c - rustc_interface[2b9613d0d03e32ba]::interface::run_compiler::<(), rustc_driver_impl[b5a68f650dfe829f]::run_compiler::{closure#0}>::{closure#1}
  47:     0x7d5884742ec7 - std[f11eb203934acfd6]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[2b9613d0d03e32ba]::util::run_in_thread_with_globals<rustc_interface[2b9613d0d03e32ba]::util::run_in_thread_pool_with_globals<rustc_interface[2b9613d0d03e32ba]::interface::run_compiler<(), rustc_driver_impl[b5a68f650dfe829f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  48:     0x7d5884743362 - <<std[f11eb203934acfd6]::thread::Builder>::spawn_unchecked_<rustc_interface[2b9613d0d03e32ba]::util::run_in_thread_with_globals<rustc_interface[2b9613d0d03e32ba]::util::run_in_thread_pool_with_globals<rustc_interface[2b9613d0d03e32ba]::interface::run_compiler<(), rustc_driver_impl[b5a68f650dfe829f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[42065d3ef999533b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:     0x7d588474492f - std::sys::pal::unix::thread::Thread::new::thread_start::h8c3d5e2b3337de45
  50:     0x7d587eaa339d - <unknown>
  51:     0x7d587eb2849c - <unknown>
  52:                0x0 - <unknown>

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

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

note: rustc 1.85.0-nightly (8e37e1518 2024-12-12) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_match] match-checking `main`
#1 [mir_built] building MIR for `main`
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0210, E0376, E0658.
For more information about an error, try `rustc --explain E0210`.

```

</p>
</details>

<!--
query stack:
#0 [check_match] match-checking `main`
#1 [mir_built] building MIR for `main`

-->