Skip to content

Providing a trait object as a type parameter to a function causes nonsense error #47990

Closed
@sgrif

Description

@sgrif

I had mistakenly written this code in crates.io: conn.transaction::<_, CargoError, _>(...) (note: CargoError is a trait). I should have written Box<CargoError>. That resulted in this compiler error, which makes absolutely no sense:

error: the `transaction` method cannot be invoked on a trait object
   --> src/user/mod.rs:546:10
    |
546 |     conn.transaction::<_, CargoError, _>(|| {
    |          ^^^^^^^^^^^
    |
    = note: another candidate was found in the following trait, perhaps add a `use` for it:
            candidate #1: `use diesel::Connection;`

I am not invoking the method on a trait object, nor would use have any effect as the Connection trait is already in scope. For reference, the signature of the method being called is:

fn transaction<T, E, F>(&self, f: F) -> Result<T, E>
where
    F: FnOnce() -> Result<T, E>,
    E: From<Error>,

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.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