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

async_fn_in_trait: return type of method impl is not checked in default bodies #103352

Closed
fasterthanlime opened this issue Oct 21, 2022 · 1 comment · Fixed by #103355
Closed
Assignees
Labels
C-bug Category: This is a bug. F-async_fn_in_trait Static async fn in traits F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fasterthanlime
Copy link
Contributor

Here's a MVCE:

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

pub trait Foo {
    // This should be a compile error, but isn't:
    //
    async fn woopsie_async(&self) -> String {
        42
    }

    // This one is checked correctly:
    //
    // fn woopsie(&self) -> String {
    //     42
    // }
}

Playground link

I expected to see this happen: compilation fails because I'm clearly returning an {integer} instead of a String

Instead, this happened: bad codegen ("async fn resumed after completion")

Meta

rustc --version --verbose:

rustc -vV
rustc 1.66.0-nightly (dcb376115 2022-10-20)
binary: rustc
commit-hash: dcb376115066d111dbf5f13d5ac2a2dbe8c12add
commit-date: 2022-10-20
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2
amos@sonic ~/work/hring afit
❯ rustc --version --verbose
rustc 1.66.0-nightly (dcb376115 2022-10-20)
binary: rustc
commit-hash: dcb376115066d111dbf5f13d5ac2a2dbe8c12add
commit-date: 2022-10-20
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2
@fasterthanlime fasterthanlime added the C-bug Category: This is a bug. label Oct 21, 2022
@compiler-errors compiler-errors self-assigned this Oct 21, 2022
@compiler-errors compiler-errors added F-async_fn_in_trait Static async fn in traits F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. requires-nightly This issue requires a nightly compiler in some way. labels Oct 21, 2022
@compiler-errors
Copy link
Member

This is specifically a bug with default body async fn in traits, this doesn't happen in impls. I'll check it out, it's probably a very simple fix.

@compiler-errors compiler-errors changed the title async_fn_in_trait: return type of method impl is not checked async_fn_in_trait: return type of method impl is not checked in default bodies Oct 21, 2022
notriddle added a commit to notriddle/rust that referenced this issue Oct 22, 2022
…ck, r=oli-obk

Handle return-position `impl Trait` in traits properly in `register_hidden_type`

The bounds that we get by calling `bound_explicit_item_bounds` from an RPITIT have projections, not opaques, but when we're *registering* an opaque, we want to treat it like an opaque.

Coincidentally fixes rust-lang#102688 as well, which makes sense, since that was failing because we were inferring an opaque type to be equal to itself (opaque cycle error => "cannot resolve opaque type").

Fixes rust-lang#103352

r? `@oli-obk`
notriddle added a commit to notriddle/rust that referenced this issue Oct 22, 2022
…ck, r=oli-obk

Handle return-position `impl Trait` in traits properly in `register_hidden_type`

The bounds that we get by calling `bound_explicit_item_bounds` from an RPITIT have projections, not opaques, but when we're *registering* an opaque, we want to treat it like an opaque.

Coincidentally fixes rust-lang#102688 as well, which makes sense, since that was failing because we were inferring an opaque type to be equal to itself (opaque cycle error => "cannot resolve opaque type").

Fixes rust-lang#103352

r? ``@oli-obk``
@bors bors closed this as completed in ff689a1 Oct 23, 2022
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-async_fn_in_trait Static async fn in traits F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants