Skip to content

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

Closed

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 + {
  |                   ^^^^^^^^^^^^^^^

Activity

  1. added
    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.
    on Aug 19, 2019
  2. added a commit that references this issue on Aug 29, 2019
    4cae33a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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