Skip to content

Error when passing a trait object as a generic type doesn't indicate what is the trait object #61525

Description

@shepmaster
pub trait Example {
    fn query<Q>(self, q: Q);
}

impl Example for i32 {
    fn query<Q>(self, _: Q) {
        unimplemented!()
    }
}

mod nested {
    use super::Example;
    fn example() {
        1.query::<dyn ToString>("")
    }
}
error: the `query` method cannot be invoked on a trait object
  --> src/lib.rs:14:11
   |
14 |         1.query::<dyn ToString>("")
   |           ^^^^^
   |
   = note: another candidate was found in the following trait, perhaps add a `use` for it:
           `use crate::Example;`

Issues with this diagnostic:

  1. The query method is not being invoked on a trait object; it's invoked on the concrete value 1.
  2. The note suggests importing the same trait that is already being reported about.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-papercutDiagnostics: An error or lint that needs small tweaks.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