Skip to content

regression: "cycle detected when borrow-checking" in offset_of! #150464

Closed

Description

@cuviper
[INFO] [stdout] error[E0391]: cycle detected when borrow-checking `firmware::operation::implement::stm::gain::tests::test_phase_half`
[INFO] [stdout]    --> src/firmware/operation/implement/stm/gain.rs:649:5
[INFO] [stdout]     |
[INFO] [stdout] 649 |     fn test_phase_half() {
[INFO] [stdout]     |     ^^^^^^^^^^^^^^^^^^^^
[INFO] [stdout]     |
[INFO] [stdout] note: ...which requires promoting constants in MIR for `firmware::operation::implement::stm::gain::tests::test_phase_half`...
[INFO] [stdout]    --> src/firmware/operation/implement/stm/gain.rs:649:5
[INFO] [stdout]     |
[INFO] [stdout] 649 |     fn test_phase_half() {
[INFO] [stdout]     |     ^^^^^^^^^^^^^^^^^^^^
[INFO] [stdout] note: ...which requires simplifying constant for the type system `firmware::operation::implement::stm::gain::tests::test_phase_half::{constant#0}`...
[INFO] [stdout]    --> src/firmware/operation/implement/stm/gain.rs:704:20
[INFO] [stdout]     |
[INFO] [stdout] 704 |                 tx[offset_of!(GainSTMHead, flag)] & 0x3F
[INFO] [stdout]     |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[INFO] [stdout] note: ...which requires const-evaluating + checking `firmware::operation::implement::stm::gain::tests::test_phase_half::{constant#0}`...
[INFO] [stdout]    --> src/firmware/operation/implement/stm/gain.rs:704:20
[INFO] [stdout]     |
[INFO] [stdout] 704 |                 tx[offset_of!(GainSTMHead, flag)] & 0x3F
[INFO] [stdout]     |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[INFO] [stdout] note: ...which requires caching mir of `firmware::operation::implement::stm::gain::tests::test_phase_half::{constant#0}` for CTFE...
[INFO] [stdout]    --> src/firmware/operation/implement/stm/gain.rs:704:20
[INFO] [stdout]     |
[INFO] [stdout] 704 |                 tx[offset_of!(GainSTMHead, flag)] & 0x3F
[INFO] [stdout]     |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[INFO] [stdout] note: ...which requires elaborating drops for `firmware::operation::implement::stm::gain::tests::test_phase_half::{constant#0}`...
[INFO] [stdout]    --> src/firmware/operation/implement/stm/gain.rs:704:20
[INFO] [stdout]     |
[INFO] [stdout] 704 |                 tx[offset_of!(GainSTMHead, flag)] & 0x3F
[INFO] [stdout]     |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[INFO] [stdout]     = note: ...which again requires borrow-checking `firmware::operation::implement::stm::gain::tests::test_phase_half`, completing the cycle
[INFO] [stdout]     = note: cycle used when running analysis passes on crate `autd3_driver`
[INFO] [stdout]     = 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
[INFO] [stdout]     = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)

https://crater-reports.s3.amazonaws.com/beta-1.93-3/beta-2025-12-09/reg/autd3-driver-38.0.1/log.txt

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Dec 28, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    and removed
    regression-untriagedUntriaged performance or correctness regression.
    on Dec 28, 2025
  3. added this to the 1.93.0 milestone on Dec 28, 2025
  4. added
    I-cycleIssue: A query cycle occurred while none was expected
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 28, 2025
  5. theemathas commented on Dec 29, 2025

    @theemathas
    Contributor

    MCVE:

    use std::mem::offset_of;
    
    struct Thing(i32);
    
    pub fn foo() {
        let temp = [0u8];
        let _ = &(temp[offset_of!(Thing, 0)] & 0u8);
    }
    Error output
    error[E0391]: cycle detected when borrow-checking `foo`
     --> src/lib.rs:5:1
      |
    5 | pub fn foo() {
      | ^^^^^^^^^^^^
      |
    note: ...which requires promoting constants in MIR for `foo`...
     --> src/lib.rs:5:1
      |
    5 | pub fn foo() {
      | ^^^^^^^^^^^^
    note: ...which requires simplifying constant for the type system `foo::{constant#0}`...
     --> src/lib.rs:7:20
      |
    7 |     let _ = &(temp[offset_of!(Thing, 0)] & 0u8);
      |                    ^^^^^^^^^^^^^^^^^^^^
    note: ...which requires const-evaluating + checking `foo::{constant#0}`...
     --> src/lib.rs:7:20
      |
    7 |     let _ = &(temp[offset_of!(Thing, 0)] & 0u8);
      |                    ^^^^^^^^^^^^^^^^^^^^
    note: ...which requires caching mir of `foo::{constant#0}` for CTFE...
     --> src/lib.rs:7:20
      |
    7 |     let _ = &(temp[offset_of!(Thing, 0)] & 0u8);
      |                    ^^^^^^^^^^^^^^^^^^^^
    note: ...which requires elaborating drops for `foo::{constant#0}`...
     --> src/lib.rs:7:20
      |
    7 |     let _ = &(temp[offset_of!(Thing, 0)] & 0u8);
      |                    ^^^^^^^^^^^^^^^^^^^^
      = note: ...which again requires borrow-checking `foo`, completing the cycle
      = note: cycle used when running analysis passes on crate `playground`
      = 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 `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    For more information about this error, try `rustc --explain E0391`.
    
  6. 18 remaining items

  7. lcnr commented on Dec 30, 2025

    @lcnr
    Contributor

    I think we should stop trying to evaluate const blocks here, they are guaranteed to query cycle 😁

  8. self-assigned this
    on Dec 31, 2025
  9. apiraino commented on Jan 22, 2026

    @apiraino
    Contributor

    Assigning priority (discussion on Zulip).

    @rustbot label -I-prioritize +P-medium

  10. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jan 22, 2026
  11. added a commit that references this issue on Jan 27, 2026
    53fb684
  12. added a commit that references this issue on Jan 27, 2026
    8d0fe88
  13. added 3 commits that reference this issue on Jan 28, 2026
    e24093f
    5ce2dfd
    340ebff
  14. added a commit that references this issue on Aug 7, 2026
    ca95a93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-arrayArea: `[T; N]`A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-constant-promotionArea: constant promotionC-bugCategory: This is a bug.I-cycleIssue: A query cycle occurred while none was expectedP-mediumMedium priorityS-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamWG-const-evalWorking group: Const evaluationregression-from-stable-to-betaPerformance or correctness regression from stable to beta.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions