Skip to content

Call pinned method from Trait on generic parameter #63966

Closed
@Jonathas-Conceicao

Description

@Jonathas-Conceicao

I've found a problem regarding Pin that I just can't solve and the current Nightly compiler gives a misleading suggestion.

This playground example serves well as a minimalist example. I can't manege to call quack on the Animal inside the Transporter even with the restriction to Animal: Quack.

And the Nightly compiler suggests:

   = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `quack`, perhaps you need to restrict type parameter `Animal` with it:
   |
17 | impl<Animal: Quack + Quack> Quack for Transporter<Animal> {
   |      ^^^^^^^^^^^^^^^

Which clearly doesn't really solve anything.

If a take off the Pin from the Traits and it's impl and just use a &self I can get the expected Quack! from inside the transporter.

The compiler suggestion surely doesn't seams right to me, but what about the Pin? Am I missing something or is there a bug too?

Metadata

Metadata

Assignees

No one assigned

    Labels

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