Skip to content

Suggest code to use enum type in return type when accidentally using variant instance #57393

Description

@estebank

When encountering an enum variant instance in a return type, make a better effort to suggest appropriate code.

Right now, if you accidentally write Some(Span) when you meant Option<Span>, we mention the existence of the enum, but we don't suggest code:

error[E0573]: expected type, found variant `Some`
    --> src/librustc_typeck/check/mod.rs:5198:10
     |
5198 |     ) -> Some(Span) {
     |          ^^^^^^^^^^ not a type
     |
     = help: there is an enum variant `rustc::middle::cstore::LibSource::Some`, try using `rustc::middle::cstore::LibSource`?
     = help: there is an enum variant `rustc::session::config::Passes::Some`, try using `rustc::session::config::Passes`?
     = help: there is an enum variant `std::prelude::v1::Option::Some`, try using `std::prelude::v1::Option`?
     = help: there is an enum variant `std::prelude::v1::Some`, try using `std::prelude::v1`?

It'd be nice if we could suggest the appropriate code.

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 lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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