Skip to content

rust compiler yields obviously broken suggestions around dyn/impl use when tickled right #147894

@erikh

Description

@erikh

I tried this code:

So, the code is sufficiently complicated that it's really not worth it to spend all day trying to replicate. This branch has all of it. What you will want to do is cd to the vayama dir and run cargo test. That dir runs fine without privilege or touching the disk.. you do not want to run in the workspace dir or use the makefiles. Sorry I don't have something better to offer.

I expected to see this happen:

A suggestion that was syntactically correct.

Instead, this happened:

16 |           async fn successful_run_func(state: TransientState) -> MigrationFuture {
   |  ________________________________________________________________________________^
17 | |             Ok(state)
18 | |         }
   | |_________^ doesn't have a size known at compile-time
   |
   = note: the full name for the type has been written to '/home/erikh/src/github.com/trunk-os/control-plane/target/debug/deps/vayama-20c2982cc915c464.long-type-5394471838162170588.txt'
   = note: consider using `--verbose` to print the full type name to the console
help: consider returning an `impl Trait` instead of a `dyn Trait`
   |
16 |         async fn successful_run_func(state: TransientState) -> MigrationFuture impl {
   |                                                                                ++++
help: alternatively, box the return type, and wrap all of the returned values in `Box::new`
   |
16 ~         async fn successful_run_func(state: TransientState) -> MigrationFuture Box<dyn {
17 |             Ok(state)
18 ~         }>

Meta

rustc --version --verbose:

rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-unknown-linux-gnu
release: 1.90.0
LLVM version: 20.1.8

No backtrace required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-dyn-traitArea: trait objects, vtable layoutC-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions