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

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

Closed
matthiaskrgr opened this issue Oct 7, 2022 · 9 comments
Closed

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

matthiaskrgr opened this issue Oct 7, 2022 · 9 comments
Assignees
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Oct 7, 2022

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 | | }
  | |_^
@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label Oct 7, 2022
@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@aDotInTheVoid
Copy link
Member

aDotInTheVoid commented Sep 25, 2023

Fixed, needs a test: https://godbolt.org/z/64TxYTTnd

@aDotInTheVoid aDotInTheVoid added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. labels Sep 25, 2023
@Milo123459
Copy link
Contributor

how would i be able to add a test? on the godbolt it still fails and seems to have the same output as the issue.

@rustbot claim

@aDotInTheVoid
Copy link
Member

the dev guide has information on how to add a test. The think we are testing for here is that when a const async function is declaired inside another function, the compiller has a parser error, but not a cycle detected error. That's the difference between the two outputs.

@Milo123459
Copy link
Contributor

Milo123459 commented Sep 26, 2023

the stderr from this example in the rest test suite:

error: expected one of `:`, `;`, `<`, `=`, or `where`, found keyword `fn`
  --> $DIR/const-async-fn-in-main.rs:4:17
   |
LL |     const async fn a() {}
   |                 ^^ expected one of `:`, `;`, `<`, `=`, or `where`

error: missing type for `const` item
  --> $DIR/const-async-fn-in-main.rs:4:16
   |
LL |     const async fn a() {}
   |                ^ help: provide a type for the item: `: <type>`

error: aborting due to 2 previous errors

the code:

// Check what happens when a const async fn is in the main function (#102796)

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

the comand:

 x test tests/ui/const-async/const-async-fn-in-main.rs --stage 1 --bless

@aDotInTheVoid
Copy link
Member

I think you need to set the edition to 2018 or later, otherwise async isn't a keyword. If I remember correctly you need // edition:2021 at the top of the file, but check the dev-guide, it'll know

@Milo123459
Copy link
Contributor

error: functions cannot be both `const` and `async`
  --> $DIR/const-async-fn-in-main.rs:5:5
   |
LL |     const async fn a() {};
   |     ^^^^^-^^^^^----------
   |     |     |
   |     |     `async` because of this
   |     `const` because of this

error: aborting due to previous error

error now looks like this. will pr.

@Milo123459
Copy link
Contributor

#116178

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 27, 2023
…-async-function-in-main, r=wesleywiser

Add test for `const async fn`

This adds a test for rust-lang#102796
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 27, 2023
Rollup merge of rust-lang#116178 - Milo123459:milo/add-test-for-const-async-function-in-main, r=wesleywiser

Add test for `const async fn`

This adds a test for rust-lang#102796
@Milo123459
Copy link
Contributor

this can be closed now, my pr has been merged

@aDotInTheVoid
Copy link
Member

thanks!

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. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

4 participants