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

Loop detection error for duplicate const functions #137521

Open
oligamiq opened this issue Feb 24, 2025 · 0 comments
Open

Loop detection error for duplicate const functions #137521

oligamiq opened this issue Feb 24, 2025 · 0 comments
Labels
C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-incomplete-features This issue requires the use of incomplete features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oligamiq
Copy link

I tried this code:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=396a3e397abbf6d5d0f417ad2dd21575

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

const fn wrap<const N: usize>() -> usize {
    0
}

const fn inner<const N: usize>() -> usize {
    0
}

const fn flip_magic_base_inner<const N: usize>()
    -> !
    where [(); wrap::<{ inner::<N>() }>()] : {
    todo!()
}

I expected to see this happen: no error

The following code, which is essentially the same, can compile.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=a568ce2d4a1d358435f825aa172c4440

Instead, this happened:

Compiling playground v0.0.1 (/playground)
error[E0391]: cycle detected when building an abstract representation for `flip_magic_base_inner::{constant#0}`
  --> src/lib.rs:14:16
   |
14 |     where [(); wrap::<{ inner::<N>() }>()] : {
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: ...which requires building THIR for `flip_magic_base_inner::{constant#0}`...
  --> src/lib.rs:14:16
   |
14 |     where [(); wrap::<{ inner::<N>() }>()] : {
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires type-checking `flip_magic_base_inner::{constant#0}`...
  --> src/lib.rs:14:16
   |
14 |     where [(); wrap::<{ inner::<N>() }>()] : {
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: ...which again requires building an abstract representation for `flip_magic_base_inner::{constant#0}`, completing the cycle
note: cycle used when checking that `flip_magic_base_inner` is well-formed
  --> src/lib.rs:12:1
   |
12 | / const fn flip_magic_base_inner<const N: usize>()
13 | |     -> !
14 | |     where [(); wrap::<{ inner::<N>() }>()] : {
   | |____________________________________________^
   = 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

For more information about this error, try `rustc --explain E0391`.
error: could not compile `playground` (lib) due to 1 previous error

There is something wrong with it because it can be compiled if it is not duplicated.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=aba90728c00aaa4808ecd5762ae9fa26

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (f8a913b13 2025-02-23)
binary: rustc
commit-hash: f8a913b1381e90379c7ca63ac2b88b9518936628
commit-date: 2025-02-23
host: x86_64-pc-windows-msvc
release: 1.87.0-nightly
LLVM version: 20.1.0
@oligamiq oligamiq added the C-bug Category: This is a bug. label Feb 24, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 24, 2025
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-incomplete-features This issue requires the use of incomplete features. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 24, 2025
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. F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-incomplete-features This issue requires the use of incomplete features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants