Skip to content

rustc suggests invalid syntax for missing method on impl Trait parameter #63706

Closed
@euclio

Description

@euclio

Given:

trait Foo {}

trait Bar {
    fn hello(&mut self) {}
}

fn test(foo: &mut impl Foo) {
    foo.hello();
}

rustc outputs:

error[E0599]: no method named `hello` found for type `&mut impl Foo` in the current scope
 --> src/lib.rs:8:9
  |
8 |     foo.hello();
  |         ^^^^^
  |
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `hello`, perhaps you need to restrict type parameter `impl Foo` with it:
  |
7 | fn test(foo: &mut impl Foo: Bar + {
  |                   ^^^^^^^^^^^^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.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