Repository: rust
Issue: Bug in `fulfillment_errors.rs` when compiling
Labels: A-diagnostics,I-ICE,P-medium,T-compiler,regression-from-stable-to-stable,C-bug,WG-diagnostics

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

```Rust
use cgroups_rs;
use nix::mount::{mount, MsFlags};

use std::path::Path;

fn main() {
    mount(None, Path::new("foo"), None, MsFlags::empty(), None).unwrap();
}
```


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-unknown-linux-gnu
release: 1.84.0
LLVM version: 19.1.5
```

### Error output

```
thread 'rustc' panicked at compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs:1824:44:
called `Option::unwrap()` on a `None` value
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: core::option::unwrap_failed
   4: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_similar_impl_candidates
   5: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_fulfillment_error
   6: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_fulfillment_errors
   7: rustc_hir_typeck::typeck
      [... omitted 1 frame ...]
   8: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#4}>::{closure#0}
   9: rustc_hir_analysis::check_crate
  10: rustc_interface::passes::run_required_analyses
  11: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  12: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: rustc 1.84.0 (9fc6b4312 2025-01-07) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
```

</p>
</details>

### Content of `Cargo.toml`

```toml
[package]
name = "rustc_bug"
version = "0.1.0"
edition = "2021"

[dependencies]
cgroups-rs = "0.3.4"
nix = { version = "0.29.0", features = ["mount"] }
```

### Additional information

The bug seems related to the `use cgroups_rs;` line, if I remove it the bug goes away.

Compiling with `cargo +nightly build` works fine.

Please note that the code does not actually compile, with the following patch it does compile without panics.

```diff
-    mount(None, Path::new("foo"), None, MsFlags::empty(), None).unwrap();
+    mount::<Path, Path, Path, Path>(None, Path::new("foo"), None, MsFlags::empty(), None).unwrap();
```