Skip to content

Do not suggest unwrap on Some(T) where T is expected #42746

Closed
@oli-obk

Description

@oli-obk

Currently

let i: i32 = Some(42);

reports

2 |     let i: i32 = Some(42);
  |                  ^^^^^^^^ expected i32, found enum `std::option::Option`
  |
  = note: expected type `i32`
             found type `std::option::Option<{integer}>`
  = help: here are some functions which might fulfill your needs:
          - .unwrap()
          - .unwrap_or_default()

I think Option and Result are special enough to warrant customized error messages. In this case simply suggesting to remove the Some

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions