Skip to content

Show other possible implementations in the "trait not implemented" message #21659

Closed
@Manishearth

Description

@Manishearth

Currently, if I try to index a [T] by a u8 (buf[1u8], or whatever), I'll get the error

test.rs:6:15: 6:19 error: the trait `core::ops::Index<u8>` is not implemented for the type `[u8]` [E0277]
test.rs:6 println!("{}",y[x])

It would be helpful in such a situation for a note saying that there is an implementation of Index<usize>.

Basically: If a trait isn't found to be implemented, but a version of that trait with different type parameters is, show some help messages containing the candidates. We do something like this already when one tries to call a nonexistent method on a type where bringing some trait into scope might make it work.

In this case, it should show something along the lines of:

test.rs:7:22: 7:22 help: the following implementations were found:
test.rs:7:22: 7:22 help: implementation #1: `Index<usize>`
``

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions