Skip to content

Maybe-sized RPIT type is unexpectedly allowed in async fn #149438

@obi1kenobi

Description

@obi1kenobi

I tried this code: playground

use std::fmt::Debug;

fn breaks() -> impl Debug + ?Sized {
    123
}
//
// error[E0277]: the size for values of type `impl Debug + ?Sized` cannot be known at compilation time
//  --> src/lib.rs:3:16
//   |
// 3 | fn breaks() -> impl Debug + ?Sized {
//   |                ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
//   |
//   = help: the trait `Sized` is not implemented for `impl Debug + ?Sized`
//   = note: the return type of a function must have a statically known size

async fn works() -> impl Debug + ?Sized {
    123
}
// no error!

I expected to see this happen: return types must always be sized, so -> impl Debug + ?Sized is not valid for any function regardless if it's async or not.

Instead, this happened: the compiler unexpectedly accepts it for async functions.

Meta

rustc --version --verbose:

rustc 1.91.1 (ed61e7d7e 2025-11-07)
binary: rustc
commit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb
commit-date: 2025-11-07
host: x86_64-unknown-linux-gnu
release: 1.91.1
LLVM version: 21.1.2

Also happens on the 2025-11-27 nightly on the playground.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-DSTsArea: Dynamically-sized types (DSTs)A-associated-itemsArea: Associated items (types, constants & functions)A-async-awaitArea: Async & AwaitA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions