Repository: rust
Issue: Cycle error involving `Freeze` when testing `time` crate
Labels: A-diagnostics,P-medium,T-compiler,regression-from-stable-to-stable,C-bug,I-cycle

For roughly a month, I have been getting an error in CI when performing code coverage. This is due to a stderr diff (I'm using `trybuild`). By itself, that is acceptable breakage, but the cause is a cycle error. Given the most recent successful and earliest failing CI runs, I bisected the compiler. The results are below. I have not attempted to minimize the error in any way.

In my opinion, a cycle error like this should be a proper ICE in terms of diagnostics, which would tell the user to file an issue. I only know to do this because of my involvement with rustc.

**This change will land on stable in just a few days.** I have reproduced it on the 1.75.0 binary from the pre-release server.

cc @compiler-errors as author of the PR apparently causing regression (#117418)

The diff in question:

```diff
diff --git a/tests/compile-fail/invalid_serializer.stderr b/tests/compile-fail/invalid_serializer.stderr
index 2f73f41..3579ac3 100644
--- a/tests/compile-fail/invalid_serializer.stderr
+++ b/tests/compile-fail/invalid_serializer.stderr
@@ -79,3 +79,35 @@ error[E0432]: unresolved import `not_string`
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no external crate `not_string`
    |
    = note: this error originates in the macro `serde::format_description` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0391]: cycle detected when computing type of opaque `my_format::description::{opaque#0}`
+  --> ../tests/compile-fail/invalid_serializer.rs:14:1
+   |
+14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+note: ...which requires borrow-checking `my_format::description`...
+  --> ../tests/compile-fail/invalid_serializer.rs:14:1
+   |
+14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: ...which requires promoting constants in MIR for `my_format::description`...
+  --> ../tests/compile-fail/invalid_serializer.rs:14:1
+   |
+14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: ...which requires const checking `my_format::description`...
+  --> ../tests/compile-fail/invalid_serializer.rs:14:1
+   |
+14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   = note: ...which requires computing whether `my_format::description::{opaque#0}` is freeze...
+   = note: ...which requires evaluating trait selection obligation `my_format::description::{opaque#0}: core::marker::Freeze`...
+   = note: ...which again requires computing type of opaque `my_format::description::{opaque#0}`, completing the cycle
+note: cycle used when computing type of `my_format::description::{opaque#0}`
+  --> ../tests/compile-fail/invalid_serializer.rs:14:1
+   |
+14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
+   = note: this error originates in the macro `serde::format_description` (in Nightly builds, run with -Z macro-backtrace for more info)
```

@rustbot label +C-bug +regression-from-stable-to-beta +T-compiler

---

searched nightlies: from nightly-2023-10-20 to nightly-2023-11-19
regressed nightly: nightly-2023-11-08
searched commit range: https://github.com/rust-lang/rust/compare/189d6c71f3bb6c52113b5639a80839791974fd22...7adc89b69b941afceadcf8609dd6b2999353e550
regressed commit: https://github.com/rust-lang/rust/commit/504f63efb0d5dd4cc22f5a43460b3b343d959b27

<details>
<summary>bisected with <a href='https://github.com/rust-lang/cargo-bisect-rustc'>cargo-bisect-rustc</a> v0.6.7</summary>


Host triple: x86_64-unknown-linux-gnu
Reproduce with:
```bash
cargo bisect-rustc --start 2023-10-20 --end 2023-11-19 --script ./test.sh 
```

`./test.sh` contains:
```bash
#!/bin/sh

RUSTFLAGS="--cfg __ui_tests" cargo test --all-features
```
</details>