Skip to content

impl dyn Trait on an auto trait produces a confusing diagnostic #85026

Closed
@PatchMixolydic

Description

@PatchMixolydic

Given the following code (playground):

impl dyn Unpin {}

The current output is:

error[E0118]: no nominal type found for inherent implementation
 --> src/lib.rs:1:6
  |
1 | impl dyn Unpin {}
  |      ^^^^^^^^^ impl requires a nominal type
  |
  = note: either implement a trait on it or create a newtype to wrap it instead

This is rather confusing. It's not immediately clear what the difference between impl dyn Unpin and this working code is (playground):

trait A {}
impl dyn A {}

Since impl dyn A is accepted, the user might be confused why dyn A would be considered a nominal type when dyn Unpin isn't. The real reason why impl dyn Unpin is an error is because it is an impl block for a type [edit: a dynamically dispatched auto trait] from another crate, which should be handled by E0116.

Ideally the output should look like:

error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
 --> src/lib.rs:1:1
  |
1 | impl dyn Unpin {}
  | ^^^^^^^^^^^^^^^^^ impl for type defined outside of crate.
  |
  = note: define and implement a trait or new type instead

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.F-auto_traits`#![feature(auto_traits)]`T-compilerRelevant to the compiler 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