Skip to content

Errors with incorrectly typed parameters to trait functions incorrectly point to function #46658

Description

@mqudsi

When a parameter of an unexpected type is passed to a trait function, the resulting error message points to the function and not the parameter. Since the function is defined elsewhere (perhaps in another crate altogether), clearly the error is with the parameter and the error message should be altered to reflect that by pointing to the parameter.

Example:

debug!("expected signature: {}", base64::encode(&hmac.result()));

generates the following error:

   Compiling messagebridge v0.2.0 (file:///Users/mqudsi/Projects/messagebridge)
error[E0277]: the trait bound `crypto::mac::MacResult: std::convert::AsRef<[u8]>` is not satisfied
   --> src/incoming.rs:141:42
    |
141 |         debug!("expected signature: {}", base64::encode(&hmac.result()));
    |                                          ^^^^^^^^^^^^^^ the trait `std::convert::AsRef<[u8]>` is not implemented for `crypto::mac::MacResult`
    |
    = note: required by `base64::encode`

error: aborting due to previous error

error: Could not compile `messagebridge`.

To learn more, run the command again with --verbose.

The text of the error message is correct (it is describing the problem with the parameter) but the arrows point to the impl fn and not the parameter.

Activity

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-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions