Skip to content

"cycle detected" with "const async" fn  #102796

Closed
@matthiaskrgr

Description

@matthiaskrgr
fn main() {
  const async fn a() {}
}

Seems a bit surprising that we don't bail out immediately when jumping from a function to itself? 🤔

rustc 1.66.0-nightly (0ca356586 2022-10-06)
error: functions cannot be both `const` and `async`
 --> src/main.rs:2:3
  |
2 |   const async fn a() {}
  |   ^^^^^-^^^^^----------
  |   |     |
  |   |     `async` because of this
  |   `const` because of this

error[[E0391]](https://doc.rust-lang.org/stable/error-index.html#E0391): cycle detected when computing type of `main::a::{opaque#0}`
 --> src/main.rs:2:22
  |
2 |   const async fn a() {}
  |                      ^
  |
note: ...which requires borrow-checking `main::a`...
 --> src/main.rs:2:3
  |
2 |   const async fn a() {}
  |   ^^^^^^^^^^^^^^^^^^
note: ...which requires processing `main::a`...
 --> src/main.rs:2:3
  |
2 |   const async fn a() {}
  |   ^^^^^^^^^^^^^^^^^^
note: ...which requires const checking `main::a`...
 --> src/main.rs:2:3
  |
2 |   const async fn a() {}
  |   ^^^^^^^^^^^^^^^^^^
  = note: ...which requires computing whether `impl core::future::future::Future<Output = ()>` is freeze...
  = note: ...which requires evaluating trait selection obligation `impl core::future::future::Future<Output = ()>: core::marker::Freeze`...
  = note: ...which again requires computing type of `main::a::{opaque#0}`, completing the cycle
note: cycle used when checking item types in top-level module
 --> src/main.rs:1:1
  |
1 | / fn main() {
2 | |   const async fn a() {}
3 | | }
  | |_^

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions