rust-lang / rust-lang/rust

Using maybe-sized APIT in `async fn` produces duplicate E0277 diagnostic

Open
#149,439 1 comment 0 reactions 1 assignee View on GitHub

@Aditya-PS-05 is already working on this.

Since Nov 29, 2025.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
use std::fmt::Debug;

async fn arg_position_maybe_sized(_value: impl Debug + ?Sized) {}

playground

Current output
Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `impl Debug + ?Sized` cannot be known at compilation time
 --> src/lib.rs:3:43
  |
3 | async fn arg_position_maybe_sized(_value: impl Debug + ?Sized) {}
  |                                           ^^^^^^^^^^^^^^^^^^^
  |                                           |
  |                                           doesn't have a size known at compile-time
  |                                           this type parameter needs to be `Sized`
  |
help: consider removing the `?Sized` bound to make the type parameter `Sized`
  |
3 - async fn arg_position_maybe_sized(_value: impl Debug + ?Sized) {}
3 + async fn arg_position_maybe_sized(_value: impl Debug) {}
  |
help: function arguments must have a statically known size, borrowed types always have a known size
  |
3 | async fn arg_position_maybe_sized(_value: &impl Debug + ?Sized) {}
  |                                           +

error[E0277]: the size for values of type `impl Debug + ?Sized` cannot be known at compilation time
 --> src/lib.rs:3:35
  |
3 | async fn arg_position_maybe_sized(_value: impl Debug + ?Sized) {}
  |                                   ^^^^^^  ------------------- this type parameter needs to be `Sized`
  |                                   |
  |                                   doesn't have a size known at compile-time
  |
  = note: all local variables must have a statically known size
help: consider removing the `?Sized` bound to make the type parameter `Sized`
  |
3 - async fn arg_position_maybe_sized(_value: impl Debug + ?Sized) {}
3 + async fn arg_position_maybe_sized(_value: impl Debug) {}
  |

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 2 previous errors
Desired output
Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `impl Debug + ?Sized` cannot be known at compilation time
 --> src/lib.rs:3:35
  |
3 | async fn arg_position_maybe_sized(_value: impl Debug + ?Sized) {}
  |                                   ^^^^^^  ------------------- this type parameter needs to be `Sized`
  |                                   |
  |                                   doesn't have a size known at compile-time
  |
  = note: all local variables must have a statically known size
help: consider removing the `?Sized` bound to make the type parameter `Sized`
  |
3 - async fn arg_position_maybe_sized(_value: impl Debug + ?Sized) {}
3 + async fn arg_position_maybe_sized(_value: impl Debug) {}
  |

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 2 previous errors
Rationale and extra context

We should see just one diagnostic here, with all the necessary information from both current diagnostics combined. For example, on nightly one of the two diagnostics includes information about unsized fn arguments being an unstable feature (easy to see in the playground) -- ideally that info would be preserved when selecting which diagnostic to show (and how to merge them).

Other cases

Rust Version
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
Anything else?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.