Skip to content

Conversion errors from &str to String should suggest .to_owned() instead #45777

Closed
@mqudsi

Description

@mqudsi

Currently, attempting to compile code that expects a String while providing an &'static str causes the following to be shown:

error[E0308]: mismatched types
  --> src/incoming.rs:70:90
   |
70 |             timestamp: headers.get_raw("x-timestamp").unwrap_or(ErrorKind::MissingHeader("x-timestamp"))?,
   |                                                                                          ^^^^^^^^^^^^^ expected struct `std::string::String`, found reference
   |
   = note: expected type `std::string::String`
              found type `&'static str`
   = help: here are some functions which might fulfill your needs:
           - .escape_debug()
           - .escape_default()
           - .escape_unicode()
           - .to_lowercase()
           - .to_uppercase()

I'm guessing that these suggestions are automatically generated/derived by the compiler, but none of them are good "generic" suggestions.

The compiler should probably suggest either .to_owned() or .into() in this case instead.

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