Skip to content

Suggest to swap a struct and a trait in trait impls where appropriate #89590

Closed
@hkmatsumoto

Description

@hkmatsumoto

Given the following code: Playground

pub trait Trait {}

pub struct Struct {}

impl Struct for Trait {}

The current output is:

error[E0404]: expected trait, found struct `Struct`
 --> src/lib.rs:5:6
  |
5 | impl Struct for Trait {}
  |      ^^^^^^ not a trait

warning: trait objects without an explicit `dyn` are deprecated
 --> src/lib.rs:5:17
  |
5 | impl Struct for Trait {}
  |                 ^^^^^ help: use `dyn`: `dyn Trait`
  |
  = note: `#[warn(bare_trait_objects)]` on by default
  = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
  = note: for more information, see issue #80165 <https://github.com/rust-lang/rust/issues/80165>

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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