Skip to content

Trait suggestions should use outermost candidates #31323

Closed as not planned
Closed as not planned
@AndiDog

Description

@AndiDog

Beginning with issue #21405, Rust combines multiple identical candidates into one (in some way). Since crates typically pub use the traits on the outermost level (e.g. module::TheTrait instead of module::inner::detail::TheTrait), the outermost candidate should be displayed as suggestion.

Here's a real-life example:

main.rs:44:21: 44:62 error: no method named `json_as` found for type `&'r mut nickel::request::Request<'mw, 'conn, _>` in the current scope
main.rs:44                let dir = request.json_as::<BlaBla>().unwrap().dir;
                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<nickel macros>:24:12: 24:42 note: in this expansion of as_block! (defined in <nickel macros>)
<nickel macros>:10:1: 10:60 note: in this expansion of _middleware_inner! (defined in <nickel macros>)
main.rs:43:47: 48:3 note: in this expansion of middleware! (defined in <nickel macros>)
main.rs:44:21: 44:62 help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
main.rs:44:21: 44:62 help: candidate #1: use `nickel::json_body_parser::JsonBody`

However the trait "JsonBody" can be imported with just use nickel::JsonBody.

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.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